Preserve turnsUsed on crash and signal finalizers - #890
Merged
Conversation
TheGreatAxios
commented
Sep 11, 2026
TheGreatAxios
left a comment
Collaborator
Author
There was a problem hiding this comment.
Review · Comment
Crash and signal finalizers copy run.turnsUsed from the in-memory handle instead of hardcoding 0.
Findings
src/tui/runner/exit.ts:596—/new//clearrepointsactiveRunHandle.sessionIdthen awaitsinitSessionDir/buildAgentbefore the newrunningpersist. A crash in that window writes the outgoing session’sturnsUsedonto the new session. Previously this path wrote 0, which is correct for a fresh session.
Notes
- Mid-run persist syncs the handle before the first await. Exec-signal integration already prefers handle over disk.
TheGreatAxios
commented
Sep 11, 2026
TheGreatAxios
left a comment
Collaborator
Author
There was a problem hiding this comment.
Critic · Comment
Handle stays in step with persist on the primary mid-run path. Rotation is the hole.
Findings
src/tui/runner/exit.ts:596— crash after rotationsessionIdreassignment and before the newrunningsnapshot mixes live newsessionIdwith outgoingturnsUsed.simulate-crash.tsleavesturnsUsed: 3after repoint; rotation integration does not assert the count.
TheGreatAxios
force-pushed
the
cl-7644-turnsused-on-handle
branch
from
September 11, 2026 03:09
b6c1c7d to
dcc7830
Compare
Crash and signal paths previously hard-coded turnsUsed to 0 even when mid-run snapshots had already advanced the live counter. Carry the count on the active-run handle and sync it with every TUI and exec snapshot so terminal writes copy the in-memory value without reading disk.
TheGreatAxios
force-pushed
the
cl-7644-turnsused-on-handle
branch
from
September 11, 2026 03:11
dcc7830 to
e021dea
Compare
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
turnsUsedfrom the in-memory active-run handle instead of writing0turnsUsed: NVerification
bun run typecheckandbun run buildpassbun run checkhits 4 pre-existing failures unrelated to this change (createOptimizedContextStoretorn-tail/hook,assembleChatAgentEROFS)Fixes CL-7644