fix(memory): preserve pre-increment compaction count in memoryFlushCompactionCount (#12590)#69138
fix(memory): preserve pre-increment compaction count in memoryFlushCompactionCount (#12590)#69138MoerAI wants to merge 1 commit into
Conversation
…mpactionCount (openclaw#12590) runMemoryFlushIfNeeded was overwriting memoryFlushCompactionCount with the post-increment compaction count when compaction completed during a flush. This caused hasAlreadyFlushedForCurrentCompaction to compare equal on the next cycle (N+1 === N+1) and falsely skip the flush, making memoryFlush fire on every other auto-compaction cycle instead of every cycle. Keep memoryFlushCompactionCount at the pre-increment value so the dedup check correctly detects a new compaction cycle.
Greptile SummaryThis PR fixes a bug where Confidence Score: 5/5Safe to merge — targeted, well-documented bug fix with passing tests. The change is a two-line deletion and one-line no-op ( No files require special attention. Reviews (1): Last reviewed commit: "fix(memory): preserve pre-increment comp..." | Re-trigger Greptile |
|
Related work from PRtags group Title: Open PR duplicate: memoryFlush compaction counter skip
|
|
Closing this as duplicate or superseded after Codex automated review. PR #69138 is a focused and plausible fix, but it duplicates the same remaining memoryFlush compaction-counter work already tracked by older open PR #51421 and bug #12590. Current main still has the implicated post-increment assignment, so this is not implemented; the best cleanup is to close this duplicate and keep review concentrated on #51421. Best possible solution: Close #69138 as a duplicate and keep the remaining review and landing discussion on older open PR #51421, with #12590 as the user-facing bug report. When landing the canonical fix, preserve the pre-increment counter behavior and include regression coverage that proves memoryFlush can run on consecutive compaction cycles. What I checked:
So I’m closing this here and keeping the remaining discussion on the canonical linked item. Codex Review notes: model gpt-5.5, reasoning high; reviewed against d54d2d6b9b8a. |
Summary
memoryFlushonly fires on every other auto-compaction cycle instead of every cycle. The dedup logic falsely skips the flush becausememoryFlushCompactionCountis set to the post-increment compaction count.Root Cause
In
runMemoryFlushIfNeeded(src/auto-reply/reply/agent-runner-memory.ts), when compaction completes during a flush,incrementCompactionCountbumpscompactionCountfrom N to N+1, and thenmemoryFlushCompactionCountis overwritten to N+1 (the new count). On the next cycle,hasAlreadyFlushedForCurrentCompactioncomparesmemoryFlushCompactionCount === compactionCount→N+1 === N+1→ true → flush is incorrectly skipped.Changes
src/auto-reply/reply/agent-runner-memory.ts: Stop overwritingmemoryFlushCompactionCountwith the post-increment count. Keep it at the pre-increment value so the dedup check correctly detects a new compaction cycle.src/auto-reply/reply/agent-runner-memory.test.ts: Update test expectation to match the corrected pre-increment behavior.Test
All 50 tests pass (3 + 15 + 32).
Closes #12590