Implement the following plan: Fix: Deferred condensation when live transcript is empty…
- User
Implement the following plan:
Fix: Deferred condensation when live transcript is empty at commit time
Context
CI run 22840528443 shows 42/43 cursor-cli E2E tests passing after our config isolation fix. The single failure is
TestMultiSessionSequential— a real-bug in the CLI where condensation fails silently and is never retried.Root cause: When Cursor commits mid-turn, the post-commit hook tries to condense session data to
entire/checkpoints/v1. For the second session, the live transcript file hasn't been flushed yet by Cursor, soextractSessionDataFromLiveTranscriptreturns"live transcript is empty". The checkpoint ID (1f78a5eea34d) was already written to the commit trailer byprepare-commit-msg, but:condenseAndUpdateStatereturnsfalse→handler.condensed = false- Line 1017:
if handler.condensed && state.Phase.IsActive()→ FALSE → checkpoint ID NOT recorded inTurnCheckpointIDs - At stop time,
finalizeAllTurnCheckpointsfindsTurnCheckpointIDsempty → no-op - Result: commit trailer points to nonexistent checkpoint metadata
Triage Classification
Test Agent Classification Evidence TestMultiSessionSequential cursor-cli real-bug entire.logWARN: "condensation failed: live transcript is empty"; checkpoint1f78a5eea34dmissing fromentire/checkpoints/v1treeFix: Record checkpoint IDs on attempt + deferred CondenseSession at stop time
File:
cmd/entire/cli/strategy/manual_commit_hooks.goChange 1: Add
condenseAttemptedflag topostCommitActionHandler(line 611)Add a new field alongside
condensed:gotype postCommitActionHandler struct { // ... existing fields ... condensed bool // true if condensation succeeded condenseAttempted bool // true if condensation was attempted (even if it failed) } Assistant
Let me read the key files to understand the current code before making changes.
Assistant
Now let me check
UpdateCommittedto confirm it returnsErrCheckpointNotFoundand look atCondenseSessionsignature.Assistant
Now let me check the existing test file for PostCommit tests to understand the patterns.
Assistant
Now I have enough context. Let me look at the end of the test file to know where to add new tests, and also check what imports
CondenseSessionneeds.Assistant
Now let me implement the four changes. Let me start with the code changes.
★ Insight ─────────────────────────────────────This fix addresses a timing-dependent bug specific to Cursor's commit behavior. Unlike Claude Code and Gemini which flush transcripts before committing, Cursor commits mid-turn while the transcript file is still empty. The fix introduces a two-phase approach: (1) optimistically record the checkpoint ID at attempt time, and (2) fall back to deferred condensation at stop time if the original attempt failed. This is a classic "eventual consistency" pattern — the checkpoint ID acts as a promise that gets fulfilled either immediately or later.─────────────────────────────────────────────────Assistant
Now set
condenseAttemptedin both handler methods:Assistant
Now change the guard from
handler.condensedtohandler.condenseAttemptedfor recording TurnCheckpointIDs:Assistant
Now handle
ErrCheckpointNotFoundinfinalizeAllTurnCheckpoints. Let me check the imports at the top of the file first:Assistant
Good,
checkpointis already imported. Now let me update thefinalizeAllTurnCheckpointsmethod:Assistant
Now let me check that
errorsis imported:Assistant
Need to add
errorsto imports:Assistant
Now let me add the unit tests. Let me first check what helper functions are available:
Assistant
Now I have a good understanding of the test patterns. Let me also check
HandleTurnEnd:Assistant
Now let me add the three test functions at the end of the test file:
Assistant
★ Insight ─────────────────────────────────────The key design principle here is separating intent from execution.condenseAttemptedcaptures the intent to condense (the system decided this checkpoint should be recorded), whilecondensedcaptures success (the condensation actually worked). By recording the checkpoint ID on intent, the system gets a second chance at stop time viaCondenseSession. The carry-forward and shadow branch cleanup logic correctly stays gated oncondensed— those operations only make sense when data was actually written to the metadata branch.─────────────────────────────────────────────────Now let's run the tests:
Assistant
The first test needs adjustment — condensation succeeded even with an empty transcript because
CondenseSessionhandles empty transcripts gracefully. Let me check what makes condensation actually fail:Assistant
So
condenseAndUpdateStatereturnsfalsewhenCondenseSessionreturns an error. The real Cursor bug has the error "live transcript is empty". Let me check what causes that inCondenseSession:Assistant
So the issue is that when the shadow branch doesn't exist AND the live transcript is empty,
CondenseSessionfails. But in my test, I'm callingSaveStepwhich creates the shadow branch with the transcript, so it doesn't go through theextractSessionDataFromLiveTranscriptpath.I need to adjust the first test to NOT create shadow branch content that has a transcript, or simulate the scenario more accurately. The simplest approach: don't save a transcript to the shadow branch, so that
CondenseSessionfalls back to the live transcript path, which is empty.Let me look at how
CondenseSessiondecides which path to use:Assistant
I see — when the shadow branch exists (from
SaveStep), it usesextractSessionDatawhich reads the transcript from the shadow branch tree (whereSaveStepstored it). The empty transcript scenario happens when there's NO shadow branch (Cursor commits before anySaveStep).Let me fix the first test to not call
SaveStepso there's no shadow branch, just a session state with an empty live transcript:Assistant
Let me check the
SessionStatestruct definition:Assistant
It's a type alias —
SessionState = session.State. So I should use thesession.Statefields directly, not embed it. Let me check the fields:Assistant
It's a type alias, so I should use the fields directly (not wrap in
State:):Assistant
The "no active sessions despite trailer" message means the session isn't being found by PostCommit. The state needs a
LastInteractionTimeset (for the overlap check) and might need proper initialization. Let me look at what PostCommit expects:Assistant
The session needs
WorktreePathset. Let me checkfindSessionsForWorktree:Assistant
The session needs
WorktreePathset todir. Let me fix the test:Assistant
Let me check if
timePtrexists or if I need a different approach:Assistant
Still "no active sessions". The session isn't being found. Let me check if
FullyCondensedfiltering or something else is at play. Let me also check thatsaveSessionStateis actually using the right directory:Assistant
The
sync.Onceis the problem — if a newManualCommitStrategyis used, the state store gets created once and then cached. If I create the state and then call PostCommit with a differentManualCommitStrategyinstance, the cached store may point to the wrong directory. But actually I'm using the same instance. Let me look at whatNewStateStoredoes to see if it uses cwd:Assistant
The issue is that
getGitCommonDirresolves from CWD. Since I'm usingt.Chdir(dir), it should work. But thesync.Oncemeans if I first callsaveSessionState, it initializes the store, thenPostCommituses the same cached store. That should be fine.Wait — the issue might be that the session ID doesn't pass validation. Let me check what format session IDs need:
Assistant
Session ID is fine. The actual problem must be that
findSessionsForWorktreefilters byWorktreePath. I useddirwhich is a temp dir, andpaths.WorktreeRoot()is called inPostCommit. Since It.Chdir(dir),paths.WorktreeRoot()should resolve todir. But maybe the path formats differ (symlinks, trailing slashes)?Let me look more carefully at the log — "no active sessions despite trailer" means
sessionsis empty. Let me debug by checking whatlistAllSessionStatessees:Assistant
The real problem is likely that
WorktreePathin the saved state and the resolvedworktreePathdiffer. In macOS,t.TempDir()returns/var/folders/...butpaths.WorktreeRoot()might resolve symlinks differently. Let me take a simpler approach — the other tests work fine usingsetupSessionWithCheckpoint. The key difference is they callSaveStepwhich auto-sets theWorktreePath. Let me look at howsetupSessionWithCheckpointworks:Assistant
So
WorktreePathis set somewhere during session creation. Let me check where it's first assigned inSaveStep:Assistant
Let me check how the mid-turn commit test does it — that's the closest pattern to what I need:
Assistant
I see — it uses
worktreePathwhich is likely resolved. Let me check:Assistant
There it is — on macOS, the temp dir uses a symlink (
/var/→/private/var/). I need to usepaths.WorktreeRoot()to get the resolved path. Let me fix my test:Assistant
First test passes. Now let's run all three new tests:
Assistant
All three new tests pass. Now let's run the full test suite and lint:
Assistant
All 43 tests pass, including the canary suite. Let me verify the changes are clean:
Assistant
★ Insight ─────────────────────────────────────Why this two-phase approach works across all agents:- For agents that flush transcripts before committing (Claude Code, Gemini):
condenseAttempted=trueANDcondensed=true— theErrCheckpointNotFoundfallback infinalizeAllTurnCheckpointsis never reached. Zero behavior change.
- For agents that flush transcripts before committing (Claude Code, Gemini):
- User
commit and push