Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions backend/src/memory/hsg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Copilot AI Dec 9, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using console.error for a warning message is semantically incorrect. This should use console.warn instead, similar to line 111 in backend/src/server/index.ts. Console.error should be reserved for actual errors that require immediate attention.

Suggested change
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');

Copilot uses AI. Check for mistakes.

Copilot AI Dec 9, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using console.error for informational messages about possible causes is semantically incorrect. These should use console.warn instead, consistent with the warning pattern established in the codebase (e.g., line 111 in backend/src/server/index.ts).

Suggested change
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');

Copilot uses AI. Check for mistakes.
}

let p = 0,
d = 0;
for (const m of mems) {
Expand All @@ -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(
Expand Down
17 changes: 13 additions & 4 deletions backend/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copilot AI Dec 9, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hardcoded 3-second delay (magic number) should be extracted to a named constant or environment variable for better maintainability and configurability. Consider defining it as const DB_INIT_DELAY_MS = 3000; at the top of the file or making it configurable via an environment variable like OM_DB_INIT_DELAY_MS.

Copilot uses AI. Check for mistakes.

start_reflection();
start_user_summary_reflection();
Expand Down