Skip to content

Commit 0eb285c

Browse files
committed
rewind picker: fall back to earlier prompt in multi-session checkpoints
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. Entire-Checkpoint: 0c02907cccaf
1 parent c00ae89 commit 0eb285c

2 files changed

Lines changed: 59 additions & 3 deletions

File tree

cmd/entire/cli/strategy/manual_commit_rewind.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,13 @@ func (s *ManualCommitStrategy) GetLogsOnlyRewindPoints(ctx context.Context, limi
214214
// For multi-session checkpoints, read all prompts
215215
if cpInfo.SessionCount > 1 && len(cpInfo.SessionIDs) > 1 {
216216
sessionPrompts = ReadAllSessionPromptsFromTree(metadataTree, checkpointPath, cpInfo.SessionCount, cpInfo.SessionIDs)
217-
// Use the last (most recent) prompt as the main session prompt
218-
if len(sessionPrompts) > 0 {
219-
sessionPrompt = sessionPrompts[len(sessionPrompts)-1]
217+
// Prefer the latest non-empty prompt: the most-recent session may
218+
// have been recorded without a prompt, but an earlier one usually has one.
219+
for i := len(sessionPrompts) - 1; i >= 0; i-- {
220+
if sessionPrompts[i] != "" {
221+
sessionPrompt = sessionPrompts[i]
222+
break
223+
}
220224
}
221225
} else {
222226
sessionPrompt = ReadLatestSessionPromptFromCommittedTree(metadataTree, cpInfo.CheckpointID, cpInfo.SessionCount)

cmd/entire/cli/strategy/manual_commit_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,58 @@ func TestShadowStrategy_GetRewindPoints_V11ReadsPromptFromMirror(t *testing.T) {
524524
assert.Equal(t, wantPrompt, points[0].SessionPrompt, "prompt must come from the mirror, not v1")
525525
}
526526

527+
// When the most-recent session of a multi-session condensed checkpoint has no
528+
// prompt, the picker must fall back to the latest non-empty session prompt
529+
// rather than displaying nothing.
530+
func TestShadowStrategy_GetRewindPoints_MultiSessionFallsBackToEarlierPrompt(t *testing.T) {
531+
dir := t.TempDir()
532+
testutil.InitRepo(t, dir)
533+
testutil.WriteFile(t, dir, "f.txt", "init")
534+
testutil.GitAdd(t, dir, "f.txt")
535+
testutil.GitCommit(t, dir, "init")
536+
537+
t.Chdir(dir)
538+
539+
repo, err := git.PlainOpen(dir)
540+
require.NoError(t, err)
541+
542+
cpID := id.MustCheckpointID("d4e5f6a1b2c3")
543+
const earlierPrompt = "earlier-session-prompt"
544+
545+
// Earlier session carries the only usable prompt.
546+
store := checkpoint.NewGitStore(repo)
547+
require.NoError(t, store.WriteCommitted(t.Context(), checkpoint.WriteCommittedOptions{
548+
CheckpointID: cpID,
549+
SessionID: "session-earlier",
550+
Strategy: "manual-commit",
551+
Transcript: redact.AlreadyRedacted([]byte("transcript\n")),
552+
Prompts: []string{earlierPrompt},
553+
AuthorName: "Test",
554+
AuthorEmail: "test@test.com",
555+
}))
556+
// Latest session has no prompt at all.
557+
require.NoError(t, store.WriteCommitted(t.Context(), checkpoint.WriteCommittedOptions{
558+
CheckpointID: cpID,
559+
SessionID: "session-latest",
560+
Strategy: "manual-commit",
561+
Transcript: redact.AlreadyRedacted([]byte("transcript\n")),
562+
Prompts: nil,
563+
AuthorName: "Test",
564+
AuthorEmail: "test@test.com",
565+
}))
566+
567+
testutil.WriteFile(t, dir, "g.txt", "feat")
568+
testutil.GitAdd(t, dir, "g.txt")
569+
testutil.GitCommit(t, dir, "feat\n\nEntire-Checkpoint: "+cpID.String())
570+
571+
strat := NewManualCommitStrategy()
572+
points, err := strat.GetRewindPoints(t.Context(), 10)
573+
require.NoError(t, err)
574+
require.Len(t, points, 1)
575+
assert.Equal(t, earlierPrompt, points[0].SessionPrompt,
576+
"picker must fall back to the latest non-empty session prompt when the most-recent session is empty")
577+
}
578+
527579
func TestShadowStrategy_GetSessionInfo_NoShadowBranch(t *testing.T) {
528580
dir := t.TempDir()
529581
repo, err := git.PlainInit(dir, false)

0 commit comments

Comments
 (0)