Implement the following plan: Test: Skip transcript flush wait for idle/ended sessions…
- User
Implement the following plan:
Test: Skip transcript flush wait for idle/ended sessions
Context
We fixed a performance bug where
waitForTranscriptFlush(3s timeout) was called during prepare-commit-msg and post-commit hooks for sessions that had already flushed their transcript (IDLE/ENDED phase). The fix guardsPrepareTranscriptcalls withstate.Phase.IsActive().We need a test that verifies: when a session is IDLE or ENDED and PostCommit runs, it completes quickly without hitting the 3s sentinel timeout.
Approach
Add a timing-based test to
phase_postcommit_test.gothat:- Sets up a session with a checkpoint and a
TranscriptPathpointing to a real transcript file (important — withoutTranscriptPathset, thePrepareTranscriptcode path is never reached) - Sets the session
AgentTypetoclaude-code(triggers the sentinel wait inPrepareTranscript) - Sets phase to IDLE
- Runs
PostCommit() - Asserts it completes in under 2 seconds (well under the 3s sentinel timeout)
This is a regression test: before the fix, this test would take ~3s+ per session due to sentinel timeouts. After the fix, it completes in milliseconds.
Also add a parallel test for ENDED phase to cover both non-active states.
Why timing assertion works here
The sentinel timeout is 3s. Normal PostCommit for these tests runs in <500ms (git operations only). A 2s threshold gives generous headroom while still catching the 3s timeout regression. This is not a flaky pattern because the difference is 10-50x (milliseconds vs seconds).
Files to modify
cmd/entire/cli/strategy/phase_postcommit_test.go— add new test
Test structure
gofunc TestPostCommit_IdleSession_SkipsSentinelWait(t *testing.T) { // Setup: git repo, session with checkpoint, transcript file, AgentType=claude-code // Set phase to IDLE, set TranscriptPath to transcript file // Time PostCommit() — assert < 2s // Also verify condensation still happened correctly } func TestPostCommit_EndedSession_SkipsSentinelWait(t *testing.T) { // Same but with phase=ENDED and FilesTouched set } - Sets up a session with a checkpoint and a
Assistant
Let me read the existing test file and related source files to understand the patterns.
Assistant
Now let me check the relevant parts of the code - the
PrepareTranscriptmethod and agent types to understand the sentinel wait behavior.Assistant
Good, now I have a clear picture. The
waitForTranscriptFlushhas a 3s max timeout. The fix guardsPrepareTranscriptcalls withstate.Phase.IsActive()in bothextractNewModifiedFilesFromLiveTranscriptandextractModifiedFilesFromLiveTranscript. Let me now check the imports already used and write the test.Assistant
Now let me check the
SessionStatestruct for the relevant fields.Assistant
Good. Now I have all the context I need. Let me write the test. The key points:
- Set
state.TranscriptPathto a real file path - Set
state.AgentType = agent.AgentTypeClaudeCode(this triggersPrepareTranscript→waitForTranscriptFlushwith 3s timeout) - Set phase to IDLE/ENDED
- Time the
PostCommit()call and assert < 2s
The guard is in
extractNewModifiedFilesFromLiveTranscript(line 1151) andextractModifiedFilesFromLiveTranscript(line 1204) - both checkstate.Phase.IsActive()before callingPrepareTranscript.- Set
Assistant
Now I need to add the
agentimport and the two test functions. Let me add the import and the tests at the end of the file.Assistant
Now add the two test functions at the end of the file.
Assistant
Now let me run the tests to make sure they pass.
Assistant
The checkpoint IDs must be 12 lowercase hex characters. Let me fix them.
Assistant
Wait, "a1a2a3a4a5a6" is already used by another test. Let me use unique hex IDs.
Assistant
The IDs don't need to be globally unique across tests since each test has its own isolated repo. But
a1a2a3a4a5a6is already valid hex. Let me also fix the ENDED test ID -e1e2e3e4e5e6is valid hex too. Let me just run the tests now.Assistant
Both tests pass and complete in ~50-90ms, well under the 2s threshold. Now let me run the full test suite and lint to make sure nothing is broken.
Assistant
All tests pass, including integration tests. Formatting and linting are clean.
The two new tests verify the fix:
-
TestPostCommit_IdleSession_SkipsSentinelWait— Sets up an IDLE session withAgentType=ClaudeCodeand a realTranscriptPath, runsPostCommit(), and asserts it completes in under 2 seconds (actual: ~90ms). Before the fix, this would take 3s+ due to the sentinel timeout. -
TestPostCommit_EndedSession_SkipsSentinelWait— Same pattern but for ENDED phase. Both non-active phases should skip thePrepareTranscriptcall since their transcripts are already fully flushed.
-