From 1470ddc7863238d0c8c9c0241699d0a2c4bb4512 Mon Sep 17 00:00:00 2001 From: yingliang-zhang Date: Sat, 4 Jul 2026 18:40:27 +0800 Subject: [PATCH 1/2] fix: wire SNAPSHOT_INTERVAL to a periodic timer that triggers mem::snapshot-create The SNAPSHOT_INTERVAL config value was read and logged at boot but no setInterval timer was ever created, so periodic snapshots never fired. Snapshots only happened when manually triggered via the API/MCP. Add a setInterval that triggers mem::snapshot-create at the configured interval, following the same pattern as auto-forget, lesson-decay, and consolidation timers (try/catch + unref). Fixes #1006 Signed-off-by: yingliang-zhang --- src/index.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/index.ts b/src/index.ts index 1e623eae8..2a1a1d901 100644 --- a/src/index.ts +++ b/src/index.ts @@ -347,6 +347,15 @@ async function main() { const snapshotConfig = loadSnapshotConfig(); if (snapshotConfig.enabled) { registerSnapshotFunction(sdk, kv, snapshotConfig.dir); + const snapshotIntervalMs = snapshotConfig.interval * 1000; + if (snapshotIntervalMs > 0) { + const snapshotTimer = setInterval(async () => { + try { + await sdk.trigger({ function_id: "mem::snapshot-create", payload: {} }); + } catch {} + }, snapshotIntervalMs); + snapshotTimer.unref(); + } bootLog( `Git snapshots: ${snapshotConfig.dir} (every ${snapshotConfig.interval}s)`, ); From 4b111973bb6af732457a4322d76c97fea6271438 Mon Sep 17 00:00:00 2001 From: yingliang-zhang Date: Sat, 4 Jul 2026 18:51:46 +0800 Subject: [PATCH 2/2] fix: clarify boot log when SNAPSHOT_INTERVAL=0 disables the periodic timer Address CodeRabbit nitpick: the boot log always reported 'every Ns' even when the timer guard (snapshotIntervalMs > 0) skipped creating it, making SNAPSHOT_INTERVAL=0 misleadingly look like periodic snapshots were running. Signed-off-by: yingliang-zhang --- src/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 2a1a1d901..caa6d8c22 100644 --- a/src/index.ts +++ b/src/index.ts @@ -357,7 +357,9 @@ async function main() { snapshotTimer.unref(); } bootLog( - `Git snapshots: ${snapshotConfig.dir} (every ${snapshotConfig.interval}s)`, + snapshotIntervalMs > 0 + ? `Git snapshots: ${snapshotConfig.dir} (every ${snapshotConfig.interval}s)` + : `Git snapshots: ${snapshotConfig.dir} (periodic timer disabled, SNAPSHOT_INTERVAL=0 — manual trigger only)`, ); }