Repository navigation
[High] Reliability: Fix parent chat failure state after unmapped Copilot subagent errors - #348415
Open
Hazem Ali (DrHazemAli) wants to merge 1 commit into
Open
Hazem Ali (DrHazemAli) wants to merge 1 commit into
Hazem Ali (DrHazemAli) wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This contribution focuses on improving the accuracy and reliability of agent execution-state reporting, particularly when errors occur during subagent execution.
The patch addresses an error-routing path that could incorrectly mark the parent conversation as failed while the underlying SDK execution continued.
Background
I encountered this issue while using BYOK for my main agent.
The main agent delegated work to a subagent using a Copilot subscription model.
The subagent encountered an error after my premium request allowance was exhausted.
The conversation displayed a red failure indicator, but the main BYOK agent continued running and making API requests. I subsequently received a substantial unexpected BYOK bill.
This experience prompted me to examine how errors are attributed and how the Agent Host manages the parent conversation's execution state.
When an agent is still executing and consuming paid resources, the conversation should accurately reflect its execution state.
Root cause
Source review identified an error-routing path in the Agent Host that could cause this mismatch.
When a
session.errorevent includes anagentId, the handler attempts to resolve the SDK agent ID to a child tool-call ID.If no mapping exists,
parentToolCallIdisundefined.Previously, an unmapped child error could fall through to the root error path, causing the handler to:
ChatErrorto the parent conversation.Clearing the Agent Host's turn state does not necessarily cancel the underlying SDK execution. Consequently, the parent conversation could appear failed while its agent continued running.
Mapped child errors could also incorrectly finalize root tool-call failure accounting.
What this changes
The patch applies the existing
_shouldDropUnmappedSubagentEventguard tosession.errorhandling, preserving the distinction between root and child errors.Root failure accounting now runs only for root errors.
flowchart TD A["SDK reports an error"] --> B{"Error belongs to a child?"} B -- No --> C["Handle root failure"] B -- Yes --> D{"Child mapping exists?"} D -- Yes --> E["Route error to child"] D -- No --> F["Retain diagnostics"] E --> G["Preserve parent turn"] F --> G G --> H["Parent continues to its own completion or failure"]Applied Fix
The implementation makes two targeted changes in
copilotAgentSession.ts:_shouldDropUnmappedSubagentEventbefore emitting chat errors or changing the active turn state._reportToolCallDetails, MCP usage failure completion, and local model attribution to root errors.The existing error logging and structured telemetry are preserved.
The patch also documents the intended error-routing behavior in
AGENTS.md.Test command:
Scope and limitations
This change addresses the identified error-routing and root failure-accounting behavior.
It does not modify subagent model selection, billing-provider inheritance, SDK execution cancellation, or billing enforcement.
The billing experience described above provides the background for the investigation; the patch specifically addresses the execution-state reporting issue identified during source review.
Review
I would appreciate a review of the error-routing change, particularly whether other SDK error paths or authentication-related side effects require similar protection.