Skip to content

Commit 9141d92

Browse files
committed
fix: add task creation guard and delegation check to prevent races
1 parent 2a136af commit 9141d92

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/core/webview/ClineProvider.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ export class ClineProvider
173173
private clineMessagesSeq = 0
174174

175175
public isViewLaunched = false
176+
public isTaskCreationInProgress = false
176177
public settingsImportedAt?: number
177178
public readonly latestAnnouncementId = "feb-2026-v3.47.0-opus-4.6-gpt-5.3-codex" // v3.47.0 Claude Opus 4.6 & GPT-5.3-Codex
178179
public readonly providerSettingsManager: ProviderSettingsManager
@@ -3027,6 +3028,12 @@ export class ClineProvider
30273028
options: CreateTaskOptions = {},
30283029
configuration: RooCodeSettings = {},
30293030
): Promise<Task> {
3031+
if (this.delegationInProgress) {
3032+
this.log("[createTask] Blocked: delegation in progress")
3033+
vscode.window.showInformationMessage("Task delegation in progress, please wait...")
3034+
throw new Error("Cannot create task while delegation is in progress")
3035+
}
3036+
30303037
if (configuration) {
30313038
await this.setValues(configuration)
30323039

src/core/webview/webviewMessageHandler.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -547,10 +547,14 @@ export const webviewMessageHandler = async (
547547
provider.isViewLaunched = true
548548
break
549549
case "newTask":
550-
// Initializing new instance of Cline will make sure that any
551-
// agentically running promises in old instance don't affect our new
552-
// task. This essentially creates a fresh slate for the new task.
550+
if (provider.isTaskCreationInProgress) {
551+
break
552+
}
553+
provider.isTaskCreationInProgress = true
553554
try {
555+
// Initializing new instance of Cline will make sure that any
556+
// agentically running promises in old instance don't affect our new
557+
// task. This essentially creates a fresh slate for the new task.
554558
const resolved = await resolveIncomingImages({ text: message.text, images: message.images })
555559
await provider.createTask(resolved.text, resolved.images)
556560
// Task created successfully - notify the UI to reset
@@ -562,6 +566,8 @@ export const webviewMessageHandler = async (
562566
vscode.window.showErrorMessage(
563567
`Failed to create task: ${error instanceof Error ? error.message : String(error)}`,
564568
)
569+
} finally {
570+
provider.isTaskCreationInProgress = false
565571
}
566572
break
567573
case "customInstructions":

0 commit comments

Comments
 (0)