fix: clear adopted legacy transcript offsets · Entire

fix: clear adopted legacy transcript offsets

7beae84→main·

peyton-alt·3w ago·3 files·+46 added/-2

Sessions

db8b4bffc8b4View transcript

[?
--enable hooks and amake sure entire is enabled in this session and you're up to date on latest version and main pleaseCodex·GPT-5.5·10 steps](/content/gh/entireio/cli/session/019ed5fe-ec49-7a72-89fd-f38e323f5448#timeline-db8b4bffc8b4/index.html)

Changes

3

363 unmodified lines

364
365
366
367
368
367
368
369
370
10 unmodified lines

381
382
383
384
385
386
387
388
389
390
391
392
393
394

363 unmodified lines

// will see 0 for these fields and fall back to scoping from the transcript start.
    // This is acceptable since CLI upgrades are monotonic and the worst case is
    // redundant transcript content in a condensation, not data loss.
    s.CondensedTranscriptLines = 0
    s.TranscriptLinesAtStart = 0
    s.ClearLegacyTranscriptOffsets()

// Backfill AttributionBaseCommit for sessions created before this field existed.
    // Without this, a mid-turn commit would migrate BaseCommit and the fallback in
10 unmodified lines

}
}

// ClearLegacyTranscriptOffsets clears deprecated transcript offset fields so
// callers that intentionally reset CheckpointTranscriptStart do not re-persist
// stale legacy state.
func (s *State) ClearLegacyTranscriptOffsets() {
    s.CondensedTranscriptLines = 0
    s.TranscriptLinesAtStart = 0
}

// RealignAttributionBase sets AttributionBaseCommit to newBase and clears any
// bookkeeping whose meaning depends on attribution being diverged from the
// shadow-branch base. Call this every time a code path intentionally brings

Mcmd/entire/cli/session/state.go+9/-2

253 unmodified lines

254
255
256
257
258
259
260

253 unmodified lines

adopted.CheckpointTranscriptStart = 0
    adopted.CheckpointTranscriptSize = 0
    adopted.TranscriptIdentifierAtStart = ""
    adopted.ClearLegacyTranscriptOffsets()
    adopted.TurnCheckpointIDs = nil
    adopted.LastCheckpointID = id.EmptyCheckpointID
    adopted.LastCheckpointCommitHash = ""

Mcmd/entire/cli/session_adopt.go+1

2 unmodified lines

3
4
5
6
7
8
9
294 unmodified lines

304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344

2 unmodified lines

import (
    "bytes"
    "context"
    "encoding/json"
    "os"
    "os/exec"
    "path/filepath"
294 unmodified lines

}
}

func TestSessionAdopt_ClearsLegacyTranscriptOffsets(t *testing.T) {
    targetRepo := setupAdoptRepo(t)
    testutil.WriteFile(t, targetRepo, "feature.txt", "agent change\n")
    t.Chdir(targetRepo)

adopted, _, err := buildAdoptedSessionState(context.Background(), &session.State{
        SessionID:                 "test-adopt-legacy-offsets",
        AgentType:                 agent.AgentTypeClaudeCode,
        StartedAt:                 time.Now().Add(-5 * time.Minute),
        Phase:                     session.PhaseActive,
        BaseCommit:                "source-head",
        WorktreePath:              "/source/repo",
        CheckpointTranscriptStart: 9,
        CondensedTranscriptLines:  9,
        TranscriptLinesAtStart:    9,
    })
    if err != nil {
        t.Fatalf("buildAdoptedSessionState failed: %v", err)
    }
    if adopted.CheckpointTranscriptStart != 0 {
        t.Fatalf("CheckpointTranscriptStart = %d, want 0", adopted.CheckpointTranscriptStart)
    }

encoded, err := json.Marshal(adopted)
    if err != nil {
        t.Fatal(err)
    }
    if bytes.Contains(encoded, []byte("condensed_transcript_lines")) {
        t.Fatalf("adopted state JSON contains condensed_transcript_lines: %s", encoded)
    }
    if bytes.Contains(encoded, []byte("transcript_lines_at_start")) {
        t.Fatalf("adopted state JSON contains transcript_lines_at_start: %s", encoded)
    }
}

func TestSessionAdopt_FromSubdirectoryReadsSourceStore(t *testing.T) {
    sourceRepo := setupAdoptRepo(t)
    targetRepo := setupAdoptRepo(t)