From 85268aaec7fd674b85354b84c0a6189f09d3b42d Mon Sep 17 00:00:00 2001 From: Will Li Date: Fri, 25 Jul 2025 09:57:08 -0700 Subject: [PATCH] remove some extra code --- .../checkpoints/__tests__/checkpoint.test.ts | 15 ----- src/core/checkpoints/index.ts | 55 +++++-------------- 2 files changed, 13 insertions(+), 57 deletions(-) diff --git a/src/core/checkpoints/__tests__/checkpoint.test.ts b/src/core/checkpoints/__tests__/checkpoint.test.ts index c45f951ac9..49b26a4c2d 100644 --- a/src/core/checkpoints/__tests__/checkpoint.test.ts +++ b/src/core/checkpoints/__tests__/checkpoint.test.ts @@ -176,21 +176,6 @@ describe("Checkpoint functionality", () => { 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 () => { mockCheckpointService.saveCheckpoint.mockRejectedValue(new Error("Save failed")) diff --git a/src/core/checkpoints/index.ts b/src/core/checkpoints/index.ts index 35d35bbf07..96ebe1ee73 100644 --- a/src/core/checkpoints/index.ts +++ b/src/core/checkpoints/index.ts @@ -16,9 +16,6 @@ import { DIFF_VIEW_URI_SCHEME } from "../../integrations/editor/DiffViewProvider import { CheckpointServiceOptions, RepoPerTaskCheckpointService } from "../../services/checkpoints" -// Map to store pending checkpoint operations by taskId to prevent race conditions -const pendingCheckpointOperations = new Map>() - export function getCheckpointService(cline: Task) { if (!cline.enableCheckpoints) { return undefined @@ -195,49 +192,23 @@ async function getInitializedCheckpointService( } 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 - const existingOperation = pendingCheckpointOperations.get(taskId) - 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 + if (!service) { + return } - })() - // Store the operation in the Map - pendingCheckpointOperations.set(taskId, checkpointOperation) + TelemetryService.instance.captureCheckpointCreated(cline.taskId) - // Clean up the Map entry after the operation completes (success or failure) - checkpointOperation - .finally(() => { - pendingCheckpointOperations.delete(taskId) - }) - .catch(() => { - // Error already handled above, this catch prevents unhandled rejection - }) - - return checkpointOperation + // 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 + } } export type CheckpointRestoreOptions = {