Skip to content

Commit f03a968

Browse files
fix(checkpoints): offer no restart after a partly rewound conversation
1 parent d02b544 commit f03a968

2 files changed

Lines changed: 47 additions & 2 deletions

File tree

‎src/core/webview/__tests__/checkpointRestoreHandler.spec.ts‎

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import type { HistoryItem } from "@roo-code/types"
33

44
import { Task } from "../../task/Task"
55
import { ClineProvider } from "../ClineProvider"
6-
import { ConversationRewindError, TaskNotRestartedError } from "../../checkpoints/ConversationRewindError"
6+
import {
7+
ConversationPartlyRewoundError,
8+
ConversationRewindError,
9+
TaskNotRestartedError,
10+
} from "../../checkpoints/ConversationRewindError"
711
import { handleCheckpointRestoreOperation, type CheckpointRestoreConfig } from "../checkpointRestoreHandler"
812
import { PendingEditOperationStore } from "../PendingEditOperationStore"
913
import { saveTaskMessages } from "../../task-persistence"
@@ -408,6 +412,43 @@ describe("checkpointRestoreHandler", () => {
408412
expect(vscode.window.showErrorMessage).toHaveBeenCalledOnce()
409413
})
410414

415+
it("does not offer to restart a deleted task whose conversation is only partly rewound, and hands an edit back", async () => {
416+
fixture.taskDouble.abort = true
417+
const partly = new ConversationRewindError(new ConversationPartlyRewoundError("only partly rewound"), {
418+
error: new Error("the task was not started again"),
419+
})
420+
fixture.taskDouble.checkpointRestore.mockRejectedValueOnce(partly)
421+
422+
await expect(handleCheckpointRestoreOperation(fixture.config)).rejects.toBe(partly)
423+
424+
// The failure is reported, and no restart is offered: it would load turns that the user cannot see.
425+
expect(vscode.window.showErrorMessage).toHaveBeenCalledOnce()
426+
expect(showWarningMessage).not.toHaveBeenCalled()
427+
expect(fixture.providerDouble.restartTaskIfCurrent).not.toHaveBeenCalled()
428+
})
429+
430+
it("hands an edit back, and offers no restart, after a partly rewound conversation of an edit", async () => {
431+
fixture.taskDouble.abort = true
432+
fixture.taskDouble.checkpointRestore.mockRejectedValueOnce(
433+
new ConversationRewindError(new ConversationPartlyRewoundError("only partly rewound"), {
434+
error: new Error("the task was not started again"),
435+
}),
436+
)
437+
438+
await expect(
439+
handleCheckpointRestoreOperation({
440+
...fixture.config,
441+
operation: "edit",
442+
editData: { editedContent: "Edited prompt", apiConversationHistoryIndex: 0 },
443+
}),
444+
).rejects.toMatchObject({ restarted: false })
445+
446+
expect(fixture.providerDouble.postMessageToWebview).toHaveBeenCalledWith(
447+
expect.objectContaining({ invoke: "setChatBoxMessage", text: "Edited prompt" }),
448+
)
449+
expect(showWarningMessage).not.toHaveBeenCalled()
450+
})
451+
411452
it("offers to restart a deleted task, since nothing started it", async () => {
412453
fixture.taskDouble.abort = true
413454
fixture.taskDouble.checkpointRestore.mockRejectedValueOnce(notRestarted())

‎src/core/webview/checkpointRestoreHandler.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Task } from "../task/Task"
22
import {
33
checkpointRestoreFailureMessage,
4+
ConversationPartlyRewoundError,
45
ConversationRewindError,
56
taskWasNotRestarted,
67
} from "../checkpoints/ConversationRewindError"
@@ -99,7 +100,10 @@ export async function handleCheckpointRestoreOperation(config: CheckpointRestore
99100
}
100101
console.error(`Error in checkpoint restore (${operation}):`, error)
101102
void vscode.window.showErrorMessage(checkpointRestoreFailureMessage(error))
102-
if (operation === "delete" && !checkpointRestored && !taskRestarted && currentCline.abort) {
103+
// A conversation that is only partly rewound is not offered a restart: it would load turns that the user cannot see.
104+
const partlyRewound =
105+
error instanceof ConversationRewindError && error.cause instanceof ConversationPartlyRewoundError
106+
if (operation === "delete" && !checkpointRestored && !taskRestarted && !partlyRewound && currentCline.abort) {
103107
try {
104108
const restart = t("common:checkpoints.restart")
105109
const response = await vscode.window.showWarningMessage(

0 commit comments

Comments
 (0)