Skip to content

Preserve turnsUsed on crash and signal finalizers - #890

Merged
TheGreatAxios merged 2 commits into
mainfrom
cl-7644-turnsused-on-handle
Sep 11, 2026
Merged

Preserve turnsUsed on crash and signal finalizers#890
TheGreatAxios merged 2 commits into
mainfrom
cl-7644-turnsused-on-handle

Conversation

@TheGreatAxios

Copy link
Copy Markdown
Collaborator

Summary

  • Crash and signal finalizers copy turnsUsed from the in-memory active-run handle instead of writing 0
  • Persist snapshots keep that handle in step so a signaled run with N persisted turns writes turnsUsed: N

Verification

  • bun run typecheck and bun run build pass
  • Focused tests for this change pass (12/12: active-run, session-start crash guard, crash/signal/exec-signal finalize)
  • bun run check hits 4 pre-existing failures unrelated to this change (createOptimizedContextStore torn-tail/hook, assembleChatAgent EROFS)

Fixes CL-7644

@linear-code

linear-code Bot commented Sep 11, 2026

Copy link
Copy Markdown

CL-7644

@TheGreatAxios TheGreatAxios left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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//clear repoints activeRunHandle.sessionId then awaits initSessionDir / buildAgent before the new running persist. A crash in that window writes the outgoing session’s turnsUsed onto 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 TheGreatAxios left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 rotation sessionId reassignment and before the new running snapshot mixes live new sessionId with outgoing turnsUsed. simulate-crash.ts leaves turnsUsed: 3 after repoint; rotation integration does not assert the count.

@TheGreatAxios
TheGreatAxios force-pushed the cl-7644-turnsused-on-handle branch from b6c1c7d to dcc7830 Compare September 11, 2026 03:09
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
TheGreatAxios force-pushed the cl-7644-turnsused-on-handle branch from dcc7830 to e021dea Compare September 11, 2026 03:11
@TheGreatAxios
TheGreatAxios merged commit 810db02 into main Sep 11, 2026
9 checks passed
@TheGreatAxios
TheGreatAxios deleted the cl-7644-turnsused-on-handle branch September 11, 2026 03:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant