diff --git a/.env.example b/.env.example index 37301da..3b98414 100644 --- a/.env.example +++ b/.env.example @@ -29,6 +29,12 @@ OM_TELEMETRY=true # Server Mode OM_MODE=standard # standard | langgraph +# Database Initialization Delay (milliseconds) +# Delay before running initial decay process to ensure database is ready +# Helps prevent race conditions with SQLite initialization +# Default: 3000 (3 seconds) +OM_DB_INIT_DELAY_MS=3000 + # -------------------------------------------- # Metadata Store # -------------------------------------------- diff --git a/.gitignore b/.gitignore index 94c630d..2a39cc0 100644 --- a/.gitignore +++ b/.gitignore @@ -20,4 +20,4 @@ exports *.egg-info *.vsix __pycache__ -test \ No newline at end of file +test.chunkhound/ diff --git a/backend/src/core/cfg.ts b/backend/src/core/cfg.ts index 4826212..7604fc1 100644 --- a/backend/src/core/cfg.ts +++ b/backend/src/core/cfg.ts @@ -107,4 +107,5 @@ export const env = { summary_layers: num(process.env.OM_SUMMARY_LAYERS, 3), keyword_boost: num(process.env.OM_KEYWORD_BOOST, 2.5), keyword_min_length: num(process.env.OM_KEYWORD_MIN_LENGTH, 3), + db_init_delay_ms: num(process.env.OM_DB_INIT_DELAY_MS, 3000), }; diff --git a/backend/src/memory/hsg.ts b/backend/src/memory/hsg.ts index 101831d..488602d 100644 --- a/backend/src/memory/hsg.ts +++ b/backend/src/memory/hsg.ts @@ -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.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'); + } + let p = 0, d = 0; for (const m of mems) { @@ -1006,6 +1016,8 @@ export async function run_decay_process(): Promise<{ p++; } if (d > 0) await log_maint_op("decay", d); + + console.log(`[DECAY] Completed: Processed ${p} memories, updated ${d}`); return { processed: p, decayed: d }; } export async function add_hsg_memory( diff --git a/backend/src/server/index.ts b/backend/src/server/index.ts index e6c8b79..985623a 100644 --- a/backend/src/server/index.ts +++ b/backend/src/server/index.ts @@ -11,8 +11,8 @@ import { start_reflection } from "../memory/reflect"; import { start_user_summary_reflection } from "../memory/user_summary"; import { sendTelemetry } from "../core/telemetry"; import { req_tracker_mw } from "./routes/dashboard"; - -const ASC = ` ____ __ __ +const ASC = ` + ____ __ __ / __ \\ | \\/ | | | | |_ __ ___ _ __ | \\ / | ___ _ __ ___ ___ _ __ _ _ | | | | '_ \\ / _ \\ '_ \\| |\\/| |/ _ \\ '_ \` _ \\ / _ \\| '__| | | | @@ -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); + } +}, env.db_init_delay_ms); start_reflection(); start_user_summary_reflection();