Skip to content

Commit fef9bb1

Browse files
committed
fix: restore orchestrator subtask connection after VSCode restart
- Check both parentTask and parentTaskId in attemptCompletionTool to handle cases where the direct reference is lost - Enhance finishSubTask to restore parent task from history when not in stack - Add proper error handling and logging for parent task restoration Fixes #8621
1 parent 3a47c55 commit fef9bb1

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

src/core/tools/attemptCompletionTool.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ export async function attemptCompletionTool(
9595
TelemetryService.instance.captureTaskCompleted(cline.taskId)
9696
cline.emit(RooCodeEventName.TaskCompleted, cline.taskId, cline.getTokenUsage(), cline.toolUsage)
9797

98-
if (cline.parentTask) {
98+
// Check both parentTask (direct reference) and parentTaskId (persisted ID)
99+
// This handles cases where VSCode was closed and the direct reference was lost
100+
if (cline.parentTask || cline.parentTaskId) {
99101
const didApprove = await askFinishSubTaskApproval()
100102

101103
if (!didApprove) {

src/core/webview/ClineProvider.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,12 +482,37 @@ export class ClineProvider
482482
// This is used when a subtask is finished and the parent task needs to be
483483
// resumed.
484484
async finishSubTask(lastMessage: string) {
485+
// Get the current task before removing it from the stack
486+
const currentTask = this.getCurrentTask()
487+
const parentTaskId = currentTask?.parentTaskId
488+
485489
// Remove the last cline instance from the stack (this is the finished
486490
// subtask).
487491
await this.removeClineFromStack()
488-
// Resume the last cline instance in the stack (if it exists - this is
489-
// the 'parent' calling task).
490-
await this.getCurrentTask()?.completeSubtask(lastMessage)
492+
493+
// Check if there's a parent task in the stack
494+
let parentTask = this.getCurrentTask()
495+
496+
// If no parent task in stack but we have a parentTaskId,
497+
// we need to restore the parent task (happens when VSCode was closed)
498+
if (!parentTask && parentTaskId) {
499+
try {
500+
// Restore the parent task from history
501+
const { historyItem } = await this.getTaskWithId(parentTaskId)
502+
parentTask = await this.createTaskWithHistoryItem(historyItem)
503+
this.log(`[finishSubTask] Restored parent task ${parentTaskId} from history to receive subtask result`)
504+
} catch (error) {
505+
this.log(
506+
`[finishSubTask] Failed to restore parent task ${parentTaskId}: ${error instanceof Error ? error.message : String(error)}`,
507+
)
508+
// Even if parent restoration fails, we should still show completion
509+
// The user can manually resume the parent from task history
510+
return
511+
}
512+
}
513+
514+
// Resume the parent task with the subtask result
515+
await parentTask?.completeSubtask(lastMessage)
491516
}
492517
// Pending Edit Operations Management
493518

0 commit comments

Comments
 (0)