Skip to content

Commit 4418519

Browse files
author
ShayBC
committed
added 500ms delay after modeSwitch to avoid a bug of running subtask before mode switch is actualy performed, also treated state of command execution where a call to finishSubtask was missing
1 parent c8ec2b6 commit 4418519

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

src/core/Cline.ts

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2628,10 +2628,7 @@ export class Cline {
26282628
}
26292629

26302630
// Switch the mode using shared handler
2631-
const provider = this.providerRef.deref()
2632-
if (provider) {
2633-
await provider.handleModeSwitch(mode_slug)
2634-
}
2631+
await this.providerRef.deref()?.handleModeSwitch(mode_slug)
26352632
pushToolResult(
26362633
`Successfully switched from ${getModeBySlug(currentMode)?.name ?? currentMode} mode to ${
26372634
targetMode.name
@@ -2700,23 +2697,18 @@ export class Cline {
27002697
this.pausedModeSlug = currentMode
27012698

27022699
// Switch mode first, then create new task instance
2703-
const provider = this.providerRef.deref()
2704-
if (provider) {
2705-
await provider.handleModeSwitch(mode)
2706-
this.providerRef
2707-
.deref()
2708-
?.log(`[subtasks] Task: ${this.taskNumber} creating new task in '${mode}' mode`)
2709-
await provider.initClineWithSubTask(message)
2710-
pushToolResult(
2711-
`Successfully created new task in ${targetMode.name} mode with message: ${message}`,
2712-
)
2713-
// set the isPaused flag to true so the parent task can wait for the sub-task to finish
2714-
this.isPaused = true
2715-
} else {
2716-
pushToolResult(
2717-
formatResponse.toolError("Failed to create new task: provider not available"),
2718-
)
2719-
}
2700+
await this.providerRef.deref()?.handleModeSwitch(mode)
2701+
// wait for mode to actually switch in UI and in State
2702+
await delay(500) // delay to allow mode change to take effect before next tool is executed
2703+
this.providerRef
2704+
.deref()
2705+
?.log(`[subtasks] Task: ${this.taskNumber} creating new task in '${mode}' mode`)
2706+
await this.providerRef.deref()?.initClineWithSubTask(message)
2707+
pushToolResult(
2708+
`Successfully created new task in ${targetMode.name} mode with message: ${message}`,
2709+
)
2710+
// set the isPaused flag to true so the parent task can wait for the sub-task to finish
2711+
this.isPaused = true
27202712
break
27212713
}
27222714
} catch (error) {
@@ -2772,6 +2764,15 @@ export class Cline {
27722764
undefined,
27732765
false,
27742766
)
2767+
2768+
if (this.isSubTask) {
2769+
// tell the provider to remove the current subtask and resume the previous task in the stack (it might decide to run the command)
2770+
await this.providerRef
2771+
.deref()
2772+
?.finishSubTask(`new_task finished successfully! ${lastMessage?.text}`)
2773+
break
2774+
}
2775+
27752776
await this.ask(
27762777
"command",
27772778
removeClosingTag("command", command),
@@ -2973,6 +2974,8 @@ export class Cline {
29732974
if (currentMode !== this.pausedModeSlug) {
29742975
// the mode has changed, we need to switch back to the paused mode
29752976
await this.providerRef.deref()?.handleModeSwitch(this.pausedModeSlug)
2977+
// wait for mode to actually switch in UI and in State
2978+
await delay(500) // delay to allow mode change to take effect before next tool is executed
29762979
this.providerRef
29772980
.deref()
29782981
?.log(

0 commit comments

Comments
 (0)