-
Notifications
You must be signed in to change notification settings - Fork 501
fix: add database initialization delay to prevent race condition on startup #95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
8428101
768f7b6
c337dca
41065a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -993,7 +993,17 @@ export async function run_decay_process(): Promise<{ | |||||||||||||||||
| processed: number; | ||||||||||||||||||
| decayed: number; | ||||||||||||||||||
| }> { | ||||||||||||||||||
| console.log('[DECAY] Querying memories from database...'); | ||||||||||||||||||
| const mems = await q.all_mem.all(10000, 0); | ||||||||||||||||||
| console.log(`[DECAY] Retrieved ${mems.length} memories from database`); | ||||||||||||||||||
|
|
||||||||||||||||||
| if (mems.length === 0) { | ||||||||||||||||||
| console.error('[DECAY] ⚠️ WARNING: No memories retrieved! Possible causes:'); | ||||||||||||||||||
| console.error('[DECAY] - Database not initialized'); | ||||||||||||||||||
| console.error('[DECAY] - Wrong database path'); | ||||||||||||||||||
| console.error('[DECAY] - Database file is empty'); | ||||||||||||||||||
|
||||||||||||||||||
| console.error('[DECAY] ⚠️ WARNING: No memories retrieved! Possible causes:'); | |
| console.error('[DECAY] - Database not initialized'); | |
| console.error('[DECAY] - Wrong database path'); | |
| console.error('[DECAY] - Database file is empty'); | |
| console.warn('[DECAY] ⚠️ WARNING: No memories retrieved! Possible causes:'); | |
| console.warn('[DECAY] - Database not initialized'); | |
| console.warn('[DECAY] - Wrong database path'); | |
| console.warn('[DECAY] - Database file is empty'); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,13 +98,22 @@ setInterval( | |
| }, | ||
| 7 * 24 * 60 * 60 * 1000, | ||
| ); | ||
| run_decay_process() | ||
| .then((result: any) => { | ||
| // Wait for database initialization before running decay | ||
| // This prevents race conditions where decay runs before SQLite is fully ready | ||
| setTimeout(async () => { | ||
| try { | ||
| console.log('[INIT] Starting delayed decay process to ensure database is ready...'); | ||
| const result = await run_decay_process(); | ||
| console.log( | ||
| `[INIT] Initial decay: ${result.decayed}/${result.processed} memories updated`, | ||
| ); | ||
| }) | ||
| .catch(console.error); | ||
| if (result.processed === 0) { | ||
| console.warn('[INIT] ⚠️ WARNING: No memories were processed! Database may not be initialized.'); | ||
| } | ||
| } catch (error) { | ||
| console.error("[INIT] Initial decay failed:", error); | ||
| } | ||
| }, 3000); // 3 second delay to ensure database connection is established | ||
|
||
|
|
||
| start_reflection(); | ||
| start_user_summary_reflection(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
console.errorfor a warning message is semantically incorrect. This should useconsole.warninstead, similar to line 111 inbackend/src/server/index.ts. Console.error should be reserved for actual errors that require immediate attention.