From dc3359a22425751279048b4805602504162295f1 Mon Sep 17 00:00:00 2001 From: Roo Code Date: Thu, 19 Jun 2025 18:34:57 +0000 Subject: [PATCH] Fix #4896: Handle API streaming errors in subtasks properly When an API streaming error occurs in a subtask, instead of reinitializing the subtask with history (which keeps it stuck in subtask view), properly return control to the parent task by calling finishSubTask(). This ensures that orchestrator mode can properly resume the parent task after a subtask encounters an API streaming failure during cancellation. --- src/core/task/Task.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/core/task/Task.ts b/src/core/task/Task.ts index a6a9d89986..5ec39a575a 100644 --- a/src/core/task/Task.ts +++ b/src/core/task/Task.ts @@ -1422,10 +1422,17 @@ export class Task extends EventEmitter { error.message ?? JSON.stringify(serializeError(error), null, 2), ) - const history = await provider?.getTaskWithId(this.taskId) + // Check if this is a subtask - if so, return to parent instead of reinitializing + if (this.parentTask) { + // For subtasks, finish the subtask and return to parent + await provider?.finishSubTask(`API streaming error: ${error.message ?? "Unknown error"}`) + } else { + // For main tasks, reinitialize with history as before + const history = await provider?.getTaskWithId(this.taskId) - if (history) { - await provider?.initClineWithHistoryItem(history.historyItem) + if (history) { + await provider?.initClineWithHistoryItem(history.historyItem) + } } } } finally {