-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: resolve orchestrator subtask cancellation during API streaming error (#4896) #4905
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: resolve orchestrator subtask cancellation during API streaming error (#4896) #4905
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR addresses an issue where orchestrator subtasks failed to properly clean up and return control to their parent tasks when an API streaming error occurred.
- Enhances race condition handling in
webviewMessageHandler.tsby delaying cleanup to ensure abort signals propagate - Improves error handling and logging in
finishSubTaskto avoid blocking parent task resumption - Makes
resumePausedTaskinTask.tsresilient to aborted/abandoned task states without throwing
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/core/webview/webviewMessageHandler.ts | Wraps subtask abort and finish in try/catch and adds a delay to avoid race conditions |
| src/core/task/Task.ts | Skips resume for aborted/abandoned tasks and removes throwing on resume failures |
Comments suppressed due to low confidence (1)
| try { | ||
| // First abort the current subtask if it's still running | ||
| if (currentTask.isStreaming || !currentTask.didFinishAbortingStream) { | ||
| currentTask.abortTask() |
Copilot
AI
Jun 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If abortTask returns a promise, consider awaiting it (e.g., await currentTask.abortTask()) to ensure the abort completes before continuing.
| currentTask.abortTask() | |
| await currentTask.abortTask() |
| currentTask.abortTask() | ||
| // Small delay to ensure abort signal is processed before cleanup | ||
| // This prevents race conditions where the stream might still be processing | ||
| await new Promise((resolve) => setTimeout(resolve, 100)) |
Copilot
AI
Jun 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hardcoded 100ms delay is a magic number; extract it into a named constant (e.g., ABORT_DELAY_MS) to clarify its purpose and make tuning easier.
| await new Promise((resolve) => setTimeout(resolve, 100)) | |
| await new Promise((resolve) => setTimeout(resolve, ABORT_DELAY_MS)) |
| await provider.finishSubTask(t("common:tasks.canceled")) | ||
| } catch (error) { | ||
| // If there's an error, still try to resume the parent task | ||
| provider.log(`Error during subtask cancellation: ${error}`) |
Copilot
AI
Jun 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This finishSubTask call appears both inside the try and catch blocks; consider moving it after the try/catch to avoid duplication and centralize cleanup.
| await provider.finishSubTask(t("common:tasks.canceled")) | |
| } catch (error) { | |
| // If there's an error, still try to resume the parent task | |
| provider.log(`Error during subtask cancellation: ${error}`) | |
| } catch (error) { | |
| // If there's an error, still try to resume the parent task | |
| provider.log(`Error during subtask cancellation: ${error}`) | |
| } finally { |

Description
Fixes #4896
This PR resolves an issue where orchestrator subtask cancellation would fail to return to the parent task when an API streaming error occurred. The fix ensures proper cleanup and parent task resumption even in error states.
Changes Made
setTimeoutusage inwebviewMessageHandler.tsto clarify why it's needed for preventing race conditions during stream abortionfinishSubTaskto include the parent task ID for better debugging contextresumePausedTaskinTask.tsmore resilient to handle aborted/abandoned statesTesting
Verification of Acceptance Criteria
Checklist
Important
Fixes subtask cancellation during API streaming errors, ensuring parent task resumption and improving error handling in
Task.tsandwebviewMessageHandler.ts.Task.tsandwebviewMessageHandler.ts.resumePausedTaskinTask.tsto prevent blocking parent task resumption.finishSubTaskto include parent task ID for better debugging.resumePausedTaskto ensure task continuation.setTimeoutinwebviewMessageHandler.tsto prevent race conditions during stream abortion.This description was created by
for 5c11f20. You can customize this summary. It will automatically update as commits are pushed.