.NET: Surface workflow exceptions instead of a JSON serialization error - #8018
Open
Atharva Vichare (atty57) wants to merge 1 commit into
Open
.NET: Surface workflow exceptions instead of a JSON serialization error#8018Atharva Vichare (atty57) wants to merge 1 commit into
Atharva Vichare (atty57) wants to merge 1 commit into
Conversation
When a workflow used as an agent fails, the streamed update carries a WorkflowErrorEvent whose Data is the original Exception. The generic workflow-event branch in AgentResponseUpdateExtensions serialized that Data directly, and System.Text.Json rejects Exception.TargetSite (a MethodBase). The resulting NotSupportedException replaced the real failure with "Serialization and deserialization of 'System.Reflection.MethodBase' instances is not supported. Path: $.TargetSite." under the execution_error code. Serialize the exception message instead, mirroring how ExecutorFailedEvent is already handled. The stack trace is deliberately not included.
Atharva Vichare (atty57)
requested review from
SergeyMenshykh,
chetantoshniwal,
Peter Ibekwe (peibekwe),
Roger Barreto (rogerbarreto) and
westey (westey-m)
as code owners
September 2, 2026 19:19
Atharva Vichare (atty57)
temporarily deployed
to
github-app-auth
September 2, 2026 19:20 — with
GitHub Actions
Inactive
Atharva Vichare (atty57)
temporarily deployed
to
github-app-auth
September 2, 2026 19:20 — with
GitHub Actions
Inactive
Atharva Vichare (atty57)
temporarily deployed
to
github-app-auth
September 2, 2026 19:20 — with
GitHub Actions
Inactive
Copilot started reviewing on behalf of
Atharva Vichare (atty57)
September 2, 2026 19:20
View session
Atharva Vichare (atty57)
temporarily deployed
to
github-app-auth
September 2, 2026 19:21 — with
GitHub Actions
Inactive
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The focused fix preserves existing behavior for other payloads and directly tests the reported failure.
Pull request overview
Fixes workflow-as-agent error streaming so clients receive the original exception message instead of a JSON serialization failure.
Changes:
- Serializes exception data as its message.
- Adds regression coverage using an exception with a populated
TargetSite.
File summaries
| File | Description |
|---|---|
AgentResponseUpdateExtensions.cs |
Safely serializes workflow exceptions. |
WorkflowErrorEventStreamingTests.cs |
Verifies the original failure message is streamed. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
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.
Motivation & Context
When a workflow registered as an agent throws, the user never sees the real failure. They see:
The streamed update carries a
WorkflowErrorEventwhoseDatais the originalException. The generic workflow-event branch inAgentResponseUpdateExtensionsserialized thatDatadirectly, andSystem.Text.JsonrejectsException.TargetSite(aMethodBase). The resultingNotSupportedExceptionreplaced the actual exception message.Description & Review Guide
What are the major changes?
The workflow-event branch in
AgentResponseUpdateExtensionsnow special-casesExceptiondata and serializesexception.Messageinstead of the exception object. This mirrors howExecutorFailedEventis already handled in the same file. AddedWorkflowErrorEventStreamingTestscovering the error event and a non-exception payload.What is the impact of these changes?
Clients now receive the actual failure message (e.g.
Executor 'AggregatorExecutor' cannot send messages of type '...') rather than a serializer error. No API change; only the emitteddatavalue for error events changes.What do you want reviewers to focus on?
The stack trace is deliberately excluded — the message alone goes to clients, consistent with the existing
ExecutorFailedEventhandling. Please confirm that is the intended boundary.Related Issue
Fixes #8012
Contribution Checklist