-
-
Notifications
You must be signed in to change notification settings - Fork 79.1k
fix: sessions.json stale after compaction transcript rotation (deadlock) #88040
Copy link
Copy link
Closed
Labels
P2Normal backlog priority with limited blast radius.Normal backlog priority with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.ClawSweeper found a clear likely implementation shape for this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.ClawSweeper marked this issue as an existing queue_fix_pr work candidate.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.impact:crash-loopCrash, hang, restart loop, or process-level availability failure.Crash, hang, restart loop, or process-level availability failure.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.Session, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.
Metadata
Metadata
Assignees
Labels
P2Normal backlog priority with limited blast radius.Normal backlog priority with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.ClawSweeper found a clear likely implementation shape for this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.ClawSweeper marked this issue as an existing queue_fix_pr work candidate.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.impact:crash-loopCrash, hang, restart loop, or process-level availability failure.Crash, hang, restart loop, or process-level availability failure.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.Session, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Summary
After compaction rotates the transcript to a new session file (
truncateAfterCompaction: true),sessions.jsonstill points to the old session file. The old file is in a stale state, and subsequent messages deadlock waiting for a session write lock that never releases.Root Cause
In
src/agents/agent-command.ts(~line 1631), when updating the session store after an agent run:sessionIdhere is resolved at the start of the run viaprepareAgentCommandExecution(). But during the run, if automatic compaction triggers andtruncateAfterCompactionis enabled,rotateTranscriptAfterCompaction()creates a new session file with a new session ID. The run's internalsessionIdUsedtracks this correctly, and it is written toresult.meta.agentMeta.sessionId.However,
updateSessionStoreAfterAgentRunignoresresult.meta.agentMeta.sessionIdand uses the caller'ssessionIdparameter. Since the caller passes the original (pre-rotation) ID,sessions.jsonis never updated to reflect the new session file.Reproduction
compaction.truncateAfterCompaction: truesessions.jsonpoints to old session file → new run tries to acquire lock on old file → timeout → deadlockFix
One-line fix in
src/agents/agent-command.ts:Impact
Any session with
truncateAfterCompaction: truethat triggers automatic compaction during a run. The/compactcommand path is unaffected (it usesincrementCompactionCountwhich handlesnewSessionIdcorrectly).Version
2026.5.22