Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
# --------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ exports
*.egg-info
*.vsix
__pycache__
test
test.chunkhound/
1 change: 1 addition & 0 deletions backend/src/core/cfg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
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.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) {
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
21 changes: 15 additions & 6 deletions backend/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `
____ __ __
/ __ \\ | \\/ |
| | | |_ __ ___ _ __ | \\ / | ___ _ __ ___ ___ _ __ _ _
| | | | '_ \\ / _ \\ '_ \\| |\\/| |/ _ \\ '_ \` _ \\ / _ \\| '__| | | |
Expand Down 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);
}
}, env.db_init_delay_ms);

start_reflection();
start_user_summary_reflection();
Expand Down