Skip to content

Commit d7e1fff

Browse files
authored
Task init promise error in task truncation (RooCodeInc#4097)
1 parent 8ca96df commit d7e1fff

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

.changeset/heavy-bananas-shave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"claude-dev": patch
3+
---
4+
5+
Added promise to task init to prevent race condition with checkpoints

src/core/task/index.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ export class Task {
165165
checkpointTrackerErrorMessage?: string
166166
conversationHistoryDeletedRange?: [number, number]
167167
isInitialized = false
168+
private initTaskPromise?: Promise<void>
168169
isAwaitingPlanResponse = false
169170
didRespondToPlanAskBySwitchingMode = false
170171

@@ -296,9 +297,9 @@ export class Task {
296297

297298
// Continue with task initialization
298299
if (historyItem) {
299-
this.resumeTaskFromHistory()
300+
this.initTaskPromise = this.resumeTaskFromHistory()
300301
} else if (task || images || files) {
301-
this.startTask(task, images, files)
302+
this.initTaskPromise = this.startTask(task, images, files)
302303
}
303304

304305
// initialize telemetry
@@ -387,6 +388,10 @@ export class Task {
387388
}
388389

389390
async restoreCheckpoint(messageTs: number, restoreType: ClineCheckpointRestore, offset?: number) {
391+
if (this.initTaskPromise && !this.isInitialized) {
392+
await this.initTaskPromise
393+
}
394+
390395
const messageIndex = this.clineMessages.findIndex((m) => m.ts === messageTs) - (offset || 0)
391396
// Find the last message before messageIndex that has a lastCheckpointHash
392397
const lastHashIndex = findLastIndex(this.clineMessages.slice(0, messageIndex), (m) => m.lastCheckpointHash !== undefined)
@@ -521,6 +526,10 @@ export class Task {
521526
}
522527

523528
async presentMultifileDiff(messageTs: number, seeNewChangesSinceLastTaskCompletion: boolean) {
529+
if (this.initTaskPromise && !this.isInitialized) {
530+
await this.initTaskPromise
531+
}
532+
524533
const relinquishButton = () => {
525534
this.postMessageToWebview({ type: "relinquishControl" })
526535
}
@@ -650,6 +659,10 @@ export class Task {
650659
}
651660

652661
async doesLatestTaskCompletionHaveNewChanges() {
662+
if (this.initTaskPromise && !this.isInitialized) {
663+
await this.initTaskPromise
664+
}
665+
653666
if (!this.enableCheckpoints) {
654667
return false
655668
}
@@ -1200,6 +1213,10 @@ export class Task {
12001213
// Checkpoints
12011214

12021215
async saveCheckpoint(isAttemptCompletionMessage: boolean = false) {
1216+
if (this.initTaskPromise && !this.isInitialized) {
1217+
await this.initTaskPromise
1218+
}
1219+
12031220
if (!this.enableCheckpoints) {
12041221
// If checkpoints are disabled, do nothing.
12051222
return

src/shared/WebviewMessage.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import { McpViewTab } from "./mcp"
99
export interface WebviewMessage {
1010
type:
1111
| "apiConfiguration"
12-
| "condense"
13-
| "reportBug"
1412
| "requestVsCodeLmModels"
1513
| "authStateChanged"
1614
| "fetchMcpMarketplace"

0 commit comments

Comments
 (0)