From 7ee88cc638962aeb36cf3d15990e38a02d8ee708 Mon Sep 17 00:00:00 2001 From: Hannes Rudolph Date: Thu, 29 Jan 2026 13:59:33 -0700 Subject: [PATCH] fix: add missing checkpointRestoreToBase function This function was in the old PR #10908 but was not included when we created the new branch from origin/main. It's needed for restoring to the initial checkpoint state. --- src/core/checkpoints/index.ts | 38 +++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/core/checkpoints/index.ts b/src/core/checkpoints/index.ts index d29e4ee301..1859b45ca9 100644 --- a/src/core/checkpoints/index.ts +++ b/src/core/checkpoints/index.ts @@ -326,6 +326,44 @@ export async function checkpointRestore( } } +/** + * Restore to the initial checkpoint (base state when task started). + * This is used by the InitialCheckpoint component since it doesn't have a message timestamp. + */ +export async function checkpointRestoreToBase(task: Task): Promise { + const service = await getCheckpointService(task) + + if (!service) { + return false + } + + const baseHash = service.baseHash + + if (!baseHash) { + const provider = task.providerRef.deref() + provider?.log("[checkpointRestoreToBase] no baseHash available") + return false + } + + const provider = task.providerRef.deref() + + try { + await service.restoreCheckpoint(baseHash) + TelemetryService.instance.captureCheckpointRestored(task.taskId) + await provider?.postMessageToWebview({ type: "currentCheckpointUpdated", text: baseHash }) + + // Cancel the task to reinitialize with the restored state + // This follows the same pattern as checkpointRestore + provider?.cancelTask() + + return true + } catch (err) { + provider?.log("[checkpointRestoreToBase] disabling checkpoints for this task") + task.enableCheckpoints = false + return false + } +} + export type CheckpointDiffOptions = { ts?: number previousCommitHash?: string