fix: detect session file rotation in bootstrap — compaction never triggers#190
Open
glfruit wants to merge 1 commit intoMartian-Engineering:mainfrom
Open
fix: detect session file rotation in bootstrap — compaction never triggers#190glfruit wants to merge 1 commit intoMartian-Engineering:mainfrom
glfruit wants to merge 1 commit intoMartian-Engineering:mainfrom
Conversation
When OpenClaw rotates a session file (new UUID.jsonl on /reset or natural rotation), the bootstrap method previously: 1. Detected the path mismatch (new path ≠ stored path) 2. Fell through to reconcileSessionTail() 3. Found no message overlap with the old DB data → hasOverlap=false 4. Skipped persistBootstrapState() (only called when hasOverlap=true) 5. Returned 'already bootstrapped' — never ingesting new messages This created a dead loop: every subsequent bootstrap hit the same stale path, compaction never triggered, and context grew unbounded. Fix: detect the path mismatch immediately after fetching bootstrapState, purge all conversation data (context_items, summaries, messages, FTS), reset bootstrapState=null and existingCount=0, then fall through to the first-import path which handles the new file correctly. Trade-off: old summaries are lost on rotation, which is acceptable since the old conversation no longer exists.
This was referenced Mar 26, 2026
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.
Bug: Session file rotation breaks bootstrap — compaction never triggers, context overflows
Environment
Description
When OpenClaw rotates a session file (creates a new UUID.jsonl on
/resetor natural rotation), LCM'sbootstrap()method fails to detect and handle the change. The new session file's messages are never ingested into the LCM database, compaction never triggers, and the main session's context grows unbounded until it hits the context limit.Root Cause
In
src/engine.ts, thebootstrap()method tracks sessions by absolute file path in theconversation_bootstrap_statetable. When a session file rotates:Line 1735 —
bootstrapState.sessionFilePath === params.sessionFileisfalse(new path ≠ old path), so the "file unchanged" fast path is skipped. ✅ Correct so far.Line 1752 — Same path comparison in the incremental append path. Also skipped. ✅ Correct.
Line 1844 — Falls through to
reconcileSessionTail(). This reads the new file's messages and tries to find a "anchor" message that exists in both the new file and the DB. Since the new file is from a post-reset session, no messages overlap with the old DB data →anchorIndex = -1→ returns{ importedMessages: 0, hasOverlap: false }.Line 1908 — Only updates
bootstrapStatewhenreconcile.hasOverlap === true. Since it'sfalse, the old file path remains in the DB.Line 1910 —
conversation.bootstrappedAtistruefrom the prior session → returns"already bootstrapped".Result: A dead loop. Every subsequent bootstrap call sees the same stale path, takes the same reconcile path, finds no overlap, and never ingests new messages. Compaction depends on DB token counts which never grow → compaction never triggers.
Evidence from production
compaction_eventstable: 0 rows (never compacted)conversationstable: session tracked wrong.jsonlfile (815KB, stale)compactionAttempts: 0/1Reproduction Steps
/resetor trigger session file rotation in OpenClawProposed Fix
Add session file rotation detection in
bootstrap(), right after fetchingbootstrapStateand before the path-comparison guards. When a path change is detected, purge all conversation data and re-bootstrap as a fresh conversation.Also requires changing
const existingCount→let existingCountandconst bootstrapState→let bootstrapState.Trade-offs
Secondary Issue (unrelated)
ZAI_API_KEYwas found empty (length=0) in the LCM auth cascade, which would cause summarization to fail auth even if bootstrap worked. This is a configuration issue, not a code bug.