Here's a plan I extracted from another session: Fix: Skip Sentinel Wait for ACTIVE…
- User
Here's a plan I extracted from another session:
Fix: Skip Sentinel Wait for ACTIVE Sessions in PostCommit
Problem
The
entirePostCommit hook takes ~3.3 seconds even when the actual work (condensation, carry-forward) takes ~18ms. The bottleneck iswaitForTranscriptFlushin the Claude Code agent, which polls for up to 3 seconds looking for a stop sentinel that can never exist during ACTIVE sessions.Why the sentinel can't exist for ACTIVE sessions
waitForTranscriptFlushpolls the transcript JSONL for the string"hooks claude-code stop". This sentinel is written by Claude Code when its stop hook fires. During PostCommit with an ACTIVE session, the agent is still running — it hasn't stopped yet — so the sentinel is never present, and the function always hits the 3-second timeout.Where the 3s wait happens
PostCommit calls
resolveFilesTouchedfor ACTIVE sessions, which callsprepareTranscriptForState→prepareTranscriptIfNeeded→PrepareTranscript→waitForTranscriptFlush. Additionally,CondenseSessioncallsprepareTranscriptIfNeededfor ACTIVE sessions (line 134-136 ofmanual_commit_condensation.go). The wait can be hit twice per PostCommit for ACTIVE sessions.Impact
Every commit made while the agent is running (ACTIVE session) adds ~3 seconds of unnecessary wall-clock time to the PostCommit hook. Visible via
entire perf --hook post-commit.Recommended Fix
Skip the sentinel wait for ACTIVE sessions in PostCommit. The sentinel remains valuable for IDLE/ENDED sessions where the stop hook has already fired.
Why this is safe
For ACTIVE sessions, without the wait we'd read whatever transcript data is already flushed to disk — potentially missing the last few lines written between the agent's most recent flush and the commit moment. The impact is minor:
- Slightly incomplete
files_touched— might miss files mentioned in the very tail of the transcript - Slightly truncated
full.jsonlin the condensed checkpoint - Slightly off token counts
All of this is self-healing: the next commit re-condenses with the updated (now more complete) transcript. Any data missed in this checkpoint gets captured in the next one. For IDLE/ENDED sessions, the sentinel wait remains important since that may be the only condensation.
- Slightly incomplete
Assistant
Looking at this plan, I'll implement Option A as recommended — skip
PrepareTranscriptfor ACTIVE sessions at the call sites. Let me start by reading the key files.Assistant
Let me read the key files to understand the current code.
Assistant
Let me also read the
PrepareTranscriptmethod andresolveFilesTouched.Assistant
Now let me check the existing tests and the
extractSessionDatamethod to understand the second call path better.Assistant
Now let me check the
extractSessionDatafunction to see if it also callsprepareTranscriptIfNeeded.Assistant
Let me check the referenced test comment and find any other references.
Assistant
Let me check the other
prepareTranscriptIfNeededreference in hooks.Assistant
Let me see what function that 4th call site is in.
Assistant
OK, so there are 4 call sites where
PrepareTranscript/prepareTranscriptIfNeededis called for ACTIVE sessions:resolveFilesTouched→prepareTranscriptForState→prepareTranscriptIfNeeded(common.go:1468)CondenseSession→prepareTranscriptIfNeededdirectly (condensation.go:135)extractSessionData→prepareTranscriptIfNeededdirectly (condensation.go:463)hasNewTranscriptWork→PrepareTranscriptdirectly (hooks.go:1498)
And there's a 5th call in
lifecycle.go:289(the Stop hook handler) which runs for IDLE/ENDED transitions — that one is correct and should stay.Now let me also check where
hasNewTranscriptWorkis called from in PostCommit.Assistant
Let me read the full test that's referenced in the plan.
Assistant
Let me check for existing ACTIVE session timing tests.
Assistant
No existing test for ACTIVE session sentinel skip. Now I have a clear picture. Let me implement the changes.
The plan is:
- Remove sentinel wait calls for ACTIVE sessions at all 4 call sites
- Remove dead helper functions
- Add a regression test for ACTIVE session PostCommit timing
- Update comments
Assistant
Now update the comment at line 1424 that references
hasNewTranscriptWork already called PrepareTranscript.Assistant
Now fix the two condensation call sites.
Assistant
Now the
extractSessionDatacall site.Assistant
Now remove the dead helper functions from
common.go.Assistant
Now let me check if removing these functions caused any unused import issues.
Assistant
The
slogimport is now unused. Let me check what other imports might be affected.Assistant
slogis now unused. Let me remove it.Assistant
Now let me also check if removing
prepareTranscriptIfNeededcaused an unused import foragentin condensation.go.Assistant
Good, all references are removed. Let me also check that
prepareTranscriptForStateis fully gone.Assistant
There's a stale comment reference. Let me fix it.
Assistant
Now let me check if there are unused imports in the files I modified. Let me also check if removing the
PrepareTranscriptcall inhasNewTranscriptWorkleft any unused variables.Assistant
Good, the code looks clean. Now let me check if
AsTranscriptPrepareris still used in the hooks file.Assistant
Good. Now let me write the regression test. I'll add it next to the existing IDLE/ENDED sentinel skip tests.
Assistant
Now let me verify the test file compiles and the imports are correct.
Assistant
Good, the
agentimport is already there. Let me run the tests to verify everything compiles and passes.Assistant
The
agvariable inCondenseSessionis now unused. Let me check its other uses.Assistant
I need to check if
agis used anywhere else in this function.Assistant
The
agon line 104 is only used there — it was previously passed toprepareTranscriptIfNeeded. Let me remove it.Assistant
The
isActiveparameter inextractSessionDatais now unused since we removed the only use of it. Let me check the function and its callers.Assistant
The
isActiveparameter is only used at one call site and is no longer needed. Let me remove it from the function signature and the call site.Assistant
Lint passes. Now let me run the tests.
Assistant
All three tests pass quickly (~60ms each, well under the 2s threshold). Now let me run the full test suite.
Assistant
All 43 tests pass, including unit tests, integration tests, and E2E canary tests. Let me provide a summary of the changes.
Summary
Removed the ~3s sentinel wait (
waitForTranscriptFlush) for ACTIVE sessions in PostCommit. The wait polls for a stop hook sentinel that can never exist while the agent is still running, always timing out.Changes
cmd/entire/cli/strategy/manual_commit_hooks.goresolveFilesTouched: RemovedprepareTranscriptForState()callhasNewTranscriptWork: RemovedPrepareTranscriptcall for ACTIVE sessionssessionHasNewContentFromLiveTranscript: Updated stale commentextractModifiedFilesFromLiveTranscript: Updated doc comment