rewind picker: fall back to earlier prompt in multi-session checkpoints · Entire
rewind picker: fall back to earlier prompt in multi-session checkpoints
0eb285c→main
pfleidi·1mo ago·2 files·+59 added/-3 removed
When a multi-session condensed checkpoint's most-recent session has no prompt, the picker previously displayed an empty prompt even when an earlier session had a usable one. Walk sessionPrompts from latest to oldest and use the first non-empty value.
Adds a TDD test that writes two sessions of the same checkpoint where the latest carries no Prompts, and asserts the picker surfaces the earlier session's prompt.
Sessions
0c02907cccafView transcript
Changes
2
cmd/entire/cli/strategy
Mmanual_commit_rewind.go+7/-3
Mmanual_commit_test.go+52
213 unmodified lines
214
215
216
217
218
219
217
218
219
220
221
222
223
224
225
226
213 unmodified lines
// For multi-session checkpoints, read all prompts
if cpInfo.SessionCount > 1 && len(cpInfo.SessionIDs) > 1 {
sessionPrompts = ReadAllSessionPromptsFromTree(metadataTree, checkpointPath, cpInfo.SessionCount, cpInfo.SessionIDs)
// Use the last (most recent) prompt as the main session prompt
if len(sessionPrompts) > 0 {
sessionPrompt = sessionPrompts[len(sessionPrompts)-1]
// Prefer the latest non-empty prompt: the most-recent session may
// have been recorded without a prompt, but an earlier one usually has one.
for i := len(sessionPrompts) - 1; i >= 0; i-- {
if sessionPrompts[i] != "" {
sessionPrompt = sessionPrompts[i]
break
}
}
} else {
sessionPrompt = ReadLatestSessionPromptFromCommittedTree(metadataTree, cpInfo.CheckpointID, cpInfo.SessionCount)
}
Mcmd/entire/cli/strategy/manual_commit_rewind.go+7/-3
523 unmodified lines
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
523 unmodified lines
assert.Equal(t, wantPrompt, points[0].SessionPrompt, "prompt must come from the mirror, not v1")
// When the most-recent session of a multi-session condensed checkpoint has no
// prompt, the picker must fall back to the latest non-empty session prompt
// rather than displaying nothing.
func TestShadowStrategy_GetRewindPoints_MultiSessionFallsBackToEarlierPrompt(t *testing.T) {
dir := t.TempDir()
testutil.InitRepo(t, dir)
testutil.WriteFile(t, dir, "f.txt", "init")
testutil.GitAdd(t, dir, "f.txt")
testutil.GitCommit(t, dir, "init")
t.Chdir(dir)
repo, err := git.PlainOpen(dir)
require.NoError(t, err)
cpID := id.MustCheckpointID("d4e5f6a1b2c3")
const earlierPrompt = "earlier-session-prompt"
// Earlier session carries the only usable prompt.
store := checkpoint.NewGitStore(repo)
require.NoError(t, store.WriteCommitted(t.Context(), checkpoint.WriteCommittedOptions{
CheckpointID: cpID,
SessionID: "session-earlier",
Strategy: "manual-commit",
Transcript: redact.AlreadyRedacted([]byte("transcript\n")),
Prompts: []string{earlierPrompt},
AuthorName: "Test",
AuthorEmail: "test@test.com",
}))
// Latest session has no prompt at all.
require.NoError(t, store.WriteCommitted(t.Context(), checkpoint.WriteCommittedOptions{
CheckpointID: cpID,
SessionID: "session-latest",
Strategy: "manual-commit",
Transcript: redact.AlreadyRedacted([]byte("transcript\n")),
Prompts: nil,
AuthorName: "Test",
AuthorEmail: "test@test.com",
}))
testutil.WriteFile(t, dir, "g.txt", "feat")
testutil.GitAdd(t, dir, "g.txt")
testutil.GitCommit(t, dir, "feat\n\nEntire-Checkpoint: "+cpID.String())
strat := NewManualCommitStrategy()
points, err := strat.GetRewindPoints(t.Context(), 10)
require.NoError(t, err)
require.Len(t, points, 1)
assert.Equal(t, earlierPrompt, points[0].SessionPrompt,
"picker must fall back to the latest non-empty session prompt when the most-recent session is empty")
}
func TestShadowStrategy_GetSessionInfo_NoShadowBranch(t *testing.T) {
dir := t.TempDir()
repo, err := git.PlainInit(dir, false)