Implement the following plan: Fix: Agent mid-turn commits produce no checkpoints Context…
- User
Implement the following plan:
Fix: Agent mid-turn commits produce no checkpoints
Context
When an AI agent (Claude Code) commits during its turn — before the
Stophook firesSaveChanges()— no checkpoint is ever created. This is because:SaveChanges()runs on Stop hook, which happens AFTER the agent commits- By the time
SaveChanges()runs, the working tree is clean (agent already committed everything) - When
PostCommitfires mid-turn, it checksStepCount > 0 || FilesTouched > 0— both are 0 becauseSaveChanges()never ran - The fallback
sessionHasNewContentInCommittedFiles()tries to parse the live transcript and match files, but has 8 silentreturn falsepaths that can fail
This is issue #274. The condensation infrastructure for this case already exists (
extractSessionDataFromLiveTranscript) but is gated off by the content detection check.Change
File:
cmd/entire/cli/strategy/manual_commit_hooks.go~line 543-555Current code:
goif state.Phase.IsActive() { if state.StepCount > 0 || len(state.FilesTouched) > 0 { hasNew = true } else { hasNew = s.sessionHasNewContentInCommittedFiles(state, committedFileSet) } }Change to:
goif state.Phase.IsActive() { if state.StepCount > 0 || len(state.FilesTouched) > 0 { hasNew = true } else if state.TranscriptPath != "" { // Agent committed mid-turn before SaveChanges ran. // PrepareCommitMsg already validated this commit is session-related // (added trailer via addTrailerForAgentCommit fast path). // Trust it — the condensation code handles "no shadow branch" // by reading the live transcript directly. hasNew = true } else { hasNew = s.sessionHasNewContentInCommittedFiles(state, committedFileSet) } } Assistant
Let me read the relevant files to understand the current code.
Assistant
Now let me look at the existing test helpers and the condensation code to understand what I need to verify.
Assistant
Let me look at how existing tests verify that condensation happened (checking the metadata branch).
Assistant
Now let me look at the key test helpers I'll need.
Assistant
Now let me look at the
SessionFilePathhelper and how tests typically verify condensation.Assistant
Now I have enough context. Let me first make the code change in the hooks file.
Assistant
Now let me look at the existing test patterns more closely to write the new tests properly. I need to understand how
TestShadow_CommitBeforeStopworks and how other tests verify condensation happened.Assistant
Now let me look at how
SimulateUserPromptSubmitWithTranscriptPathandGitCommitWithShadowHooksAsAgentwork.Assistant
Good. Now I have a clear picture. Let me write the two new test functions. They follow the pattern from
TestShadowStrategy_AgentCommit_AlwaysGetsTrailerbut verify condensation.Assistant
Now let me look at how
SimulateStopwith a transcript path works, and also thesessionpackage import forPhaseActive.Assistant
Now I'll write the two new tests. I'll append them to the existing
mid_session_commit_test.gofile.Assistant
Now I'll add the two new tests. The key test is
TestAgentCommitMidTurn_CondensingWithoutSaveChangeswhich verifies that condensation actually happens (the fix). AndTestAgentCommitMidTurn_NoCondensationWithoutTranscriptwhich verifies the safety guard.Assistant
Now append the two new tests at the end of the file:
Assistant
Now let me run the verification suite. I'll start with fmt and lint in parallel, then run tests.
Assistant
I see - mise isn't installed but I can run the commands directly. Let me check lint config and run gofmt + golangci-lint + tests.
Assistant
All tests pass, including integration tests. Let me verify the specific new tests ran by checking the output more closely.
Assistant
Both new tests pass. Let me also verify the existing related tests still pass:
Assistant
All existing tests pass with no regressions. Let me update the task status.
Assistant
All done. Here's a summary of the changes:
Code change (
cmd/entire/cli/strategy/manual_commit_hooks.go):- Added
else if state.TranscriptPath != ""branch in the PostCommit hook's content detection logic (~line 550). When a session is ACTIVE withStepCount=0andFilesTouched=[](because SaveChanges never ran), but has a TranscriptPath (properly initialized via UserPromptSubmit), we now sethasNew = true. This allows condensation to proceed, and the existingextractSessionDataFromLiveTranscriptfallback handles reading the transcript directly.
New tests (
cmd/entire/cli/integration_test/mid_session_commit_test.go):TestAgentCommitMidTurn_CondensingWithoutSaveChanges— verifies the full flow: session starts, agent commits mid-turn without SaveChanges, and condensation produces a checkpoint onentire/checkpoints/v1with transcript data. Also verifies session stays ACTIVE and transitions to IDLE cleanly on Stop.TestAgentCommitMidTurn_NoCondensationWithoutTranscript— verifies the safety guard: when TranscriptPath is empty, no checkpoint data is condensed even though the agent commit fast path adds a trailer.
- Added
Assistant
The background task was just the earlier
misesearch — already handled. All work is complete. The fix and tests are ready for commit.- User
awesome go upt up a draft pr and link that issue
Assistant
No commits yet on this branch — need to commit first, then push and create the PR.