Persist claude session id only after the headless turn finishes - #116
Merged
Conversation
Spec 040 shipped the non-interactive branch persisting claude_session_id before spawn + returning after a 10s liveness window; the Vault UI flips to Resume while the turn still runs, so resume fails (session not found, partial replay, two writers on one transcript). Inverts the non-interactive design: block until the detached child exits (bounded by sessionTurnTimeout = 30 min, never a kill), capture stdout to a temp file and validate the JSON (shared helper with the interactive branch), and only then persist the id. Interactive branch + scenarios/005 untouched.
…r-turn # Conflicts: # CHANGELOG.md
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.
Problem
v0.116.3/0.116.4 made the non-interactive
work-onbranch return within a ~10s liveness window while the detached headless turn kept running, and persistedclaude_session_idbefore spawning the child.That fixed the Vault UI Start timeout but shipped a worse bug in its place. The UI keys its Resume button off the mere presence of
claude_session_id, so the button flipped to Resume within ~10s — while the transcript was still being written. Clicking it and running the offeredclaude --resume <id>gave "session not found", then a few seconds later replayed only the first ~10s of work, then more on each reopen. Two writers could also land on the same jsonl.The root confusion: an id on frontmatter meant "a session exists", not "a session is resumable".
Fix
Invert the ordering. The id is persisted only after the child has exited and its turn JSON validates. An id on disk now means Resume will work.
StartSession's non-interactive branch blocks on the child'sWait, bounded bysessionTurnTimeout(30m).exec.Command,Setpgid) and survives expiry; the parent just stops waiting.Waitreturns. Unlinked eagerly, so no path leaks it.--output-format jsonvalidation (validateSessionTurn) is now shared by both branches and load-bearing:claudereports asession_ideven for a failed or zero-turn session, so exit code alone is not enough.clearSessionAndMetrics/clearGoalSessiondeleted — with post-exit ordering nothing is pre-written, so there is nothing to compensate.Also fixed, found by a test while doing the above:
persistSessionAndMetrics/persistGoalSessionIDreturned the session id even when the re-read or write failed. Nothing had landed on disk, so that reported an id the UI could not resume — the same lie one layer up. Both now return an empty id on failure.Not changed
The interactive TTY branch keeps its blocking behaviour and 5m cap. Turn 2
syscall.Execsclaude --resumeagainst turn 1's on-disk result, so blocking is exactly what makes that handoff correct.scenarios/005regression-locks it.Verification
make precommitpasses;pkg/opsis 833 specs green.scenarios/002timing note inverted: a fast return is now a FAIL, not a pass.claude --resumeverification against a completed turn is pending post-release; its absence is what let the previous bug ship.