Pattern: Every failing test involves an agent-initiated commit (commit happens during a turn). The checkpoint branch never advances — meaning the post-commit hook isn't producing checkpoints when Cursor makes the commit. Tests that only involve manual (user) commits all pass.
Let me look at the cursor-cli agent implementation and hook handling to understand why.
Assistant· claude-opus-4-6
Good starting point. Let me dig deeper into the actual mechanism — specifically how cursor-cli's hooks fire vs other agents.
Assistant· claude-opus-4-6
Now I see the key issue. Let me check what hookCmdPrefix returns in the E2E context — specifically whether entire is in PATH when the git hook runs inside the cursor tmux session. Let me also look at how Cursor's hooks system interacts with git hooks.
Assistant· claude-opus-4-6
Now let me look at one of the failing tests to understand the specific flow.
Assistant· claude-opus-4-6
Now I see the pattern clearly. Let me check the key difference — when cursor-cli's agent (agent binary) makes a commit, does it run the git commit through the shell in the tmux session, meaning the post-commit hook should fire? Let me check if there's something about cursor's commit flow that might bypass hooks, or if there's a PATH issue specific to cursor.
Assistant· claude-opus-4-6
Let me look at some of the passing tests that involve commits to understand the difference.
Assistant· claude-opus-4-6
Interesting — TestInteractiveMultiStep and TestMidTurnCommit_DifferentFilesThanPreviousTurn both involve agent commits and PASS for cursor-cli. Let me look at the post-commit hook logic to understand when condensation is skipped.
Assistant· claude-opus-4-6
The key insight: post-commit requires the Entire-Checkpoint trailer to advance the checkpoint branch (line 792). Let me check the prepare-commit-msg hook.
Assistant· claude-opus-4-6
Now I have the full picture. Here's my analysis:
Root Cause
All 11 cursor-cli failures have the same root cause: hasTTY() returns true in cursor's tmux session, which causes the agent-commit fast path to be skipped.
The mechanism
In manual_commit_hooks.go:376-382, there's a fast path for agent commits:
go
if !hasTTY() {
for _, state := range sessions {
if state.Phase.IsActive() {
return s.addTrailerForAgentCommit(...)
}
}
}
This adds the Entire-Checkpoint trailer directly when an agent is committing (ACTIVE session + no TTY). Without this trailer, PostCommit (line 792) sees no trailer and skips condensation → checkpoint branch never advances.
Why cursor-cli breaks this
hasTTY() (line 45-79) checks:
ENTIRE_TEST_TTY env var — not set in cursor's tmux session
GEMINI_CLI env var — not applicable
COPILOT_CLI env var — not applicable
GIT_TERMINAL_PROMPT=0 — not set
Opens /dev/tty — succeeds in tmux (tmux provides a PTY)
Good point — cursor-cli passed 5 days ago. Let me find what changed between the two runs.
Assistant· claude-opus-4-6
Only nolint comments changed in the strategy code. Let me check what changed in the E2E infrastructure and CI workflow.
Assistant· claude-opus-4-6
No changes to the cursor-cli adapter or tmux code. Let me check the CI workflow diff.
Assistant· claude-opus-4-6
The code changes are minimal — mostly roger-roger agent additions and linter bumps. The cursor-cli adapter and strategy code are essentially unchanged. Since cursor is installed fresh each CI run via curl https://cursor.com/install, let me check if the cursor CLI version changed.
Assistant· claude-opus-4-6
There it is. Different Cursor Agent CLI versions:
Passing run (Mar 11): 2026.02.27-e7d2ef6
Failing run (Mar 16): 2026.03.11-6dfa30c
Cursor released a new version on March 11 that broke things. The cursor agent CLI was updated between the two runs, and the new version likely changed how it handles git commits or hooks.
Let me check the E2E artifacts from the failing run to see what's actually happening in the test sessions.
Assistant· claude-opus-4-6
The Entire-Checkpoint trailer IS present in the commit. So the prepare-commit-msg hook worked. The issue is that post-commit didn't condense to the checkpoint branch. Let me check the debug logs.
Assistant· claude-opus-4-6
Found the actual root cause! Line 21:
code
WARN condensation failed: failed to extract session data from live transcript:
failed to read live transcript: open /home/runner/.cursor/projects/tmp-e2e-repo-1628316570/
agent-transcripts/87874108-eff2-47a0-b260-183961dd6cb0.jsonl: no such file or directory
And then line 25 shows the stop hook receives a different path:
The new Cursor CLI version (2026.03.11) switched from flat to nested transcript layout mid-session! The before-submit-prompt hook reports the flat path, but by the time the post-commit hook fires and tries to read the transcript, the file is at the nested path. The ResolveSessionFile method in cursor.go handles both layouts, but the post-commit hook is using the stored session_ref from before-submit-prompt — the flat path which doesn't exist yet (or was moved to nested).
Let me verify this is the pattern across other failing tests.
Assistant· claude-opus-4-6
Same pattern in every failing test. Here's the corrected root cause:
Actual Root Cause
The new Cursor CLI version (2026.03.11-6dfa30c) changed its transcript storage layout mid-session:
before-submit-prompt hook reports a flat path: .../agent-transcripts/<id>.jsonl
Cursor creates the transcript file at a nested path: .../agent-transcripts/<id>/<id>.jsonl
When the post-commit hook fires during the agent's turn, it tries to read the transcript from the flat path stored in session state → file not found → condensation fails → checkpoint branch never advances
The ResolveSessionFile in cursor.go:75-86 already handles both layouts — it checks nested first, then falls back to flat. But the post-commit hook isn't using ResolveSessionFile. It's using the session_ref stored during before-submit-prompt, which is the stale flat path.
The old cursor version (2026.02.27) presumably used the flat layout consistently, so the stored path was always correct.
The fix should be to re-resolve the transcript path at read time (in the post-commit/condensation flow) rather than relying on the stored session_ref from before-submit-prompt. Want me to dig into where the condensation reads the transcript to find the exact fix location?
User
yes, let's fix it
Assistant· claude-opus-4-6
Now I see the exact location. Line 521 reads from state.TranscriptPath which was set during before-submit-prompt. I need to re-resolve the path using ResolveSessionFile before reading. Let me check how TranscriptPath gets set and where the agent's session directory info is available.
Assistant· claude-opus-4-6
Now let me look at where TranscriptPath is set — it's likely in the before-submit-prompt hook handler.
Assistant· claude-opus-4-6
Now I understand the full picture. The TranscriptPath is set at before-submit-prompt time (line 1823), and is used later in extractSessionDataFromLiveTranscript (line 521). The fix should re-resolve the path using ResolveSessionFile when the stored path doesn't exist. Let me look at how to do this cleanly.
Assistant· claude-opus-4-6
The right approach is: when os.ReadFile(state.TranscriptPath) fails with a file-not-found error, re-resolve the path using the agent's ResolveSessionFile and retry. This handles the case where the transcript file moved between hooks.
Let me also check the GetSessionDir + ResolveSessionFile API to understand how to re-resolve.
Assistant· claude-opus-4-6
Now let me look at how the transcript path is resolved in the lifecycle code (stop hook) — that path works correctly (line 25 in the logs showed the nested path). This will show the right pattern.
Assistant· claude-opus-4-6
Now let me look at the lifecycle code where ResolveSessionFile is called during the stop hook (which works correctly).
Assistant· claude-opus-4-6
Now I see — event.SessionRef is what carries the transcript path through the system. The before-submit-prompt hook receives it from cursor with the flat path, and the stop hook receives it with the nested path. The issue is that the stored TranscriptPath from before-submit-prompt is stale by the time post-commit runs.
The cleanest fix is in extractSessionDataFromLiveTranscript — when the stored path fails, re-resolve using the agent's ResolveSessionFile. Let me implement this.
Assistant· claude-opus-4-6
Now let me check what info is available to re-resolve. I need the agent's GetSessionDir and ResolveSessionFile, plus the session ID. The state has AgentType and SessionID. Let me also check if we need the repoPath for GetSessionDir.
Assistant· claude-opus-4-6
The approach: when the stored TranscriptPath doesn't exist, extract the session dir and session ID from the path, then use ResolveSessionFile to get the correct path. But actually, simpler — we already have state.AgentSessionID (the cursor session ID) and the agent. Let me check the SessionState struct.
Assistant· claude-opus-4-6
Now I have the full picture. The SessionState has TranscriptPath (in session/state.go:151) and AgentType. The fix should re-resolve the transcript path when the stored one doesn't exist. The most robust approach is to add a helper that re-resolves using the agent's GetSessionDir + ResolveSessionFile.
Assistant· claude-opus-4-6
Now I have all the info. Let me also check the SessionState struct to see if it has AgentSessionID or if I need to derive it from the session ID.
Assistant· claude-opus-4-6
The SessionState has SessionID and AgentType but not AgentSessionID. Looking at the logs, the session ID IS the agent session ID (e.g., 87874108-eff2-47a0-b260-183961dd6cb0). And the TranscriptPath contains the session dir. I can derive the session dir from the stored path.
The simplest and most robust fix: when os.ReadFile(state.TranscriptPath) fails with a not-found error, use the agent's ResolveSessionFile to re-resolve, using the directory of the stored path as the session dir and the session ID.
Assistant· claude-opus-4-6
The test uses session.State but the function takes *SessionState. Let me check what SessionState is in the strategy package.
Assistant· claude-opus-4-6
SessionState is aliased as session.State. So the function signature uses *SessionState (which is *session.State), but the test uses *session.State directly. That should work since it's a type alias. The issue is that the test function name doesn't match the package — let me check the actual compilation error.
Assistant· claude-opus-4-6
Tests pass. The LSP errors were likely stale. Let me verify the full changes are correct and run the full test suite.
Assistant· claude-opus-4-6
Good — 2 new files and 2 modified files. Let me review the changes to the existing files.
Assistant· claude-opus-4-6
The changes look correct and consistent. Now let me run the full pre-commit checks.
Assistant· claude-opus-4-6
All tests pass — unit tests, integration tests, and both canary E2E suites (vogon + roger-roger). 47/47 passed.
Here's a summary of the fix:
Changes
New file: resolve_transcript.go — resolveTranscriptPath() helper that:
Returns the stored path if the file exists (fast path)
On ENOENT, re-resolves via the agent's ResolveSessionFile method
Updates state.TranscriptPath in place so subsequent reads are correct
New file: resolve_transcript_test.go — 7 unit tests covering: file exists, nested re-resolution (the Cursor bug), file not found, unknown agent, empty path, directory path, and Claude Code (no relocation).
Let me check what the existing tests cover vs what the new code paths need.
Assistant· claude-opus-4-6
The resolveTranscriptPath helper is well-covered. But the existing unit tests have a gap — none of the higher-level tests (mid-turn commit, condensation) exercise the scenario where the transcript path changes between hooks. Let me check.
Assistant· claude-opus-4-6
The existing tests cover the resolveTranscriptPath helper thoroughly, and there's an existing TestCondenseSession_PrefersLiveTranscript test that exercises the condensation-with-live-transcript path. But there's no test that verifies condensation succeeds when the transcript moves mid-session (the exact Cursor bug). That's the gap — a test that:
Sets state.TranscriptPath to a flat path
Puts the actual file at the nested path
Calls CondenseSession and verifies it succeeds
This would be the regression test ensuring the fix works end-to-end through condensation, not just through the helper. I think it's worth adding — it directly reproduces the CI failure.
Assistant· claude-opus-4-6
Good, I have the pattern. Let me add the regression test right after TestCondenseSession_PrefersLiveTranscript.
Assistant· claude-opus-4-6
Now let me add the regression test. I'll model it after TestCondenseSession_PrefersLiveTranscript but with the flat-to-nested path change.
Assistant· claude-opus-4-6
The regression test passes. Now let me make sure everything still passes together.
Assistant· claude-opus-4-6
All green. The test coverage is now:
resolveTranscriptPath unit tests (7 tests): cover all edge cases of the helper — file exists, nested re-resolution, file not found, unknown agent, empty path, directory path, Claude Code (no relocation)
TestCondenseSession_TranscriptRelocatedMidSession (new regression test): exercises the full condensation path with a stale flat path and file at the nested path, verifying CondenseSession succeeds and updates state.TranscriptPath
That covers it. The helper is well unit-tested, and the regression test reproduces the exact Cursor CI failure scenario end-to-end through the condensation pipeline.
User
simplify
/simplify
Assistant· claude-opus-4-6
Launched all three review agents in parallel. Waiting for results.
Assistant· claude-opus-4-6
Waiting for the three review agents to complete — they're still running.
Assistant· claude-opus-4-6
Good, first agent done. Waiting for the other two.
User
Findings
1. Existing function that re-resolves transcript paths or handles file-not-found-then-retry
Name collision found. There is already a function named resolveTranscriptPath in /Users/soph/Work/entire/devenv/cli/cmd/entire/cli/transcript.go (line 24). It is in the cli package (not strategy), takes different parameters (ctx, sessionID, agent), and uses a different approach: it computes the path from scratch via agent.GetSessionDir(repoRoot) + agent.ResolveSessionFile(sessionDir, sessionID). It does not do a "check-then-retry" pattern -- it always computes dynamically.
The new resolveTranscriptPath in strategy/resolve_transcript.go takes *SessionState and uses a stat-then-re-resolve approach. These are two distinct functions with the same name in sibling packages. The cli package version computes a transcript path from a session ID and agent; the strategy package version tries to fix a stale stored path. They do overlapping work (both call ResolveSessionFile) but serve different use cases.
The rewind code in manual_commit_rewind.go (lines 700-707 and 840-845) also does transcript path resolution via agent.GetSessionDir + agent.ResolveSessionFile, but it computes fresh paths (never stat-then-retry). This is similar to the cli.resolveTranscriptPath approach.
2. Existing filepath.Dir + TrimSuffix(Base, Ext) pattern for extracting session dir and agent session ID
No existing utility found. The filepath.Dir(state.TranscriptPath) + strings.TrimSuffix(filepath.Base(...), filepath.Ext(...)) decomposition at lines 44-46 of resolve_transcript.go is new. The rewind code (lines 700-707, 840-845) does the inverse -- it constructs paths from (sessionDir, sessionID) via GetSessionDir + ResolveSessionFile, rather than decomposing a stored path. No other location in the codebase extracts a session ID from a transcript path by stripping the extension.
3. Redundant agent.GetByAgentType calls in callers
Yes, redundant lookups exist in 3 of the 5 call sites.
CondenseSession (line 104): Calls GetByAgentType at line 104, then resolveTranscriptPath at line 127 calls it again internally. The from line 104 is used later (line 144 for ), so this is a redundant second lookup.
Assistant· claude-opus-4-6
Two down, one to go. Waiting for the quality review agent.
User
Summary
All findings are LOW severity. The resolveTranscriptPath function is well-designed for its purpose:
The state mutation (state.TranscriptPath = resolved) correctly ensures that repeated calls hit the fast path, making redundant invocations cost only a single os.Stat each.
The TOCTOU gap is not exploitable in the agent transcript context.
The GetByAgentType duplication is sub-microsecond cost and only triggered on the slow (re-resolution) path within resolveTranscriptPath itself.
All of these costs are dwarfed by the dominant I/O operations in the hook paths (git object reads, file parsing, potential network calls).
No changes recommended.
<total_tokens>54835</total_tokens><tool_uses>17</tool_uses><duration_ms>95895</duration_ms>
Full transcript available at: /private/tmp/claude-501/-Users-soph-Work-entire-devenv-cli/4a93df6c-18f9-424f-af2a-6ee3b41ac6aa/tasks/ad2347ef1d03b9ff6.output
User
Efficiency Review: resolveTranscriptPath
Finding 1: Redundant os.Stat in double-call path (CondenseSession -> extractSessionDataFromLiveTranscript)
Severity: LOW
In CondenseSession (line 127), resolveTranscriptPath(state) is called to eagerly resolve the path. If the code takes the !hasShadowBranch branch (line 139), it calls extractSessionDataFromLiveTranscript (line 147), which calls resolveTranscriptPath(state) again (line 526).
However, the state mutation design handles this correctly. The first call either:
Succeeds on the fast path (os.Stat finds the file), returns immediately. The second call re-Stats the same path, hits the fast path again -- one redundant os.Stat.
Succeeds on the re-resolution path, updating state.TranscriptPath. The second call then hits the fast path on the new path -- one redundant os.Stat.
The cost is a single extra os.Stat system call (~1-10 microseconds on local filesystems). This is negligible relative to the os.ReadFile that follows. Not worth refactoring.
Finding 2: Redundant agent.GetByAgentType calls
Severity: LOW
Multiple call sites call resolveTranscriptPath(state) (which internally calls GetByAgentType on the slow path only -- when the file is missing) and then immediately call GetByAgentType themselves:
hasNewTranscriptWork: resolveTranscriptPath at line 1490, then agent.GetByAgentType at line 1498.
extractModifiedFilesFromLiveTranscript: resolveTranscriptPath at line 1559, then agent.GetByAgentType at line 1567.
extractSessionDataFromLiveTranscript: resolveTranscriptPath at line 526, then agent.GetByAgentType at line 523 (actually called before resolve -- line 523 precedes 526).
CondenseSession: agent.GetByAgentType at line 104, then resolveTranscriptPath at line 127.
The code comment on GetByAgentType (line 127-134 of registry.go) explicitly states it is a linear search with ~400ns worst-case cost. With ~2-20 registered agents and lightweight factory functions, the duplicate call adds sub-microsecond overhead. The alternative -- passing an parameter to -- would complicate its API for negligible gain, since only needs the agent on the slow (re-resolution) path.
Assistant· claude-opus-4-6
All three agents are done. Let me aggregate and fix the real issues.
Actionable findings:
#
Source
Finding
Action
1
Quality
_ = resolved discard in CondenseSession is confusing
Fix: simplify call
2
Quality
Error double-wrapping: "failed to read live transcript: transcript not found at..." is misleading
Fix: pass through directly
3
Reuse
Name collision with cli.resolveTranscriptPath in transcript.go
Skip: different packages, different signatures, no ambiguity
4
Quality
Copy-paste resolve-log-bail blocks
Skip: different return types/levels/side-effects make unification worse
5
Quality
filepath.Ext multi-dot edge case
Skip: agent IDs are UUIDs, never contain dots
6
Efficiency
All findings LOW
Skip: no changes needed
7
Reuse
Redundant GetByAgentType after resolve
Skip: sub-microsecond cost, only on slow path
Assistant· claude-opus-4-6
Fix 1: Simplify the _ = resolved discard — the empty-path guard is already inside resolveTranscriptPath, so the outer check is also redundant.
Assistant· claude-opus-4-6
Fix 2: Remove the misleading "failed to read live transcript" wrapper in extractSessionDataFromLiveTranscript.
Assistant· claude-opus-4-6
gosec wants a different nolint directive. Let me fix that.
Assistant· claude-opus-4-6
All clean. Here's what the simplify pass fixed:
Removed confusing _ = resolved discard in CondenseSession — replaced with a simple resolveTranscriptPath(state) call since only the side effect matters
Removed misleading error double-wrapping in extractSessionDataFromLiveTranscript — was wrapping "transcript not found" as "failed to read live transcript", now passes through directly
Skipped findings that were false positives or not worth the trade-off (copy-paste blocks have meaningfully different behavior, GetByAgentType duplication is sub-microsecond, multi-dot filenames don't apply to UUID session IDs, all efficiency findings were LOW).
User
Summary
#
Finding
Severity
1
Side-effect-only call (_ = resolved) is clear but the dual-purpose function design adds cognitive load
Low
2
Three nearly-identical resolve-log-bail blocks in hooks; not easily unified due to differing return types/behavior, but the duplicated GetByAgentType call after resolve is wasteful
Medium
3
Double resolution is harmless (second call hits fast path after first succeeds); the early resolve is needed for the shadow-branch code path
Low
4
Triple error wrapping produces verbose, misleading messages; middle wrapper says "failed to read" when it was actually a resolution failure
Medium
5
filepath.Ext handles multi-dot filenames correctly for current agent ID formats (UUIDs), but the code has an implicit single-extension assumption that could break with future formats
1. Redundant state mutation -- side-effect-only call pattern
Severity: Low
In CondenseSession (line 127-129 of manual_commit_condensation.go):
go
if resolved, resolveErr := resolveTranscriptPath(state); resolveErr == nil {
_ = resolved // state.TranscriptPath already updated by resolveTranscriptPath
}
The _ = resolved with an explanatory comment is a code smell but is functionally correct. The function serves two purposes: it returns the path AND mutates state.TranscriptPath. At this call site, only the mutation matters. The comment makes the intent explicit.
However, the dual-purpose design (return value + side effect) violates the principle of least surprise. A reader must understand that calling this function "just for the side effect" is intentional. Consider either:
Splitting into resolveTranscriptPath(state) (string, error) (pure, no mutation) and a separate updateTranscriptPathIfNeeded(state) (mutation only), or
Documenting the side-effect-only call pattern as an acceptable usage in the function's godoc.
The existing godoc does describe the mutation, so this is minor. The pattern is safe because state is always a pointer to a mutable struct that gets saved later via saveSessionState.
2. Copy-paste boilerplate across 3 hooks call sites
Severity: Medium
The three call sites in manual_commit_hooks.go follow an almost identical pattern:
Problem: Cursor CLI 2026.03.11 changed its transcript storage layout mid-session — the before-submit-prompt hook reports a flat path (<dir>/<id>.jsonl) but by the time the agent commits, the file lives at a nested path (<dir>/<id>/<id>.jsonl). The post-commit hook tried to read from the stale flat path, failed with "no such file or directory", and silently skipped condensation. This broke all 11 E2E tests involving agent-initiated commits.
Fix: Added resolveTranscriptPath() — when the stored path doesn't exist, it re-resolves via the agent's ResolveSessionFile method (which already handles both layouts), updates state.TranscriptPath in place, and returns the correct path. Applied at all 5 call sites that read the live transcript.
Files changed:
File
Change
resolve_transcript.go
New helper: resolveTranscriptPath(state)
resolve_transcript_test.go
7 unit tests for the helper
manual_commit_condensation.go
Applied in CondenseSession (early best-effort) and extractSessionDataFromLiveTranscript
manual_commit_hooks.go
Applied in hasNewTranscriptWork, extractModifiedFilesFromLiveTranscript, finalizeAllTurnCheckpoints
Have multiple turns before the commit — prior turns' Stop hooks save content to the shadow branch, so filterSessionsWithNewContent (the fallback path after fast-path is skipped) finds content and adds the trailer
For single-turn-with-commit: no prior Stop hook → no shadow branch content → filterSessionsWithNewContent returns empty → no trailer → no checkpoint.
Fix options
Add cursor detection to hasTTY() — needs cursor's CLI binary to set an env var (like CURSOR_CLI=1), similar to Gemini/Copilot. This is the production-correct fix but requires coordination with Cursor.
Remove !hasTTY() guard when session is ACTIVE — always use the fast path for ACTIVE sessions regardless of TTY. Trade-off: humans who commit while an agent is active won't get the confirmation prompt (trailer is auto-added). This seems like reasonable default behavior.
Set GIT_TERMINAL_PROMPT=0 in cursor E2E tmux session — quick E2E-only fix, doesn't address production.
Set commit_linking: "always" in E2E settings for cursor — another E2E-only fix.
Option 2 is probably the cleanest: if a session is ACTIVE, the commit is almost certainly from the agent, and the fast path should apply regardless of TTY. Want me to implement one of these fixes?
ag
prepareTranscriptIfNeeded
extractSessionDataFromLiveTranscript (line 523): Calls GetByAgentType at line 523, then resolveTranscriptPath at line 526 calls it again. The ag from line 523 is used later for token calculation.
hasNewTranscriptWork (line 1498): Calls resolveTranscriptPath at line 1490, then calls GetByAgentType at line 1498. Only one redundant lookup here (inside resolveTranscriptPath).
extractModifiedFilesFromLiveTranscript (line 1567): Calls resolveTranscriptPath at line 1559, then calls GetByAgentType at line 1567. Same pattern as hasNewTranscriptWork.
finalizeAllTurnCheckpoints (line 2191): Calls resolveTranscriptPath at line 2191. Does NOT separately call GetByAgentType -- this is the cleanest call site with no redundancy.
In total, GetByAgentType is called twice (once inside resolveTranscriptPath, once by the caller) at 4 of the 5 call sites. The lookup goes through a registry map so it is cheap, but it is technically redundant. An alternative design would be to accept an agent.Agent parameter (or return the resolved agent alongside the path) to avoid the double-lookup.
4. Existing pattern for mutating state.TranscriptPath as a side effect
Yes, there is an existing precedent. In manual_commit_hooks.go line 1840-1841 (inside the handleUserPromptSubmit / turn-start handler), state.TranscriptPath is updated from the hook-provided transcriptPath parameter:
This is the only other place that mutates state.TranscriptPath. The new resolveTranscriptPath adds a second mutation site (line 60). Both mutations follow the same pattern of updating the field and relying on the caller to persist the state afterward. This is consistent with how other SessionState fields (e.g., LastPrompt, ModelName) are mutated by functions and then saved by the caller.
<total_tokens>41903</total_tokens><tool_uses>17</tool_uses><duration_ms>70149</duration_ms>
Full transcript available at: /private/tmp/claude-501/-Users-soph-Work-entire-devenv-cli/4a93df6c-18f9-424f-af2a-6ee3b41ac6aa/tasks/a461045f5a85f079b.output
Agent
resolveTranscriptPath
resolveTranscriptPath
Not a concern.
Finding 3: TOCTOU between os.Stat and os.ReadFile
Severity: LOW (not a real risk in this context)
The os.Stat in resolveTranscriptPath followed by os.ReadFile in callers creates a theoretical TOCTOU window. However, this is not a practical concern because:
The transcript file is owned by the agent process. Agents (Claude Code, Cursor, Gemini CLI, etc.) append to their transcript files. They do not delete or relocate them once written -- the only relocation that occurs is Cursor CLI's one-time flat-to-nested migration, which is exactly what resolveTranscriptPath handles.
The callers already handle os.ReadFile failure gracefully. For example, finalizeAllTurnCheckpoints (line 2201-2213) logs a warning and returns an error count. extractSessionDataFromLiveTranscript (line 531-533) returns an error. There is no security-sensitive operation gated on the Stat result.
Removing the Stat would not help. The only way to eliminate the TOCTOU is to replace Stat+ReadFile with just ReadFile and check for os.ErrNotExist to trigger re-resolution. This would save the Stat syscall but require restructuring the function's purpose (it would need to return the file contents, not just the path). The current design where resolveTranscriptPath is a path-resolver and callers do the I/O is cleaner for separation of concerns.
Finding 4: Hot path impact (git hook invocations)
Severity: LOW
The call sites run during post-commit and prepare-commit-msg git hooks, which are synchronous and block the user's git commit command.
The added cost per hook invocation is:
Fast path (file exists at stored location): 1 os.Stat call (~1-10 microseconds). Negligible.
For context, the hook itself does far more expensive work: opening a git repository, reading/writing shadow branches, parsing transcripts, and potentially summarizing content via an API call. The os.Stat cost is many orders of magnitude below the dominant I/O costs in these hooks.
Finding 5: sessionHasNewContentFromLiveTranscript calls hasNewTranscriptWork then extractModifiedFilesFromLiveTranscript -- triple resolve
Severity: LOW
At line 1419, hasNewTranscriptWork calls resolveTranscriptPath. If it returns true and state.FilesTouched is empty, extractModifiedFilesFromLiveTranscript is called at line 1428, which calls resolveTranscriptPath again. Both hit the fast path (first call resolved the path, second call Stats the same path). Two redundant os.Stat calls, ~20 microseconds total. Not worth refactoring.
Finding 6: CondenseSession calls GetByAgentType when the result may not be used
Severity: LOW
Line 104 of CondenseSession calls agent.GetByAgentType(state.AgentType) unconditionally. The ag result is only used at line 144 (prepareTranscriptIfNeeded) in the !hasShadowBranch path. When the shadow branch exists, the agent lookup is wasted. Cost: ~400ns. Not worth adding a conditional.
These share the same resolve-log-bail structure but differ in:
Log message prefix (function name)
Log level (Debug vs Warn)
Return value type (bool vs []string vs int)
Side-effect cleanup (state.TurnCheckpointIDs = nil in finalize)
The differences are meaningful enough that a single wrapper would need to accept callbacks or generics, which would arguably be worse. But the resolve+guard-check pair (resolve path, check empty path, resolve agent, call GetByAgentType) is duplicated between resolveTranscriptPath and the callers -- both hasNewTranscriptWork and extractModifiedFilesFromLiveTranscript call agent.GetByAgentType(state.AgentType) immediately after resolving, repeating the agent lookup that resolveTranscriptPath already does internally. This is a minor efficiency concern but mainly a readability issue -- the callers don't know that resolveTranscriptPath already validated the agent type.
3. Double resolution -- CondenseSession early resolve then extractSessionDataFromLiveTranscript resolves again
Severity: Low
In CondenseSession:
Line 126-130: Early resolution (error ignored, mutation-only).
Line 147: Calls extractSessionDataFromLiveTranscript(ctx, state) which calls resolveTranscriptPath(state) again (line 526).
The second call is NOT redundant in the worst case -- it is harmless but defensive. If the early resolve succeeds, state.TranscriptPath is updated, and the second call hits the fast path (os.Stat succeeds, returns immediately). The cost is one extra os.Stat syscall.
The early resolve serves a different purpose: it updates state.TranscriptPath before the extractSessionData branch (line 135), which uses state.TranscriptPath directly without going through resolveTranscriptPath. So the early resolve is needed for the hasShadowBranch=true path, and happens to also run on the hasShadowBranch=false path where it will be resolved again.
One minor concern: if the early resolve fails (error ignored), and then a TOCTOU race causes the file to appear before the second resolve, the second call would succeed. This is fine -- it makes the code more resilient. But it means the "errors are ignored" comment on line 125 is slightly misleading; errors aren't just ignored, they're retried.
In extractSessionDataFromLiveTranscript (line 527-528):
go
transcriptPath, resolveErr := resolveTranscriptPath(state)
if resolveErr != nil {
return nil, fmt.Errorf("failed to read live transcript: %w", resolveErr)
}
When resolveTranscriptPath returns an error, it already includes context like:
"transcript not found at /path/to/file: file does not exist"
"transcript not found at /path/to/file (also tried /other/path): file does not exist"
The caller wraps this again with "failed to read live transcript", and then CondenseSession wraps it once more (line 149):
go
return nil, fmt.Errorf("failed to extract session data from live transcript: %w", extractErr)
This produces error messages like:
code
failed to extract session data from live transcript: failed to read live transcript: transcript not found at /foo/bar.jsonl: file does not exist
Three layers of wrapping where two would suffice. The middle layer "failed to read live transcript" is misleading when the actual failure is path resolution, not reading. The caller in extractSessionDataFromLiveTranscript could just pass through the error from resolveTranscriptPath directly, or use a more accurate wrapper like "transcript path resolution failed".
Additionally, resolveTranscriptPath wraps os.ErrNotExist as a sentinel, but callers never check errors.Is(err, os.ErrNotExist) -- they just propagate. So the sentinel wrapping adds no value at the current call sites.
5. strings.TrimSuffix(base, filepath.Ext(base)) with multi-dot filenames
Severity: Medium
At line 46 of resolve_transcript.go:
go
base := filepath.Base(state.TranscriptPath)
agentSessionID := strings.TrimSuffix(base, filepath.Ext(base))
filepath.Ext returns the extension from the last dot. For session.backup.jsonl, filepath.Ext returns .jsonl, so TrimSuffix produces session.backup. This is passed to ag.ResolveSessionFile(sessionDir, "session.backup").
Looking at the actual agent implementations:
Claude Code: sessionDir + "/" + agentSessionID + ".jsonl" -- would produce session.backup.jsonl (correct, same as input)
Cursor: Same pattern, plus nested check with sessionDir/session.backup/session.backup.jsonl
Copilot CLI: sessionDir + "/" + agentSessionID + "/events.jsonl" -- completely different filename, so the session ID is used as a directory name, not a file stem. Multi-dot is safe.
Gemini CLI: Takes first 8 chars of agentSessionID and searches for session-*-<8chars>.json. Multi-dot IDs would still work.
In practice, agent session IDs are UUIDs (e.g., 87874108-eff2-47a0-b260-183961dd6cb0) or date-prefixed UUIDs. They never contain dots. So this is not a real bug today.
However, the code has an implicit assumption that transcript filenames have a single-dot extension. If a future agent used a format like session-2026.03.16.jsonl, this would break -- filepath.Ext returns .jsonl, TrimSuffix produces session-2026.03.16, which is fine. But if the format were session.2026-03-16.jsonl.gz (double extension), filepath.Ext returns .gz, and the resulting ID session.2026-03-16.jsonl would be wrong.
The more defensive approach would be strings.TrimSuffix(base, ".jsonl") with a known-extension check, or using strings.Cut to split at the first dot. But given current agent ID formats, this is a latent concern rather than an active bug.