fix(memory): memoryFlush fires every compaction cycle instead of every other#1160
Open
BingqingLyu wants to merge 1 commit into
Open
fix(memory): memoryFlush fires every compaction cycle instead of every other#1160BingqingLyu wants to merge 1 commit into
BingqingLyu wants to merge 1 commit into
Conversation
…y other After a memoryFlush during compaction, memoryFlushCompactionCount was reassigned to the post-increment compactionCount, locking both counters to the same value. The dedup gate hasAlreadyFlushedForCurrentCompaction then saw equal values and skipped the next flush. Fix: stop reassigning memoryFlushCompactionCount to the post-increment value. The counter stays at N (pre-increment); after incrementCompactionCount, compactionCount becomes N+1. Next cycle, N !== N+1, flush fires. Closes openclaw#12590. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
memoryFlushCompactionCountto the post-increment valueRoot cause
After a memoryFlush during compaction,
memoryFlushCompactionCountis reassigned to the post-incrementcompactionCount(line 536 ofagent-runner-memory.ts). This locks both counters to the same value. On the next cycle, the dedup gate atreply-state.tsseesmemoryFlushCompactionCount === compactionCountand skips the flush. Only after a regular compaction (without flush) incrementscompactionCountalone do the values differ again, allowing the next flush.The result: flush, skip, flush, skip — memoryFlush fires on every other compaction instead of every one.
Fix
Remove the reassignment.
memoryFlushCompactionCountstays at the pre-increment value (N). AfterincrementCompactionCount(),compactionCountbecomes N+1. Next cycle,N !== N+1, flush fires. The counter is then updated through the normal session store update path.Prior art
This issue has been reported and patch-attempted multiple times:
We've been running this fix as a local dist patch since early March 2026 with no issues.
Fixes openclaw#12590.
Test plan
reply-state.test.tstests formemoryFlushCompactionCountlogic pass🤖 Generated with Claude Code
Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com