Skip to content

Commit cf200c5

Browse files
committed
Blocked waiting for checkpoint initialization timing to change
1 parent f934276 commit cf200c5

File tree

3 files changed

+24
-39
lines changed

3 files changed

+24
-39
lines changed

src/core/assistant-message/presentAssistantMessage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import { switchModeTool } from "../tools/switchModeTool"
2525
import { attemptCompletionTool } from "../tools/attemptCompletionTool"
2626
import { newTaskTool } from "../tools/newTaskTool"
2727

28-
import { checkpointSave } from "../checkpoints"
2928
import { updateTodoListTool } from "../tools/updateTodoListTool"
3029

3130
import { formatResponse } from "../prompts/responses"
@@ -431,10 +430,11 @@ export async function presentAssistantMessage(cline: Task) {
431430
)
432431
}
433432

434-
await checkpointSaveAndMark(cline)
435433
if (isMultiFileApplyDiffEnabled) {
434+
await checkpointSaveAndMark(cline)
436435
await applyDiffTool(cline, block, askApproval, handleError, pushToolResult, removeClosingTag)
437436
} else {
437+
await checkpointSaveAndMark(cline)
438438
await applyDiffToolLegacy(
439439
cline,
440440
block,

src/core/checkpoints/index.ts

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,29 @@ import { DIFF_VIEW_URI_SCHEME } from "../../integrations/editor/DiffViewProvider
1616

1717
import { CheckpointServiceOptions, RepoPerTaskCheckpointService } from "../../services/checkpoints"
1818

19-
export async function getCheckpointService(cline: Task) {
19+
export async function getCheckpointService(
20+
cline: Task,
21+
{ interval = 250, timeout = 15_000 }: { interval?: number; timeout?: number } = {},
22+
) {
2023
if (!cline.enableCheckpoints) {
2124
return undefined
2225
}
2326

2427
if (cline.checkpointService) {
25-
return cline.checkpointService
26-
}
27-
28-
if (cline.checkpointServiceInitializing) {
29-
console.log("[Task#getCheckpointService] checkpoint service is still initializing")
30-
return undefined
28+
if (cline.checkpointServiceInitializing) {
29+
console.log("[Task#getCheckpointService] checkpoint service is still initializing")
30+
const service = cline.checkpointService
31+
await pWaitFor(
32+
() => {
33+
console.log("[Task#getCheckpointService] waiting for service to initialize")
34+
return service.isInitialized
35+
},
36+
{ interval, timeout },
37+
)
38+
return service.isInitialized ? cline.checkpointService : undefined
39+
} else {
40+
return cline.checkpointService
41+
}
3142
}
3243

3344
const provider = cline.providerRef.deref()
@@ -69,8 +80,8 @@ export async function getCheckpointService(cline: Task) {
6980
}
7081

7182
const service = RepoPerTaskCheckpointService.create(options)
72-
7383
cline.checkpointServiceInitializing = true
84+
cline.checkpointService = service
7485

7586
// Check if Git is installed before initializing the service
7687
// Note: This is intentionally fire-and-forget to match the original IIFE pattern
@@ -120,7 +131,6 @@ async function checkGitInstallation(
120131
const isCheckpointNeeded =
121132
typeof cline.clineMessages.find(({ say }) => say === "checkpoint_saved") === "undefined"
122133

123-
cline.checkpointService = service
124134
cline.checkpointServiceInitializing = false
125135

126136
if (isCheckpointNeeded) {
@@ -167,31 +177,6 @@ async function checkGitInstallation(
167177
}
168178
}
169179

170-
async function getInitializedCheckpointService(
171-
cline: Task,
172-
{ interval = 250, timeout = 15_000 }: { interval?: number; timeout?: number } = {},
173-
) {
174-
const service = await getCheckpointService(cline)
175-
176-
if (!service || service.isInitialized) {
177-
return service
178-
}
179-
180-
try {
181-
await pWaitFor(
182-
() => {
183-
console.log("[Task#getCheckpointService] waiting for service to initialize")
184-
return service.isInitialized
185-
},
186-
{ interval, timeout },
187-
)
188-
189-
return service
190-
} catch (err) {
191-
return undefined
192-
}
193-
}
194-
195180
export async function checkpointSave(cline: Task, force = false) {
196181
const service = await getCheckpointService(cline)
197182

@@ -222,7 +207,7 @@ export type CheckpointRestoreOptions = {
222207
}
223208

224209
export async function checkpointRestore(cline: Task, { ts, commitHash, mode }: CheckpointRestoreOptions) {
225-
const service = await getInitializedCheckpointService(cline)
210+
const service = await getCheckpointService(cline)
226211

227212
if (!service) {
228213
return
@@ -290,7 +275,7 @@ export type CheckpointDiffOptions = {
290275
}
291276

292277
export async function checkpointDiff(cline: Task, { ts, previousCommitHash, commitHash, mode }: CheckpointDiffOptions) {
293-
const service = await getInitializedCheckpointService(cline)
278+
const service = await getCheckpointService(cline)
294279

295280
if (!service) {
296281
return

src/core/task/Task.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,7 @@ export class Task extends EventEmitter<ClineEvents> {
12961296

12971297
private async initiateTaskLoop(userContent: Anthropic.Messages.ContentBlockParam[]): Promise<void> {
12981298
// Kicks off the checkpoints initialization process in the background.
1299-
await getCheckpointService(this)
1299+
getCheckpointService(this)
13001300

13011301
let nextUserContent = userContent
13021302
let includeFileDetails = true

0 commit comments

Comments
 (0)