Skip to content

.NET: Fail declarative workflows when an agent returns an error - #7497

Open
peibekwe wants to merge 2 commits into
microsoft:mainfrom
peibekwe:declarative-bugfix
Open

.NET: Fail declarative workflows when an agent returns an error#7497
peibekwe wants to merge 2 commits into
microsoft:mainfrom
peibekwe:declarative-bugfix

Conversation

@peibekwe

@peibekwe peibekwe commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Motivation & Context

When an agent inside a declarative workflow returned a failed response, the workflow treated it as success. It moved on to the next action and finished with a "completed" status and an empty message, so callers got a blank but apparently successful reply
with no indication anything went wrong. This is the source of intermittent "empty response" reports.

There are two reasons this happened:

  1. The Foundry provider never saw the failure. When a run fails mid-stream, the underlying OpenAI Responses library turns that event into an update with no content, which is indistinguishable from an ordinary empty response.
  2. The workflow engine never checked for errors. It passed any response straight through, so even a genuine error advanced the workflow.

Description & Review Guide

  • AzureAgentProvider now recognises a failed run and converts it into error content, replacing the original update so the provider's raw error text never reaches callers.
  • AgentProviderExtensions now stops the action when a response carries an error, before the response is reported as complete or copied into the conversation. The error detail travels on the thrown exception, so hosts that have not opted into exception detail still get a redacted message.
  • Tests cover both halves, including the original failure case, refusals, autoSend on and off, and streaming and non-streaming callers.

Fixes #7496

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. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

@peibekwe peibekwe self-assigned this Aug 3, 2026
Copilot AI review requested due to automatic review settings August 3, 2026 22:40
@peibekwe
peibekwe temporarily deployed to github-app-auth August 3, 2026 22:41 — with GitHub Actions Inactive
@peibekwe
peibekwe temporarily deployed to github-app-auth August 3, 2026 22:41 — with GitHub Actions Inactive
@peibekwe
peibekwe temporarily deployed to github-app-auth August 3, 2026 22:41 — with GitHub Actions Inactive
@agent-framework-automation agent-framework-automation Bot added .NET Usage: [Issues, PRs], Target: .Net workflows Usage: [Issues, PRs], Target: Workflows labels Aug 3, 2026
@github-actions github-actions Bot changed the title Fail declarative workflows when an agent returns an error .NET: Fail declarative workflows when an agent returns an error Aug 3, 2026

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.

Pull request overview

This PR fixes a workflow correctness bug where inner agent failures could be interpreted as successful (but empty) responses, causing declarative workflows to continue executing and finish as “completed” without signaling an error.

Changes:

  • Add failure detection in the Foundry AzureAgentProvider to translate response.failed (previously mapped to contentless updates) into ErrorContent.
  • Update declarative workflow invocation to treat ErrorContent as a failing outcome (throwing before the response is marked complete or persisted), and avoid streaming raw error updates that would bypass the host’s exception-detail policy.
  • Add targeted unit tests and workflow fixtures covering failed runs, refusals, autoSend on/off, and streaming/non-streaming hosting behavior.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
dotnet/src/Microsoft.Agents.AI.Workflows.Declarative.Foundry/AzureAgentProvider.cs Detect response.failed via raw update shape and emit ErrorContent instead of a contentless “success-looking” update.
dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/Extensions/AgentProviderExtensions.cs Fail the action when an aggregated response contains ErrorContent, and suppress streaming error updates to preserve exception-detail redaction behavior.
dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/InvokeAgentFailureTest.cs End-to-end workflow tests proving failures stop downstream actions and hosted agent callers see appropriate error surfacing/redaction.
dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/AzureAgentProviderFailureTest.cs Provider-level tests ensuring failed runs become ErrorContent and raw failure representations aren’t forwarded.
dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/AgentUpdateTestHelpers.cs Test helper for building failed-run update shapes and exercising the failure-detection transform.
dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/Workflows/AgentFailureFollowup.yaml Declarative workflow fixture with a downstream action to verify failure prevents follow-up execution.
dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/Workflows/AgentFailureNoAutoSend.yaml Declarative workflow fixture verifying behavior when autoSend: false.
dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests.csproj Adds Foundry project reference needed by the new provider-focused tests.

@github-actions github-actions Bot 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.

Automated Code Review

Reviewers: 4 | Confidence: 42% | Result: All clear

Reviewed: Correctness, Security Reliability, Failure Modes, Design Approach


Automated review by peibekwe's agents

@peibekwe
peibekwe marked this pull request as ready for review August 4, 2026 01:10
@peibekwe
peibekwe temporarily deployed to github-app-auth August 4, 2026 01:10 — with GitHub Actions Inactive

@github-actions github-actions Bot 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.

Automated Code Review

Reviewers: 5 | Confidence: 44% | Result: All clear

Reviewed: Correctness, Security Reliability, Test Coverage, Failure Modes, Design Approach


Automated review by peibekwe's agents

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 workflows Usage: [Issues, PRs], Target: Workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.NET: [Bug]: Inner agent failure does not fail workflow in declarative workflow

3 participants