<git_diff_from_branch_to_main>
Relevant Diff: The following is the git diff from the current branch to the main/default branch:
diff --git a/cmd/entire/cli/checkpoint/checkpoint.go b/cmd/entire/cli/checkpoint/checkpoint.go
index a2a102415..625b380d6 100644
--- a/cmd/entire/cli/checkpoint/checkpoint.go
+++ b/cmd/entire/cli/checkpoint/checkpoint.go
@@ -273,6 +273,12 @@ type WriteCommittedOptions struct {
// CheckpointTranscriptStart is written to both CommittedMetadata.CheckpointTranscriptStart
// and the deprecated CommittedMetadata.TranscriptLinesAtStart for backward compatibility.
// CompactTranscriptStart is the transcript.jsonl line offset at start of this
// checkpoint's data. Used by v2 /main where checkpoint_transcript_start in metadata
// should correspond to the compact transcript (transcript.jsonl) rather than the
// raw transcript (full.jsonl). V1 continues using CheckpointTranscriptStart.
CompactTranscriptStart int
// TokenUsage contains the token usage for this checkpoint
TokenUsage *agent.TokenUsage
Reviewing this branch as a code review pass focused on whether checkpoint_transcript_start now correctly tracks compact transcript.jsonl offsets per checkpoint. I’ll inspect the touched strategy/store paths and tests, then report concrete findings (or explicitly confirm none).
Assistant
I found one key area to verify next: whether the /main update path also keeps checkpoint_transcript_start aligned when metadata is rewritten after turn-end updates. I’m checking that now.
Assistant
Findings
Medium: Existing in-progress sessions won’t get a valid compact_transcript_start baseline after upgrade, so the next checkpoint can record in v2 metadata even when prior transcript content already exists.
User
Assistant
I’ll implement a migration/backfill so older session-state files don’t produce compact start offsets of zero after upgrade, then add/adjust tests to lock this in.
Assistant
I’m applying a focused migration fix in session state normalization so pre-existing sessions get a sensible compact start baseline immediately after upgrade.
Assistant
Implemented the fix for the upgrade/migration gap I flagged.
What I changed
Updated NormalizeAfterLoad() in cmd/entire/cli/session/state.go to backfill:
CompactTranscriptStart from CheckpointTranscriptStart when:
CompactTranscriptStart == 0
CheckpointTranscriptStart > 0
This prevents pre-existing session state files (created before compact_transcript_start existed) from incorrectly writing checkpoint_transcript_start=0 in v2 /main metadata after upgrade.
Tests added/updated
In cmd/entire/cli/session/state_test.go:
Added explicit coverage for:
backfilling compact start from checkpoint start
preserving an existing compact_transcript_start
Extended JSON round-trip table tests to assert CompactTranscriptStart behavior, including legacy and explicit compact field cases.
User
Assistant
I’ll run a strict review pass for Go idioms (state migration logic, naming/comments, error handling, and tests), then report findings ordered by severity with concrete file references.
Assistant
No idiomatic Go issues found in the branch changes.
I reviewed all files changed vs main (checkpoint, session, and strategy packages) with a Go-style lens (naming, struct field design, migration behavior, error handling, comments, and tests), and this set looks clean and consistent with existing repo conventions.
What checks I ran
go test ./cmd/entire/cli/session ./cmd/entire/cli/checkpoint ./cmd/entire/cli/strategy ✅
I’ll do a focused pass over newly added comments in this branch, trim wording where it’s verbose, and keep intent intact. Then I’ll run a quick test/lint sanity check on touched files.
Assistant
I found a few verbose comment blocks; I’m tightening them now without changing behavior.
Assistant
Condensed the newly added comments across the branch while preserving meaning.
What I tightened
cmd/entire/cli/checkpoint/checkpoint.go
Reduced CompactTranscriptStart field docs from a long multi-line explanation to a concise v1/v2 behavior statement.
cmd/entire/cli/session/state.go
Shortened the CompactTranscriptStart state field comment.
Condensed migration/backfill explanation in NormalizeAfterLoad().
Tightened inline comments on expected v2 metadata source offsets.
cmd/entire/cli/strategy/manual_commit_test.go
Shortened new test header and related step comments.
Validation
User
Assistant
I’ll create a small series of incremental commits split by concern (core compact-offset behavior, migration/tests, and comment cleanup). First I’m checking the exact current git state and recent commit style.
Assistant
I can split this cleanly into two commits from the current tree:
migration/backfill + tests, then 2) comment condensation in related files. I’m doing that now.
Assistant
Created an incremental commit on top of the existing branch work:
e6fd19cea — Backfill compact transcript start for legacy session state.
This commit includes the remaining tracked changes currently in your working tree (including the comment-condense edits), so there are no additional tracked diffs left to split right now.
"v2 /main metadata should use CompactTranscriptStart for checkpoint_transcript_start")
+}
+
func TestV2GitStore_UpdateCommitted_WritesCompactTranscript(t *testing.T) {
t.Parallel()
repo := initTestRepo(t)
diff --git a/cmd/entire/cli/session/state.go b/cmd/entire/cli/session/state.go
index 79e01eb05..4dd85186d 100644
--- a/cmd/entire/cli/session/state.go
+++ b/cmd/entire/cli/session/state.go
@@ -109,6 +109,14 @@ type State struct {
// against this value without reading the full transcript content.
CheckpointTranscriptSize int64 json:"checkpoint_transcript_size,omitempty"
// CompactTranscriptStart is the transcript.jsonl (compact format) line offset
// where the current checkpoint cycle began. Parallel to CheckpointTranscriptStart
// (which tracks full.jsonl lines). Used for v2 checkpoint metadata where
// checkpoint_transcript_start should correspond to transcript.jsonl, not full.jsonl.
// Set to 0 at session start, updated to cumulative compact line count after each
// condensation.
CompactTranscriptStart int json:"compact_transcript_start,omitempty"
// Deprecated: CondensedTranscriptLines is replaced by CheckpointTranscriptStart.
// Kept for backward compatibility with existing state files.
// Use NormalizeAfterLoad() to migrate.
diff --git a/cmd/entire/cli/strategy/manual_commit_condensation.go b/cmd/entire/cli/strategy/manual_commit_condensation.go
index 20dcf55c8..202ae4109 100644
--- a/cmd/entire/cli/strategy/manual_commit_condensation.go
+++ b/cmd/entire/cli/strategy/manual_commit_condensation.go
@@ -1,6 +1,7 @@
package strategy
+// countCompactLines returns the number of lines in a compact transcript.
+// Each line is newline-terminated by compact.appendLine, so we count '\n' bytes.
+func countCompactLines(compactTranscript []byte) int {
// writeCommittedV2IfEnabled writes checkpoint data to v2 refs when checkpoints_v2
// is enabled in settings. Failures are logged as warnings — v2 writes are
// best-effort during the dual-write period and must not block the v1 path.
diff --git a/cmd/entire/cli/strategy/manual_commit_hooks.go b/cmd/entire/cli/strategy/manual_commit_hooks.go
index e28bdce10..fbe78f8f3 100644
--- a/cmd/entire/cli/strategy/manual_commit_hooks.go
+++ b/cmd/entire/cli/strategy/manual_commit_hooks.go
@@ -1289,6 +1289,7 @@ func (s *ManualCommitStrategy) condenseAndUpdateState(
state.AttributionBaseCommit = newHead
state.StepCount = 0
state.CheckpointTranscriptStart = result.TotalTranscriptLines
// Clear attribution tracking — condensation already used these values
@@ -2649,6 +2650,7 @@ func (s *ManualCommitStrategy) carryForwardToNewShadowBranch(
// but this would complicate checkpoint retrieval and require careful tracking of dependencies.
state.StepCount = 1
state.CheckpointTranscriptStart = 0
state.CompactTranscriptStart = 0
state.CheckpointTranscriptSize = 0
state.LastCheckpointID = ""
// NOTE: TurnCheckpointIDs is intentionally NOT cleared here. Those checkpoint
diff --git a/cmd/entire/cli/strategy/manual_commit_test.go b/cmd/entire/cli/strategy/manual_commit_test.go
index b5e5c8a5c..53a079d3b 100644
--- a/cmd/entire/cli/strategy/manual_commit_test.go
+++ b/cmd/entire/cli/strategy/manual_commit_test.go
@@ -4028,6 +4028,115 @@ func TestCondenseSession_V2DualWrite(t *testing.T) {
require.NoError(t, err, "full.jsonl should exist on /full/current")
}
+// TestCondenseSession_V2CompactTranscriptStart verifies that the v2 /main metadata
+// uses the compact transcript.jsonl line offset (CompactTranscriptStart) for
+// checkpoint_transcript_start, not the full.jsonl line offset.
+func TestCondenseSession_V2CompactTranscriptStart(t *testing.T) {
"CondenseResult should report compact transcript lines")
+}
+
// TestCondenseSession_V2Disabled_NoV2Refs verifies that when checkpoints_v2 is
// not enabled, CondenseSession only writes to v1 and does not create v2 refs.
func TestCondenseSession_V2Disabled_NoV2Refs(t *testing.T) {
diff --git a/cmd/entire/cli/strategy/manual_commit_types.go b/cmd/entire/cli/strategy/manual_commit_types.go
index 65d490157..96d92e36f 100644
--- a/cmd/entire/cli/strategy/manual_commit_types.go
+++ b/cmd/entire/cli/strategy/manual_commit_types.go
@@ -53,7 +53,8 @@ type CondenseResult struct {
CheckpointsCount int
FilesTouched []string
Prompts []string // User prompts from the condensed session
TotalTranscriptLines int // Total lines in transcript after this condensation
TotalTranscriptLines int // Total lines in full.jsonl after this condensation
CompactTranscriptLines int // Lines in the compact transcript written for this checkpoint (0 if v2 disabled)
Transcript []byte // Raw transcript bytes for downstream consumers (trail title generation)
}
</git_diff_from_branch_to_main>
Review changes on transcript-start-at-metadata to ensure that transcript.jsonl files have the appropriate started_at lines so we keep track of where we're at for each new checkpoint in the transcript.jsonl file. It should be a line start offset for where we should start reading to read and display only new information for that particular checkpoint.
checkpoint_transcript_start=0
/main
222:259:cmd/entire/cli/session/state.go
func (s *State) NormalizeAfterLoad(ctx context.Context) {
// ...
if s.CheckpointTranscriptStart == 0 {
if s.CondensedTranscriptLines > 0 {
s.CheckpointTranscriptStart = s.CondensedTranscriptLines
} else if s.TranscriptLinesAtStart > 0 {
s.CheckpointTranscriptStart = s.TranscriptLinesAtStart
}
}
// ...
}
NormalizeAfterLoad migrates only legacy full-transcript fields, not CompactTranscriptStart. For active sessions created before this field existed, CompactTranscriptStart stays zero until enough new checkpoints accumulate, which can mis-scope “new info only” reads for the first post-upgrade checkpoint in transcript.jsonl.
Low (residual risk): If compact transcript generation is skipped/fails for a checkpoint, compact offsets do not advance, which can desync subsequent checkpoint_transcript_start values from compact transcript progress.
This is graceful-failure behavior, but it means one failed compact write can make later compact offsets too small.
What Looks Good
The main functional wiring is correct for new sessions: v2 /main now writes checkpoint_transcript_start from CompactTranscriptStart rather than full transcript offset.
State updates were added in all condensation paths I checked (post-commit, condense by id, fully condensed, carry-forward reset).
Added targeted tests pass locally for the new behavior (v2_store and manual_commit tests).
<git_diff_from_branch_to_main>
Relevant Diff: The following is the git diff from the current branch to the main/default branch:
diff --git a/cmd/entire/cli/checkpoint/checkpoint.go b/cmd/entire/cli/checkpoint/checkpoint.go
index a2a102415..625b380d6 100644
--- a/cmd/entire/cli/checkpoint/checkpoint.go
+++ b/cmd/entire/cli/checkpoint/checkpoint.go
@@ -273,6 +273,12 @@ type WriteCommittedOptions struct {
// CheckpointTranscriptStart is written to both CommittedMetadata.CheckpointTranscriptStart
// and the deprecated CommittedMetadata.TranscriptLinesAtStart for backward compatibility.
// CompactTranscriptStart is the transcript.jsonl line offset at start of this
// checkpoint's data. Used by v2 /main where checkpoint_transcript_start in metadata
// should correspond to the compact transcript (transcript.jsonl) rather than the
// raw transcript (full.jsonl). V1 continues using CheckpointTranscriptStart.
CompactTranscriptStart int
// TokenUsage contains the token usage for this checkpoint
TokenUsage *agent.TokenUsage
"v2 /main metadata should use CompactTranscriptStart for checkpoint_transcript_start")
+}
+
func TestV2GitStore_UpdateCommitted_WritesCompactTranscript(t *testing.T) {
t.Parallel()
repo := initTestRepo(t)
diff --git a/cmd/entire/cli/session/state.go b/cmd/entire/cli/session/state.go
index 79e01eb05..4dd85186d 100644
--- a/cmd/entire/cli/session/state.go
+++ b/cmd/entire/cli/session/state.go
@@ -109,6 +109,14 @@ type State struct {
// against this value without reading the full transcript content.
CheckpointTranscriptSize int64 json:"checkpoint_transcript_size,omitempty"
// CompactTranscriptStart is the transcript.jsonl (compact format) line offset
// where the current checkpoint cycle began. Parallel to CheckpointTranscriptStart
// (which tracks full.jsonl lines). Used for v2 checkpoint metadata where
// checkpoint_transcript_start should correspond to transcript.jsonl, not full.jsonl.
// Set to 0 at session start, updated to cumulative compact line count after each
// condensation.
CompactTranscriptStart int json:"compact_transcript_start,omitempty"
// Deprecated: CondensedTranscriptLines is replaced by CheckpointTranscriptStart.
// Kept for backward compatibility with existing state files.
// Use NormalizeAfterLoad() to migrate.
diff --git a/cmd/entire/cli/strategy/manual_commit_condensation.go b/cmd/entire/cli/strategy/manual_commit_condensation.go
index 20dcf55c8..202ae4109 100644
--- a/cmd/entire/cli/strategy/manual_commit_condensation.go
+++ b/cmd/entire/cli/strategy/manual_commit_condensation.go
@@ -1,6 +1,7 @@
package strategy
+// countCompactLines returns the number of lines in a compact transcript.
+// Each line is newline-terminated by compact.appendLine, so we count '\n' bytes.
+func countCompactLines(compactTranscript []byte) int {
// writeCommittedV2IfEnabled writes checkpoint data to v2 refs when checkpoints_v2
// is enabled in settings. Failures are logged as warnings — v2 writes are
// best-effort during the dual-write period and must not block the v1 path.
diff --git a/cmd/entire/cli/strategy/manual_commit_hooks.go b/cmd/entire/cli/strategy/manual_commit_hooks.go
index e28bdce10..fbe78f8f3 100644
--- a/cmd/entire/cli/strategy/manual_commit_hooks.go
+++ b/cmd/entire/cli/strategy/manual_commit_hooks.go
@@ -1289,6 +1289,7 @@ func (s *ManualCommitStrategy) condenseAndUpdateState(
state.AttributionBaseCommit = newHead
state.StepCount = 0
state.CheckpointTranscriptStart = result.TotalTranscriptLines
// Clear attribution tracking — condensation already used these values
@@ -2649,6 +2650,7 @@ func (s *ManualCommitStrategy) carryForwardToNewShadowBranch(
// but this would complicate checkpoint retrieval and require careful tracking of dependencies.
state.StepCount = 1
state.CheckpointTranscriptStart = 0
state.CompactTranscriptStart = 0
state.CheckpointTranscriptSize = 0
state.LastCheckpointID = ""
// NOTE: TurnCheckpointIDs is intentionally NOT cleared here. Those checkpoint
diff --git a/cmd/entire/cli/strategy/manual_commit_test.go b/cmd/entire/cli/strategy/manual_commit_test.go
index b5e5c8a5c..53a079d3b 100644
--- a/cmd/entire/cli/strategy/manual_commit_test.go
+++ b/cmd/entire/cli/strategy/manual_commit_test.go
@@ -4028,6 +4028,115 @@ func TestCondenseSession_V2DualWrite(t *testing.T) {
require.NoError(t, err, "full.jsonl should exist on /full/current")
}
+// TestCondenseSession_V2CompactTranscriptStart verifies that the v2 /main metadata
+// uses the compact transcript.jsonl line offset (CompactTranscriptStart) for
+// checkpoint_transcript_start, not the full.jsonl line offset.
+func TestCondenseSession_V2CompactTranscriptStart(t *testing.T) {
+}
+
// TestCondenseSession_V2Disabled_NoV2Refs verifies that when checkpoints_v2 is
// not enabled, CondenseSession only writes to v1 and does not create v2 refs.
func TestCondenseSession_V2Disabled_NoV2Refs(t *testing.T) {
diff --git a/cmd/entire/cli/strategy/manual_commit_types.go b/cmd/entire/cli/strategy/manual_commit_types.go
index 65d490157..96d92e36f 100644
--- a/cmd/entire/cli/strategy/manual_commit_types.go
+++ b/cmd/entire/cli/strategy/manual_commit_types.go
@@ -53,7 +53,8 @@ type CondenseResult struct {
CheckpointsCount int
FilesTouched []string
Prompts []string // User prompts from the condensed session
TotalTranscriptLines int // Total lines in transcript after this condensation
TotalTranscriptLines int // Total lines in full.jsonl after this condensation
CompactTranscriptLines int // Lines in the compact transcript written for this checkpoint (0 if v2 disabled)
Transcript []byte // Raw transcript bytes for downstream consumers (trail title generation)
}
</git_diff_from_branch_to_main>
Fix any issues found
Verification run
go test ./cmd/entire/cli/session -run "TestState_NormalizeAfterLoad" ✅
go test ./cmd/entire/cli/checkpoint -run "V2GitStore_WriteCommittedMain_UsesCompactTranscriptStart" ✅
go test ./cmd/entire/cli/strategy -run "TestCondenseSession_V2CompactTranscriptStart" ✅
Lints on edited files: ✅ no issues
<git_diff_from_branch_to_main>
Relevant Diff: The following is the git diff from the current branch to the main/default branch:
diff --git a/cmd/entire/cli/checkpoint/checkpoint.go b/cmd/entire/cli/checkpoint/checkpoint.go
index a2a102415..625b380d6 100644
--- a/cmd/entire/cli/checkpoint/checkpoint.go
+++ b/cmd/entire/cli/checkpoint/checkpoint.go
@@ -273,6 +273,12 @@ type WriteCommittedOptions struct {
// CheckpointTranscriptStart is written to both CommittedMetadata.CheckpointTranscriptStart
// and the deprecated CommittedMetadata.TranscriptLinesAtStart for backward compatibility.
// CompactTranscriptStart is the transcript.jsonl line offset at start of this
// checkpoint's data. Used by v2 /main where checkpoint_transcript_start in metadata
// should correspond to the compact transcript (transcript.jsonl) rather than the
// raw transcript (full.jsonl). V1 continues using CheckpointTranscriptStart.
CompactTranscriptStart int
// TokenUsage contains the token usage for this checkpoint
TokenUsage *agent.TokenUsage
"v2 /main metadata should use CompactTranscriptStart for checkpoint_transcript_start")
+}
+
func TestV2GitStore_UpdateCommitted_WritesCompactTranscript(t *testing.T) {
t.Parallel()
repo := initTestRepo(t)
diff --git a/cmd/entire/cli/session/state.go b/cmd/entire/cli/session/state.go
index 79e01eb05..2c9f71be4 100644
--- a/cmd/entire/cli/session/state.go
+++ b/cmd/entire/cli/session/state.go
@@ -109,6 +109,14 @@ type State struct {
// against this value without reading the full transcript content.
CheckpointTranscriptSize int64 json:"checkpoint_transcript_size,omitempty"
// CompactTranscriptStart is the transcript.jsonl (compact format) line offset
// where the current checkpoint cycle began. Parallel to CheckpointTranscriptStart
// (which tracks full.jsonl lines). Used for v2 checkpoint metadata where
// checkpoint_transcript_start should correspond to transcript.jsonl, not full.jsonl.
// Set to 0 at session start, updated to cumulative compact line count after each
// condensation.
CompactTranscriptStart int json:"compact_transcript_start,omitempty"
// Deprecated: CondensedTranscriptLines is replaced by CheckpointTranscriptStart.
// Kept for backward compatibility with existing state files.
// Use NormalizeAfterLoad() to migrate.
@@ -234,6 +242,15 @@ func (s *State) NormalizeAfterLoad(ctx context.Context) {
s.CheckpointTranscriptStart = s.TranscriptLinesAtStart
}
}
// Backfill CompactTranscriptStart for sessions created before this field existed.
// This preserves incremental "start offset" behavior for v2 checkpoint metadata
// instead of regressing to zero on the first post-upgrade condensation.
//
// Note: this is best-effort. Legacy state does not have compact-specific offsets,
// so we fall back to the existing checkpoint offset to avoid re-reading from start.
if s.CompactTranscriptStart == 0 && s.CheckpointTranscriptStart > 0 {
}
// Clear deprecated fields so they aren't re-persisted.
// Note: this is a one-way migration. If the state is re-saved, older CLI versions
// will see 0 for these fields and fall back to scoping from the transcript start.
diff --git a/cmd/entire/cli/session/state_test.go b/cmd/entire/cli/session/state_test.go
index b4742c96b..7fee6e7cf 100644
--- a/cmd/entire/cli/session/state_test.go
+++ b/cmd/entire/cli/session/state_test.go
@@ -77,6 +77,25 @@ func TestState_NormalizeAfterLoad(t *testing.T) {
assert.Equal(t, 200, state.CheckpointTranscriptStart)
assert.Equal(t, 0, state.TranscriptLinesAtStart)
})
wantCompact: 75,
},
{
name: "preserves new field over old",
json: `{"session_id":"s1","condensed_transcript_lines":10,"checkpoint_transcript_start":50}`,
wantCTS: 50,
+// countCompactLines returns the number of lines in a compact transcript.
+// Each line is newline-terminated by compact.appendLine, so we count '\n' bytes.
+func countCompactLines(compactTranscript []byte) int {
// writeCommittedV2IfEnabled writes checkpoint data to v2 refs when checkpoints_v2
// is enabled in settings. Failures are logged as warnings — v2 writes are
// best-effort during the dual-write period and must not block the v1 path.
diff --git a/cmd/entire/cli/strategy/manual_commit_hooks.go b/cmd/entire/cli/strategy/manual_commit_hooks.go
index e28bdce10..fbe78f8f3 100644
--- a/cmd/entire/cli/strategy/manual_commit_hooks.go
+++ b/cmd/entire/cli/strategy/manual_commit_hooks.go
@@ -1289,6 +1289,7 @@ func (s *ManualCommitStrategy) condenseAndUpdateState(
state.AttributionBaseCommit = newHead
state.StepCount = 0
state.CheckpointTranscriptStart = result.TotalTranscriptLines
// Clear attribution tracking — condensation already used these values
@@ -2649,6 +2650,7 @@ func (s *ManualCommitStrategy) carryForwardToNewShadowBranch(
// but this would complicate checkpoint retrieval and require careful tracking of dependencies.
state.StepCount = 1
state.CheckpointTranscriptStart = 0
state.CompactTranscriptStart = 0
state.CheckpointTranscriptSize = 0
state.LastCheckpointID = ""
// NOTE: TurnCheckpointIDs is intentionally NOT cleared here. Those checkpoint
diff --git a/cmd/entire/cli/strategy/manual_commit_test.go b/cmd/entire/cli/strategy/manual_commit_test.go
index b5e5c8a5c..53a079d3b 100644
--- a/cmd/entire/cli/strategy/manual_commit_test.go
+++ b/cmd/entire/cli/strategy/manual_commit_test.go
@@ -4028,6 +4028,115 @@ func TestCondenseSession_V2DualWrite(t *testing.T) {
require.NoError(t, err, "full.jsonl should exist on /full/current")
}
+// TestCondenseSession_V2CompactTranscriptStart verifies that the v2 /main metadata
+// uses the compact transcript.jsonl line offset (CompactTranscriptStart) for
+// checkpoint_transcript_start, not the full.jsonl line offset.
+func TestCondenseSession_V2CompactTranscriptStart(t *testing.T) {
+}
+
// TestCondenseSession_V2Disabled_NoV2Refs verifies that when checkpoints_v2 is
// not enabled, CondenseSession only writes to v1 and does not create v2 refs.
func TestCondenseSession_V2Disabled_NoV2Refs(t *testing.T) {
diff --git a/cmd/entire/cli/strategy/manual_commit_types.go b/cmd/entire/cli/strategy/manual_commit_types.go
index 65d490157..96d92e36f 100644
--- a/cmd/entire/cli/strategy/manual_commit_types.go
+++ b/cmd/entire/cli/strategy/manual_commit_types.go
@@ -53,7 +53,8 @@ type CondenseResult struct {
CheckpointsCount int
FilesTouched []string
Prompts []string // User prompts from the condensed session
TotalTranscriptLines int // Total lines in transcript after this condensation
TotalTranscriptLines int // Total lines in full.jsonl after this condensation
CompactTranscriptLines int // Lines in the compact transcript written for this checkpoint (0 if v2 disabled)
Transcript []byte // Raw transcript bytes for downstream consumers (trail title generation)
}
</git_diff_from_branch_to_main>
Review all changes on transcript-start-at-metadata for idiomatic go standards
cmd/entire/cli/strategy/manual_commit_types.go
Minor residual risk (not a style defect)
Migration backfill for CompactTranscriptStart is intentionally best-effort and uses CheckpointTranscriptStart as a fallback baseline. That’s pragmatic and reasonable, but for agents where raw transcript indexing differs from compact line indexing, first post-upgrade offsets may be approximate rather than exact.
This is acceptable given legacy data limitations and preferable to regressing to 0.
<git_diff_from_branch_to_main>
Relevant Diff: The following is the git diff from the current branch to the main/default branch:
diff --git a/cmd/entire/cli/checkpoint/checkpoint.go b/cmd/entire/cli/checkpoint/checkpoint.go
index a2a102415..625b380d6 100644
--- a/cmd/entire/cli/checkpoint/checkpoint.go
+++ b/cmd/entire/cli/checkpoint/checkpoint.go
@@ -273,6 +273,12 @@ type WriteCommittedOptions struct {
// CheckpointTranscriptStart is written to both CommittedMetadata.CheckpointTranscriptStart
// and the deprecated CommittedMetadata.TranscriptLinesAtStart for backward compatibility.
// CompactTranscriptStart is the transcript.jsonl line offset at start of this
// checkpoint's data. Used by v2 /main where checkpoint_transcript_start in metadata
// should correspond to the compact transcript (transcript.jsonl) rather than the
// raw transcript (full.jsonl). V1 continues using CheckpointTranscriptStart.
CompactTranscriptStart int
// TokenUsage contains the token usage for this checkpoint
TokenUsage *agent.TokenUsage
"v2 /main metadata should use CompactTranscriptStart for checkpoint_transcript_start")
+}
+
func TestV2GitStore_UpdateCommitted_WritesCompactTranscript(t *testing.T) {
t.Parallel()
repo := initTestRepo(t)
diff --git a/cmd/entire/cli/session/state.go b/cmd/entire/cli/session/state.go
index 79e01eb05..2c9f71be4 100644
--- a/cmd/entire/cli/session/state.go
+++ b/cmd/entire/cli/session/state.go
@@ -109,6 +109,14 @@ type State struct {
// against this value without reading the full transcript content.
CheckpointTranscriptSize int64 json:"checkpoint_transcript_size,omitempty"
// CompactTranscriptStart is the transcript.jsonl (compact format) line offset
// where the current checkpoint cycle began. Parallel to CheckpointTranscriptStart
// (which tracks full.jsonl lines). Used for v2 checkpoint metadata where
// checkpoint_transcript_start should correspond to transcript.jsonl, not full.jsonl.
// Set to 0 at session start, updated to cumulative compact line count after each
// condensation.
CompactTranscriptStart int json:"compact_transcript_start,omitempty"
// Deprecated: CondensedTranscriptLines is replaced by CheckpointTranscriptStart.
// Kept for backward compatibility with existing state files.
// Use NormalizeAfterLoad() to migrate.
@@ -234,6 +242,15 @@ func (s *State) NormalizeAfterLoad(ctx context.Context) {
s.CheckpointTranscriptStart = s.TranscriptLinesAtStart
}
}
// Backfill CompactTranscriptStart for sessions created before this field existed.
// This preserves incremental "start offset" behavior for v2 checkpoint metadata
// instead of regressing to zero on the first post-upgrade condensation.
//
// Note: this is best-effort. Legacy state does not have compact-specific offsets,
// so we fall back to the existing checkpoint offset to avoid re-reading from start.
if s.CompactTranscriptStart == 0 && s.CheckpointTranscriptStart > 0 {
}
// Clear deprecated fields so they aren't re-persisted.
// Note: this is a one-way migration. If the state is re-saved, older CLI versions
// will see 0 for these fields and fall back to scoping from the transcript start.
diff --git a/cmd/entire/cli/session/state_test.go b/cmd/entire/cli/session/state_test.go
index b4742c96b..7fee6e7cf 100644
--- a/cmd/entire/cli/session/state_test.go
+++ b/cmd/entire/cli/session/state_test.go
@@ -77,6 +77,25 @@ func TestState_NormalizeAfterLoad(t *testing.T) {
assert.Equal(t, 200, state.CheckpointTranscriptStart)
assert.Equal(t, 0, state.TranscriptLinesAtStart)
})
wantCompact: 75,
},
{
name: "preserves new field over old",
json: `{"session_id":"s1","condensed_transcript_lines":10,"checkpoint_transcript_start":50}`,
wantCTS: 50,
+// countCompactLines returns the number of lines in a compact transcript.
+// Each line is newline-terminated by compact.appendLine, so we count '\n' bytes.
+func countCompactLines(compactTranscript []byte) int {
// writeCommittedV2IfEnabled writes checkpoint data to v2 refs when checkpoints_v2
// is enabled in settings. Failures are logged as warnings — v2 writes are
// best-effort during the dual-write period and must not block the v1 path.
diff --git a/cmd/entire/cli/strategy/manual_commit_hooks.go b/cmd/entire/cli/strategy/manual_commit_hooks.go
index e28bdce10..fbe78f8f3 100644
--- a/cmd/entire/cli/strategy/manual_commit_hooks.go
+++ b/cmd/entire/cli/strategy/manual_commit_hooks.go
@@ -1289,6 +1289,7 @@ func (s *ManualCommitStrategy) condenseAndUpdateState(
state.AttributionBaseCommit = newHead
state.StepCount = 0
state.CheckpointTranscriptStart = result.TotalTranscriptLines
// Clear attribution tracking — condensation already used these values
@@ -2649,6 +2650,7 @@ func (s *ManualCommitStrategy) carryForwardToNewShadowBranch(
// but this would complicate checkpoint retrieval and require careful tracking of dependencies.
state.StepCount = 1
state.CheckpointTranscriptStart = 0
state.CompactTranscriptStart = 0
state.CheckpointTranscriptSize = 0
state.LastCheckpointID = ""
// NOTE: TurnCheckpointIDs is intentionally NOT cleared here. Those checkpoint
diff --git a/cmd/entire/cli/strategy/manual_commit_test.go b/cmd/entire/cli/strategy/manual_commit_test.go
index b5e5c8a5c..53a079d3b 100644
--- a/cmd/entire/cli/strategy/manual_commit_test.go
+++ b/cmd/entire/cli/strategy/manual_commit_test.go
@@ -4028,6 +4028,115 @@ func TestCondenseSession_V2DualWrite(t *testing.T) {
require.NoError(t, err, "full.jsonl should exist on /full/current")
}
+// TestCondenseSession_V2CompactTranscriptStart verifies that the v2 /main metadata
+// uses the compact transcript.jsonl line offset (CompactTranscriptStart) for
+// checkpoint_transcript_start, not the full.jsonl line offset.
+func TestCondenseSession_V2CompactTranscriptStart(t *testing.T) {
+}
+
// TestCondenseSession_V2Disabled_NoV2Refs verifies that when checkpoints_v2 is
// not enabled, CondenseSession only writes to v1 and does not create v2 refs.
func TestCondenseSession_V2Disabled_NoV2Refs(t *testing.T) {
diff --git a/cmd/entire/cli/strategy/manual_commit_types.go b/cmd/entire/cli/strategy/manual_commit_types.go
index 65d490157..96d92e36f 100644
--- a/cmd/entire/cli/strategy/manual_commit_types.go
+++ b/cmd/entire/cli/strategy/manual_commit_types.go
@@ -53,7 +53,8 @@ type CondenseResult struct {
CheckpointsCount int
FilesTouched []string
Prompts []string // User prompts from the condensed session
TotalTranscriptLines int // Total lines in transcript after this condensation
TotalTranscriptLines int // Total lines in full.jsonl after this condensation
CompactTranscriptLines int // Lines in the compact transcript written for this checkpoint (0 if v2 disabled)
Transcript []byte // Raw transcript bytes for downstream consumers (trail title generation)
}
</git_diff_from_branch_to_main>
Now review and condense any comments added to this branch
Targeted tests still pass:
go test ./cmd/entire/cli/session -run "TestState_NormalizeAfterLoad"
go test ./cmd/entire/cli/checkpoint -run "V2GitStore_WriteCommittedMain_UsesCompactTranscriptStart"
go test ./cmd/entire/cli/strategy -run "TestCondenseSession_V2CompactTranscriptStart"
Lints on touched files: clean.
<git_diff_from_branch_to_main>
Relevant Diff: The following is the git diff from the current branch to the main/default branch:
diff --git a/cmd/entire/cli/checkpoint/checkpoint.go b/cmd/entire/cli/checkpoint/checkpoint.go
index a2a102415..3728c8d66 100644
--- a/cmd/entire/cli/checkpoint/checkpoint.go
+++ b/cmd/entire/cli/checkpoint/checkpoint.go
@@ -273,6 +273,11 @@ type WriteCommittedOptions struct {
// CheckpointTranscriptStart is written to both CommittedMetadata.CheckpointTranscriptStart
// and the deprecated CommittedMetadata.TranscriptLinesAtStart for backward compatibility.
// CompactTranscriptStart is the transcript.jsonl line offset at checkpoint start.
// V2 /main writes this to checkpoint_transcript_start; v1 continues to use
// CheckpointTranscriptStart (full.jsonl).
CompactTranscriptStart int
// TokenUsage contains the token usage for this checkpoint
TokenUsage *agent.TokenUsage
"v2 /main metadata should use CompactTranscriptStart for checkpoint_transcript_start")
+}
+
func TestV2GitStore_UpdateCommitted_WritesCompactTranscript(t *testing.T) {
t.Parallel()
repo := initTestRepo(t)
diff --git a/cmd/entire/cli/session/state.go b/cmd/entire/cli/session/state.go
index 79e01eb05..a83c493f3 100644
--- a/cmd/entire/cli/session/state.go
+++ b/cmd/entire/cli/session/state.go
@@ -109,6 +109,11 @@ type State struct {
// against this value without reading the full transcript content.
CheckpointTranscriptSize int64 json:"checkpoint_transcript_size,omitempty"
// CompactTranscriptStart is the transcript.jsonl line offset where the current
// checkpoint cycle began. It parallels CheckpointTranscriptStart (full.jsonl)
// and is updated after each condensation.
CompactTranscriptStart int json:"compact_transcript_start,omitempty"
// Deprecated: CondensedTranscriptLines is replaced by CheckpointTranscriptStart.
// Kept for backward compatibility with existing state files.
// Use NormalizeAfterLoad() to migrate.
@@ -234,6 +239,12 @@ func (s *State) NormalizeAfterLoad(ctx context.Context) {
s.CheckpointTranscriptStart = s.TranscriptLinesAtStart
}
}
// Backfill CompactTranscriptStart for legacy sessions so v2 incremental scoping
// does not regress to zero on first post-upgrade condensation.
// Legacy state has no compact-specific offset, so we reuse checkpoint start.
if s.CompactTranscriptStart == 0 && s.CheckpointTranscriptStart > 0 {
}
// Clear deprecated fields so they aren't re-persisted.
// Note: this is a one-way migration. If the state is re-saved, older CLI versions
// will see 0 for these fields and fall back to scoping from the transcript start.
diff --git a/cmd/entire/cli/session/state_test.go b/cmd/entire/cli/session/state_test.go
index b4742c96b..7fee6e7cf 100644
--- a/cmd/entire/cli/session/state_test.go
+++ b/cmd/entire/cli/session/state_test.go
@@ -77,6 +77,25 @@ func TestState_NormalizeAfterLoad(t *testing.T) {
assert.Equal(t, 200, state.CheckpointTranscriptStart)
assert.Equal(t, 0, state.TranscriptLinesAtStart)
})
wantCompact: 75,
},
{
name: "preserves new field over old",
json: `{"session_id":"s1","condensed_transcript_lines":10,"checkpoint_transcript_start":50}`,
wantCTS: 50,
// writeCommittedV2IfEnabled writes checkpoint data to v2 refs when checkpoints_v2
// is enabled in settings. Failures are logged as warnings — v2 writes are
// best-effort during the dual-write period and must not block the v1 path.
diff --git a/cmd/entire/cli/strategy/manual_commit_hooks.go b/cmd/entire/cli/strategy/manual_commit_hooks.go
index e28bdce10..fbe78f8f3 100644
--- a/cmd/entire/cli/strategy/manual_commit_hooks.go
+++ b/cmd/entire/cli/strategy/manual_commit_hooks.go
@@ -1289,6 +1289,7 @@ func (s *ManualCommitStrategy) condenseAndUpdateState(
state.AttributionBaseCommit = newHead
state.StepCount = 0
state.CheckpointTranscriptStart = result.TotalTranscriptLines
// Clear attribution tracking — condensation already used these values
@@ -2649,6 +2650,7 @@ func (s *ManualCommitStrategy) carryForwardToNewShadowBranch(
// but this would complicate checkpoint retrieval and require careful tracking of dependencies.
state.StepCount = 1
state.CheckpointTranscriptStart = 0
state.CompactTranscriptStart = 0
state.CheckpointTranscriptSize = 0
state.LastCheckpointID = ""
// NOTE: TurnCheckpointIDs is intentionally NOT cleared here. Those checkpoint
diff --git a/cmd/entire/cli/strategy/manual_commit_test.go b/cmd/entire/cli/strategy/manual_commit_test.go
index b5e5c8a5c..24443dff1 100644
--- a/cmd/entire/cli/strategy/manual_commit_test.go
+++ b/cmd/entire/cli/strategy/manual_commit_test.go
@@ -4028,6 +4028,114 @@ func TestCondenseSession_V2DualWrite(t *testing.T) {
require.NoError(t, err, "full.jsonl should exist on /full/current")
}
+// TestCondenseSession_V2CompactTranscriptStart verifies v2 /main writes
+// checkpoint_transcript_start from compact transcript offset, not full.jsonl offset.
+func TestCondenseSession_V2CompactTranscriptStart(t *testing.T) {
+}
+
// TestCondenseSession_V2Disabled_NoV2Refs verifies that when checkpoints_v2 is
// not enabled, CondenseSession only writes to v1 and does not create v2 refs.
func TestCondenseSession_V2Disabled_NoV2Refs(t *testing.T) {
diff --git a/cmd/entire/cli/strategy/manual_commit_types.go b/cmd/entire/cli/strategy/manual_commit_types.go
index 65d490157..96d92e36f 100644
--- a/cmd/entire/cli/strategy/manual_commit_types.go
+++ b/cmd/entire/cli/strategy/manual_commit_types.go
@@ -53,7 +53,8 @@ type CondenseResult struct {
CheckpointsCount int
FilesTouched []string
Prompts []string // User prompts from the condensed session
TotalTranscriptLines int // Total lines in transcript after this condensation
TotalTranscriptLines int // Total lines in full.jsonl after this condensation
CompactTranscriptLines int // Lines in the compact transcript written for this checkpoint (0 if v2 disabled)
Transcript []byte // Raw transcript bytes for downstream consumers (trail title generation)
}
assert.Equal(t, tt.wantCompact, state.CompactTranscriptStart)
assert.Equal(t, tt.wantStep, state.StepCount)
assert.Equal(t, 0, state.CondensedTranscriptLines, "deprecated field should be cleared")
assert.Equal(t, 0, state.TranscriptLinesAtStart, "deprecated field should be cleared")
assert.Equal(t, tt.wantCompact, state.CompactTranscriptStart)
assert.Equal(t, tt.wantStep, state.StepCount)
assert.Equal(t, 0, state.CondensedTranscriptLines, "deprecated field should be cleared")
assert.Equal(t, 0, state.TranscriptLinesAtStart, "deprecated field should be cleared")
assert.Equal(t, tt.wantCompact, state.CompactTranscriptStart)
assert.Equal(t, tt.wantStep, state.StepCount)
assert.Equal(t, 0, state.CondensedTranscriptLines, "deprecated field should be cleared")
assert.Equal(t, 0, state.TranscriptLinesAtStart, "deprecated field should be cleared")