The changes in this branch are supposed to prevent unusable empty agent sessions from…
- User
The changes in this branch are supposed to prevent unusable empty agent sessions from being added to a checkpoint. I just noticed that checkpoint id 12a9a7e2ffbe still contained such a codex session. Can you debug and find out why this was still committed to a checkpoint?
Assistant· claude-opus-4-6
Let me investigate the checkpoint and the branch changes to understand what happened.
Assistant· claude-opus-4-6
Clear. Sessions 0 and 1 are Codex sessions with no transcript (
checkpoints_count: 0, no transcript file in the top-level metadata). These are the empty sessions that should have been skipped. Let me look at how condensation decides to skip or include sessions.Assistant· claude-opus-4-6
Now let me look at the PostCommit hook handler that orchestrates multi-session condensation.
Assistant· claude-opus-4-6
Now let me find the
postCommitProcessSessionfunction, which is the per-session handler:Assistant· claude-opus-4-6
Found the bug. Let me verify the specific path by checking what
state.FilesTouchedlooked like for these Codex sessions and howfilterFilesTouchedinteracts with the skip gate.Assistant· claude-opus-4-6
Here's the root cause:
The
filterFilesTouchedfallback defeats the skip gate.The flow for the empty Codex sessions:
-
extractOrCreateSessionDatahits thedefaultcase (line 382) — no shadow branch, no transcript path — returnsExtractedSessionData{FilesTouched: state.FilesTouched}wherestate.FilesTouchedis nil (Codex never called SaveStep,checkpoints_count: 0) -
filterFilesTouched(line 156) seeslen(sessionData.FilesTouched) == 0and falls into theelsebranch (line 349-355), which assigns all committed files tosessionData.FilesTouchedas a fallback for "mid-turn commits"
-
- User
Yes
Assistant· claude-opus-4-6
I already have a thorough understanding of the bug from the earlier investigation. Let me verify the existing test coverage for the skip gate and then write the plan.
Assistant· claude-opus-4-6
Now I have a complete understanding. The existing test
TestCondenseSession_SkipsWhenNoTranscriptAndNoFilespassesnilascommittedFiles, sofilterFilesTouchedreturns early and never exercises the bug path. Let me write the plan.Assistant· claude-opus-4-6
Step 1: Move the skip gate before
filterFilesTouchedAssistant· claude-opus-4-6
Now Step 2: Add the test that exercises the exact bug path.
Assistant· claude-opus-4-6
Now let me verify.
Assistant· claude-opus-4-6
Both tests pass. Let me run the full lint and test suite.
Assistant· claude-opus-4-6
All passing. Let me look at the integration test setup to add a test for this behavior.
Assistant· claude-opus-4-6
Let me look at how existing integration tests simulate multiple concurrent sessions (e.g., a Codex companion alongside Claude Code) to understand the pattern.
Assistant· claude-opus-4-6
Good — the existing
read_only_session_test.gotests read-only sessions that have transcripts but no files. The bug I'm fixing is different: sessions with no transcript AND no files wherecommittedFilesfallback inflatesFilesTouched. Let me look attestenv.gofor the helper patterns I need.Assistant· claude-opus-4-6
Now let me look at the read_only_session_test.go to understand the pattern for an "empty" session alongside a real one, and what
NewSessionWithAgentor similar helpers exist.Assistant· claude-opus-4-6
Let me look at
attach_test.goto see how Codex hooks are simulated, and also check if there's a Codex hook runner.Assistant· claude-opus-4-6
I see — Codex integration tests use the CLI binary directly, not the Claude Code hook runner. For this integration test, I need to simulate the scenario using the existing hook runner (Claude Code) to have a real session alongside a session with no transcript. Let me look at how the read_only_session test creates the scenario — it's very similar to what I need, except the "empty" session in my case has no transcript at all (not even a read-only one).
Let me look at how a session without a transcript path can be simulated. The key is: the Codex companion fires SessionStart and UserPromptSubmit but never sets a transcript path. I can model this by directly writing a session state with no transcript path, similar to what happens when Codex hooks fire.
Let me look at the pattern in the read_only test more carefully and how
GetSessionStateand direct state manipulation works.Assistant· claude-opus-4-6
Now I have a good understanding. The key difference for my test is: the empty session has no transcript at all (not even written to disk, simulating a Codex companion that never provides
transcript_path). Let me look at whatSimulateUserPromptSubmitpasses as transcript_path (it seems like it doesn't pass one by default).Assistant· claude-opus-4-6
Good —
SimulateUserPromptSubmitpasses empty transcript_path. This is exactly the pattern for Codex sessions that don't provide a transcript path. The read_only test already does this but then writes a transcript and passes the path viaSimulateStop.For my test, the empty session should never have a transcript at all. Let me also check if
SimulateStopwith no transcript works, or if I should just skip the stop entirely.Actually, the scenario I'm testing is: an empty Codex-like session is ACTIVE (or IDLE after Stop) when the user commits, and it has no transcript path and no files. Let me write the test.
Assistant· claude-opus-4-6
Let me also check the helpers
AssertCheckpointContainsSessionandAssertCheckpointExcludesSession, andCheckpointSummaryPath.Assistant· claude-opus-4-6
I have everything I need. Now let me write the integration test.
Assistant· claude-opus-4-6
Now I'll add the integration test to the end of this file, since it's closely related (empty/no-transcript session alongside a real session).
Assistant· claude-opus-4-6
Now let me run the new integration tests specifically.
Assistant· claude-opus-4-6
The
SimulateStopwith empty transcript_path fails because the hook rejects it. The ACTIVE test passed. For the IDLE test, I need to avoid callingSimulateStopwith empty transcript_path. Let me check if I can useSimulateSessionEndinstead, which transitions to ENDED without requiring a transcript path.Actually, looking at the test again — the real scenario is a Codex companion that started but never finished. The more realistic pattern is either:
- The session is still ACTIVE when the user commits (already tested and passing)
- The session ended via
session-endhook
Or I can just skip the Stop call and go directly to the commit. Let me adjust the IDLE test to use
SimulateSessionEndinstead.Assistant· claude-opus-4-6
Good,
SimulateSessionEndexists onTestEnv. I'll change the test: instead ofSimulateStop(which requires a transcript), I'll useSimulateSessionEndto move it to ENDED phase, which is more accurate for the Codex companion pattern (the session simply ends without a full Stop lifecycle).Assistant· claude-opus-4-6
Both integration tests pass. Now let me run the full suite to make sure nothing is broken.
Assistant· claude-opus-4-6
Everything passes: lint, unit tests, integration tests, and E2E canary.
Here's a summary of the changes:
manual_commit_condensation.go— Moved the skip gate (len(Transcript) == 0 && len(FilesTouched) == 0) to run beforefilterFilesTouched. This ensures the check sees the session's own tracked files, not the inflated set from the committed-files fallback. Added a comment explaining why the ordering matters.condense_skip_test.go— AddedTestCondenseSession_SkipsEmptySessionEvenWithCommittedFilesthat exercises the exact bug path: an empty session with non-nilcommittedFiles.read_only_session_test.go— Added two integration tests:TestEmptySession_NoTranscriptPath_NotCondensed— ENDED session with no transcript alongside a real sessionTestEmptySession_ActiveDuringCommit_NotCondensed— ACTIVE session with no transcript during a mid-session commit
- User
commit
Assistant· claude-opus-4-6
Committed as
2880dad0f. Working tree is clean.