fix(memory): memoryFlush fires every compaction cycle instead of every other

After a memoryFlush during compaction, memoryFlushCompactionCount was
reassigned to the post-increment compaction count. This locked both
counters to the same value, causing the dedup gate to skip the next
flush. The result: flush, skip, flush, skip...

Remove the reassignment so memoryFlushCompactionCount stays at the
pre-increment value. The next compaction increments compactionCount
alone, the counters differ, and the flush fires reliably.

Fixes #12590.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Kaspre 2026-03-21 00:39:31 -04:00
parent 5e417b44e1
commit b8cf08d775

View File

@ -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 {