Skip to content

Commit 4df4b51

Browse files
committed
fix: ensure checkpoint service is undefined on initialization error and improve checkpoint diff handling
1 parent ff3e40f commit 4df4b51

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

src/core/assistant-message/presentAssistantMessage.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -580,10 +580,20 @@ export async function presentAssistantMessage(cline: Task) {
580580
presentAssistantMessage(cline)
581581
}
582582
}
583-
async function checkpointSaveAndMark(cline: Task) {
584-
if (cline.currentStreamingDidCheckpoint) {
583+
584+
/**
585+
* save checkpoint and mark done in the current streaming task.
586+
* @param task The Task instance to checkpoint save and mark.
587+
* @returns
588+
*/
589+
async function checkpointSaveAndMark(task: Task) {
590+
if (task.currentStreamingDidCheckpoint) {
585591
return
586592
}
587-
await cline.checkpointSave(true)
588-
cline.currentStreamingDidCheckpoint = true
593+
try {
594+
await task.checkpointSave(true)
595+
task.currentStreamingDidCheckpoint = true
596+
} catch (error) {
597+
console.error(`[Task#presentAssistantMessage] Error saving checkpoint: ${error.message}`, error)
598+
}
589599
}

src/core/checkpoints/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ async function checkGitInstallation(
140140
} catch (err) {
141141
log("[Task#getCheckpointService] caught error in on('initialize'), disabling checkpoints")
142142
cline.enableCheckpoints = false
143+
cline.checkpointService = undefined
143144
}
144145
})
145146

@@ -283,19 +284,19 @@ export async function checkpointDiff(cline: Task, { ts, previousCommitHash, comm
283284

284285
TelemetryService.instance.captureCheckpointDiffed(cline.taskId)
285286

286-
let from = commitHash
287-
let to: string | undefined
287+
let prevHash = commitHash
288+
let nextHash: string | undefined
288289

289290
const checkpoints = typeof service.getCheckpoints === "function" ? service.getCheckpoints() : []
290291
const idx = checkpoints.indexOf(commitHash)
291292
if (idx !== -1 && idx < checkpoints.length - 1) {
292-
to = checkpoints[idx + 1]
293+
nextHash = checkpoints[idx + 1]
293294
} else {
294-
to = undefined
295+
nextHash = undefined
295296
}
296297

297298
try {
298-
const changes = await service.getDiff({ from, to })
299+
const changes = await service.getDiff({ from: prevHash, to: nextHash })
299300

300301
if (!changes?.length) {
301302
vscode.window.showInformationMessage("No changes found.")

0 commit comments

Comments
 (0)