Skip to content
This repository was archived by the owner on May 15, 2026. It is now read-only.

Commit a89acc5

Browse files
committed
fix: initial checkpoint restore now uses checkpointRestoreToBase
The initial checkpoint has no message in clineMessages (ts=0 doesn't exist), so checkpointRestore was returning early without doing anything. Now when isInitial=true is passed in the restore payload, the handler calls checkpointRestoreToBase() instead which properly restores to the baseHash without needing to find a message.
1 parent 8a433c6 commit a89acc5

3 files changed

Lines changed: 23 additions & 5 deletions

File tree

packages/types/src/vscode-extension-host.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,7 @@ export const checkoutRestorePayloadSchema = z.object({
737737
ts: z.number(),
738738
commitHash: z.string(),
739739
mode: z.enum(["preview", "restore"]),
740+
isInitial: z.boolean().optional(),
740741
})
741742

742743
export type CheckpointRestorePayload = z.infer<typeof checkoutRestorePayloadSchema>

src/core/webview/webviewMessageHandler.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,18 @@ export const webviewMessageHandler = async (
12001200
}
12011201

12021202
try {
1203-
await provider.getCurrentTask()?.checkpointRestore(result.data)
1203+
// For initial checkpoint, use checkpointRestoreToBase instead of checkpointRestore
1204+
// because there's no message with ts to find in clineMessages
1205+
if (result.data.isInitial) {
1206+
const { checkpointRestoreToBase } = await import("../checkpoints")
1207+
const success = await checkpointRestoreToBase(provider.getCurrentTask()!)
1208+
1209+
if (!success) {
1210+
vscode.window.showErrorMessage(t("common:errors.checkpoint_restore_base_failed"))
1211+
}
1212+
} else {
1213+
await provider.getCurrentTask()?.checkpointRestore(result.data)
1214+
}
12041215
} catch (error) {
12051216
vscode.window.showErrorMessage(t("common:errors.checkpoint_failed"))
12061217
}

webview-ui/src/components/chat/checkpoints/CheckpointMenu.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,20 @@ export const CheckpointMenu = ({ ts, commitHash, checkpoint, isInitial, onOpenCh
7575
}, [ts, commitHash])
7676

7777
const onPreview = useCallback(() => {
78-
vscode.postMessage({ type: "checkpointRestore", payload: { ts, commitHash, mode: "preview" } })
78+
vscode.postMessage({
79+
type: "checkpointRestore",
80+
payload: { ts, commitHash, mode: "preview", ...(isInitial && { isInitial: true }) },
81+
})
7982
setRestoreOpen(false)
80-
}, [ts, commitHash, setRestoreOpen])
83+
}, [ts, commitHash, isInitial, setRestoreOpen])
8184

8285
const onRestore = useCallback(() => {
83-
vscode.postMessage({ type: "checkpointRestore", payload: { ts, commitHash, mode: "restore" } })
86+
vscode.postMessage({
87+
type: "checkpointRestore",
88+
payload: { ts, commitHash, mode: "restore", ...(isInitial && { isInitial: true }) },
89+
})
8490
setRestoreOpen(false)
85-
}, [ts, commitHash, setRestoreOpen])
91+
}, [ts, commitHash, isInitial, setRestoreOpen])
8692

8793
const handleOpenChange = useCallback(
8894
(open: boolean) => {

0 commit comments

Comments
 (0)