remove some extra code

This commit is contained in:
Will Li 2025-07-25 09:57:08 -07:00
parent 0bd49d7e54
commit 85268aaec7
2 changed files with 13 additions and 57 deletions

View file

@ -176,21 +176,6 @@ describe("Checkpoint functionality", () => {
expect(mockTask.enableCheckpoints).toBe(true) expect(mockTask.enableCheckpoints).toBe(true)
}) })
it("should prevent duplicate checkpoint operations for the same task", async () => {
// Start two checkpoint saves simultaneously
const promise1 = checkpointSave(mockTask)
const promise2 = checkpointSave(mockTask)
// Wait for both promises
const [result1, result2] = await Promise.all([promise1, promise2])
// Both should return the same result
expect(result1).toEqual(result2)
// saveCheckpoint should only be called once due to deduplication
expect(mockCheckpointService.saveCheckpoint).toHaveBeenCalledTimes(1)
})
it("should handle errors gracefully and disable checkpoints", async () => { it("should handle errors gracefully and disable checkpoints", async () => {
mockCheckpointService.saveCheckpoint.mockRejectedValue(new Error("Save failed")) mockCheckpointService.saveCheckpoint.mockRejectedValue(new Error("Save failed"))

View file

@ -16,9 +16,6 @@ import { DIFF_VIEW_URI_SCHEME } from "../../integrations/editor/DiffViewProvider
import { CheckpointServiceOptions, RepoPerTaskCheckpointService } from "../../services/checkpoints" import { CheckpointServiceOptions, RepoPerTaskCheckpointService } from "../../services/checkpoints"
// Map to store pending checkpoint operations by taskId to prevent race conditions
const pendingCheckpointOperations = new Map<string, Promise<any>>()
export function getCheckpointService(cline: Task) { export function getCheckpointService(cline: Task) {
if (!cline.enableCheckpoints) { if (!cline.enableCheckpoints) {
return undefined return undefined
@ -195,49 +192,23 @@ async function getInitializedCheckpointService(
} }
export async function checkpointSave(cline: Task, force = false) { export async function checkpointSave(cline: Task, force = false) {
const taskId = cline.taskId try {
// Use getInitializedCheckpointService to wait for initialization
const service = await getInitializedCheckpointService(cline)
// Check if there's already a pending checkpoint operation for this task if (!service) {
const existingOperation = pendingCheckpointOperations.get(taskId) return
if (existingOperation) {
// Return the existing Promise to prevent duplicate operations
return existingOperation
}
// Create a new checkpoint operation Promise
const checkpointOperation = (async () => {
try {
// Use getInitializedCheckpointService to wait for initialization
const service = await getInitializedCheckpointService(cline)
if (!service) {
return
}
TelemetryService.instance.captureCheckpointCreated(cline.taskId)
// Start the checkpoint process in the background.
return await service.saveCheckpoint(`Task: ${cline.taskId}, Time: ${Date.now()}`, { allowEmpty: force })
} catch (err) {
console.error("[Task#checkpointSave] caught unexpected error, disabling checkpoints", err)
cline.enableCheckpoints = false
return undefined
} }
})()
// Store the operation in the Map TelemetryService.instance.captureCheckpointCreated(cline.taskId)
pendingCheckpointOperations.set(taskId, checkpointOperation)
// Clean up the Map entry after the operation completes (success or failure) // Start the checkpoint process in the background.
checkpointOperation return await service.saveCheckpoint(`Task: ${cline.taskId}, Time: ${Date.now()}`, { allowEmpty: force })
.finally(() => { } catch (err) {
pendingCheckpointOperations.delete(taskId) console.error("[Task#checkpointSave] caught unexpected error, disabling checkpoints", err)
}) cline.enableCheckpoints = false
.catch(() => { return undefined
// Error already handled above, this catch prevents unhandled rejection }
})
return checkpointOperation
} }
export type CheckpointRestoreOptions = { export type CheckpointRestoreOptions = {