diff --git a/src/auto-reply/reply/agent-runner-memory.ts b/src/auto-reply/reply/agent-runner-memory.ts index 267326a7e20..ebef0f807ed 100644 --- a/src/auto-reply/reply/agent-runner-memory.ts +++ b/src/auto-reply/reply/agent-runner-memory.ts @@ -526,15 +526,16 @@ export async function runMemoryFlushIfNeeded(params: { (params.sessionKey ? activeSessionStore?.[params.sessionKey]?.compactionCount : 0) ?? 0; if (memoryCompactionCompleted) { - const nextCount = await incrementCompactionCount({ + await incrementCompactionCount({ sessionEntry: activeSessionEntry, sessionStore: activeSessionStore, sessionKey: params.sessionKey, storePath: params.storePath, }); - if (typeof nextCount === "number") { - memoryFlushCompactionCount = nextCount; - } + // Do NOT reassign memoryFlushCompactionCount to the post-increment value. + // Keeping it at the pre-increment value ensures the next compaction cycle + // sees different counters, allowing memoryFlush to fire every cycle + // instead of every other. See #12590. } if (params.storePath && params.sessionKey) { try {