Skip to content

.NET: Surface workflow exceptions instead of a JSON serialization error - #8018

Open
Atharva Vichare (atty57) wants to merge 1 commit into
microsoft:mainfrom
atty57:atty57-issue-8012
Open

.NET: Surface workflow exceptions instead of a JSON serialization error#8018
Atharva Vichare (atty57) wants to merge 1 commit into
microsoft:mainfrom
atty57:atty57-issue-8012

Conversation

@atty57

Copy link
Copy Markdown
Contributor

Motivation & Context

When a workflow registered as an agent throws, the user never sees the real failure. They see:

Serialization and deserialization of 'System.Reflection.MethodBase' instances is not supported. Path: $.TargetSite. (Code: execution_error)

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 actual exception message.

Description & Review Guide

  • What are the major changes?
    The workflow-event branch in AgentResponseUpdateExtensions now special-cases Exception data and serializes exception.Message instead of the exception object. This mirrors how ExecutorFailedEvent is already handled in the same file. Added WorkflowErrorEventStreamingTests covering 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 emitted data value 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 ExecutorFailedEvent handling. Please confirm that is the intended boundary.

Related Issue

Fixes #8012

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change.

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

.NET Usage: [Issues, PRs], Target: .Net

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.NET: [Bug]: Exception in workflow, that is added as agent, results in json serialisation error message instead of exception

2 participants