I think there might be a bug... here's an example: checkpointtranscriptstart is set to…
- User
I think there might be a bug... here's an example:
checkpoint_transcript_start is set to 4.
the transcript is:
{"v":1,"agent":"claude-code","cli_version":"dev","type":"user","ts":"2026-04-10T17:05:36.940Z","content":[{"id":"5d450845-926a-446d-9d34-28da9462d395","text":"Add another line now that says "this is step three, adding on to the same transcript""}]} {"v":1,"agent":"claude-code","cli_version":"dev","type":"assistant","ts":"2026-04-10T17:05:40.173Z","id":"msg_016wAstLyCPRo1RssseNgEgo","input_tokens":3,"output_tokens":139,"content":[{"id":"toolu_01Phu6xk5shpY56QyG9SuSS3","input":{"replace_all":false,"file_path":"/Users/ninawork/entire/test-repos/test-repo/test-compact-transcript/steps.md","old_string":"this is step two now\n","new_string":"this is step two now\nthis is step three, adding on to the same transcript\n"},"name":"Edit","result":{"output":"The file /Users/ninawork/entire/test-repos/test-repo/test-compact-transcript/steps.md has been updated successfully.","status":"success","file":{"filePath":"/Users/ninawork/entire/test-repos/test-repo/test-compact-transcript/steps.md"}},"type":"tool_use"}]} {"v":1,"agent":"claude-code","cli_version":"dev","type":"assistant","ts":"2026-04-10T17:05:44.786Z","id":"REDACTED","input_tokens":1,"output_tokens":21,"content":[{"text":"Done. Added the new line to
test-compact-transcript/steps.md.","type":"text"}]}The bug is we're saying start at 4, but the transcript is in reverse order, so the newest stuff is first...
Assistant· claude-opus-4-6
Let me look at how
checkpoint_transcript_startis used and how transcripts are ordered.Assistant· claude-opus-4-6
Now let me look at the specific code that writes the transcript to shadow branches - I need to understand the order transcripts are stored in.
Assistant· claude-opus-4-6
Now let me look at how the transcript is stored on shadow branches - specifically the order when writing to the shadow branch.
Assistant· claude-opus-4-6
Now let me look at how the transcript is read from the live file and what order the lines are in. The user says the transcript has the newest entries first. Let me check how Claude Code writes its transcript.
Assistant· claude-opus-4-6
Now I need to understand how Claude Code writes its JSONL transcript. The question is whether it appends (oldest first) or prepends (newest first). Let me check how the transcript is actually read from the Claude Code session.
Assistant· claude-opus-4-6
Let me look at how the transcript gets stored on the shadow branch to understand if the order gets reversed.
Assistant· claude-opus-4-6
Let me look at how compact transcripts are generated - this might be where the reverse ordering happens.
Assistant· claude-opus-4-6
Now let me look at the
compact.Compactfunction, specifically how it handles theStartLineparameter.Assistant· claude-opus-4-6
Let me check how v2 checkpoints store and read back compact transcripts.
Assistant· claude-opus-4-6
Now let me look at how this
checkpoint_transcript_startis consumed when reading back. Let me check what reads the compact transcript and applies the start offset.Assistant· claude-opus-4-6
Let me look at how v2 accumulates the compact transcript on
/main- specifically whether it prepends or appends new content.Assistant· claude-opus-4-6
Let me check what transcript is read for display purposes and how it's loaded.
- User
[Request interrupted by user]
- User
I think there might be a bug... here's an example:
checkpoint_transcript_start is set to 4.
the transcript is:
{"v":1,"agent":"claude-code","cli_version":"dev","type":"user","ts":"2026-04-10T17:05:36.940Z","content":[{"id":"5d450845-926a-446d-9d34-28da9462d395","text":"Add another line now that says "this is step three, adding on to the same transcript""}]} {"v":1,"agent":"claude-code","cli_version":"dev","type":"assistant","ts":"2026-04-10T17:05:40.173Z","id":"msg_016wAstLyCPRo1RssseNgEgo","input_tokens":3,"output_tokens":139,"content":[{"id":"toolu_01Phu6xk5shpY56QyG9SuSS3","input":{"replace_all":false,"file_path":"/Users/ninawork/entire/test-repos/test-repo/test-compact-transcript/steps.md","old_string":"this is step two now\n","new_string":"this is step two now\nthis is step three, adding on to the same transcript\n"},"name":"Edit","result":{"output":"The file /Users/ninawork/entire/test-repos/test-repo/test-compact-transcript/steps.md has been updated successfully.","status":"success","file":{"filePath":"/Users/ninawork/entire/test-repos/test-repo/test-compact-transcript/steps.md"}},"type":"tool_use"}]} {"v":1,"agent":"claude-code","cli_version":"dev","type":"assistant","ts":"2026-04-10T17:05:44.786Z","id":"REDACTED","input_tokens":1,"output_tokens":21,"content":[{"text":"Done. Added the new line to .","type":"text"}]}
Assistant· claude-opus-4-6
Let me look at what you've been working on for this branch to understand the context better.
Assistant· claude-opus-4-6
Now let me understand what
opts.Transcriptis when passed to the condensation write path - is it the FULL or SCOPED transcript?Assistant· claude-opus-4-6
I see the issue. Let me confirm my understanding of the data flow:
Assistant· claude-opus-4-6
OK, I now understand the data flow clearly. Here's what I see:
The compact
transcript.jsonlstored per-checkpoint on v2/mainis already scoped —compactTranscriptForV2()callscompact.Compact(transcript, MetadataFields{StartLine: checkpointTranscriptStart}), which internally doesSliceFromLine(content, startLine)before compacting. So the stored compact transcript only contains this checkpoint's portion (your 3 lines).But
checkpoint_transcript_startin the metadata says 4 — this is the offset calculated bycomputeCompactTranscriptStart(), representing where these 3 lines would sit in a cumulative compact transcript across all checkpoints.The bug: if a consumer reads the per-checkpoint compact
transcript.jsonl(which has 3 lines, already scoped) and tries to applycheckpoint_transcript_start=4via , they'd skip past all 3 lines and get nothing. The offset is meaningless for the already-scoped compact transcript stored alongside it.- User
Assistant· claude-opus-4-6
Now I understand the bug clearly. Let me trace the exact issue.
The problem is in
compactTranscriptForV2()atmanual_commit_condensation.go:1119:gocompacted, err := compact.Compact(transcript, compact.MetadataFields{ StartLine: checkpointTranscriptStart, // ← scopes to only NEW content })This produces a compact transcript with only the new lines (3 lines for checkpoint 2). Then
writeMainSessionToSubdirectoryreplaces the previoustranscript.jsonlin the session subdirectory. So the cumulative compact transcript from checkpoint 1 (4 lines) is lost — overwritten with just the 3 new lines.The fix: store the full cumulative compact transcript (
StartLine: 0), while keeping the scoped compact for line counting sostate.CompactTranscriptStartaccumulates correctly.Assistant· claude-opus-4-6
Now I need to:
- Generate the scoped compact (for line counting / offset calc)
- Generate the full compact (for storage)
- Store the full compact but count the scoped lines
Assistant· claude-opus-4-6
Now let me check if there's a similar issue in the other condensation paths (
CondenseSessionByIDandCondenseAndMarkFullyCondensed), since those also updatestate.CompactTranscriptStart.Assistant· claude-opus-4-6
Both callers do
state.CompactTranscriptStart += result.CompactTranscriptLines. TheCompactTranscriptLinesis now computed asfullLines - CompactTranscriptStart, which gives the scoped count. Let me verify the math:- Checkpoint 1:
CompactTranscriptStart=0, full compact has 4 lines →compactLines = 4 - 0 = 4→state.CompactTranscriptStart = 0 + 4 = 4 - Checkpoint 2:
CompactTranscriptStart=4, full compact has 7 lines →compactLines = 7 - 4 = 3→state.CompactTranscriptStart = 4 + 3 = 7
That's correct. Let me also verify the existing test to make sure I understand the expected behavior.
- Checkpoint 1:
Assistant· claude-opus-4-6
Good, the existing test only checks the first checkpoint (where
checkpoint_transcript_start=0). It doesn't test the second checkpoint where the bug manifests. Let me now run the existing tests to make sure my change doesn't break anything.Assistant· claude-opus-4-6
Now let me add a test that exercises the multi-checkpoint scenario to verify the fix.
Assistant· claude-opus-4-6
Now let me look at the
pathspackage for the compact transcript file name.Assistant· claude-opus-4-6
Now let me write the test. I'll extend the existing test to add a second checkpoint and verify the compact transcript is cumulative.
Assistant· claude-opus-4-6
Now let me check if the test file imports
bytesandstrings.Assistant· claude-opus-4-6
Need to add
bytesimport.Assistant· claude-opus-4-6
Test passes. Let me run the broader test suite to make sure nothing else broke.
Assistant· claude-opus-4-6
All strategy tests pass. Let me also run the compact transcript tests and the checkpoint tests.
Assistant· claude-opus-4-6
Let me run the full test suite as required by the project guidelines.
Assistant· claude-opus-4-6
All tests pass — unit, integration, and canary E2E.
Here's a summary of the fix:
Bug:
compactTranscriptForV2()was called withStartLine: checkpointTranscriptStart, which truncated the raw transcript before compacting. This produced a compacttranscript.jsonlcontaining only the new checkpoint's content. Since v2/mainreplaces the session'stranscript.jsonlon each write, the previous checkpoint's compact content was lost. The result: checkpoint 2'stranscript.jsonlhad 3 lines (just the new content), whilecheckpoint_transcript_start=4implied it should be cumulative.Fix in
manual_commit_condensation.go:- Generate a scoped compact (new content only) for line counting and offset calculation
- Generate a full compact (
StartLine: 0) for storage on v2/main - Derive
CompactTranscriptLinesasfullLines - CompactTranscriptStart(the scoped count) sostate.CompactTranscriptStartaccumulates correctly