Skip to content

fix: only advance memoryFlushCompactionCount when compaction ran (closes #12590)#46513

Closed
Br1an67 wants to merge 1 commit into
openclaw:mainfrom
Br1an67:fix/12590
Closed

fix: only advance memoryFlushCompactionCount when compaction ran (closes #12590)#46513
Br1an67 wants to merge 1 commit into
openclaw:mainfrom
Br1an67:fix/12590

Conversation

@Br1an67

@Br1an67 Br1an67 commented Mar 14, 2026

Copy link
Copy Markdown
Contributor

Summary

runMemoryFlushIfNeeded unconditionally persisted memoryFlushCompactionCount after every flush turn, even when compaction didn't complete during that turn. This synchronized both counters (compactionCount === memoryFlushCompactionCount), causing shouldRunMemoryFlush to return false on the next cycle — producing the "flush, skip, flush, skip" pattern.

Only persist the updated memoryFlushCompactionCount when memoryCompactionCompleted is true. When compaction doesn't run, the counters stay desynced, so the next compaction cycle correctly triggers a flush.

Change Type

Bug fix

Scope

src/auto-reply/reply/agent-runner-memory.tsrunMemoryFlushIfNeeded()

Linked Issue

Closes #12590

Security Impact

None.

Evidence

  • pnpm build passes
  • 4-line change: conditional spread replaces unconditional persist

Human Verification

  1. Enable memoryFlush in config
  2. Have a conversation that triggers multiple auto-compactions
  3. Before fix: flush runs on alternating cycles. After fix: flush runs on every cycle.

Compatibility

Backward-compatible. Existing sessions may have synced counters from the old bug; the next compaction after this fix will desync them naturally.

Risks

None — the dedup logic still prevents double-flushing within the same compaction count.

This PR was AI-assisted (fully tested with pnpm build/check/test).

@greptile-apps

greptile-apps Bot commented Mar 14, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a bug in runMemoryFlushIfNeeded where memoryFlushCompactionCount was unconditionally persisted on every flush turn, even when compaction didn't actually complete during that turn. This caused the counters compactionCount and memoryFlushCompactionCount to synchronize, making hasAlreadyFlushedForCurrentCompaction return true on the next cycle and producing the "flush, skip, flush, skip" alternating pattern.

The fix is a minimal, targeted 4-line conditional spread: memoryFlushCompactionCount is now only written to the session store when memoryCompactionCompleted is true. This keeps the counters desynced when compaction doesn't run, ensuring shouldRunMemoryFlush continues to return true on subsequent cycles as intended.

  • Core change: ...(memoryCompactionCompleted ? { memoryFlushCompactionCount } : {}) replaces the unconditional memoryFlushCompactionCount in the updateSessionStoreEntry call
  • Side effect: memoryFlushAt is still always updated (even without compaction), which is correct for tracking flush timestamp independently of the compaction counter
  • Backward compatibility: Existing sessions with synced counters will naturally desync on the next compaction cycle, as noted in the PR description

Confidence Score: 5/5

  • This PR is safe to merge — it is a small, well-scoped bug fix with no side effects on unrelated code paths.
  • The change is minimal (4 lines, one file), directly addresses the described root cause, and the logic is verified against hasAlreadyFlushedForCurrentCompaction and shouldRunMemoryFlush in memory-flush.ts. The dedup guard still prevents double-flushing within a compaction cycle. The memoryFlushAt timestamp continues to be written unconditionally, which is correct. No regressions introduced.
  • No files require special attention.

Last reviewed commit: 7e5fb5d

 openclaw#12590)

runMemoryFlushIfNeeded unconditionally persisted memoryFlushCompactionCount
after every flush turn, even when compaction didn't complete. This
synchronized both counters, causing shouldRunMemoryFlush to skip the
next cycle (flush, skip, flush, skip pattern).

Only persist the updated count when memoryCompactionCompleted is true,
so the counters stay desynced and every compaction cycle triggers a
flush as expected.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Br1an67

Br1an67 commented Mar 17, 2026

Copy link
Copy Markdown
Contributor Author

Closing to manage active PR count. Will reopen when slot is available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: memoryFlush does not fire reliably

1 participant