Skip to content

.NET: preserve cooperative workflow handler cancellation - #8494

Draft
Naveen Chatlapalli (1aifanatic) wants to merge 2 commits into
microsoft:mainfrom
1aifanatic:contrib/8092-enterprise-agents
Draft

Naveen Chatlapalli (1aifanatic) wants to merge 2 commits into
microsoft:mainfrom
1aifanatic:contrib/8092-enterprise-agents

Conversation

@1aifanatic

@1aifanatic Naveen Chatlapalli (1aifanatic) commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Motivation & Context

A workflow handler that cooperatively observes runtime cancellation currently becomes an ExecutorFailedEvent followed by TargetInvocationException. Operators then see an intentional stop classified as a workflow failure.

Description & Review Guide

  • What are the major changes? Before emitting a terminal executor event, propagate cancellation when the runtime token is cancelled and the original cancellation exception carries that same token. Preserve the reflection-path cancellation exception metadata and document the public exception contract. Add twelve regression cases for delegate/reflection handlers, ordinary errors during cancellation, cancellation without a cancelled runtime token, and public CancelRunAsync in lockstep/off-thread runs.
  • What is the impact of these changes? Cooperative cancellation follows the existing runtime cancellation path rather than the failure path. No public API changes. Ordinary errors still fail even if the runtime token is cancelled. The existing delegate/reflection distinction for cancellation while the runtime token is not cancelled is intentionally retained.
  • What do you want reviewers to focus on? Confirm this bounded cooperative-cancellation behavior for .NET: [Bug]: Workflow handler cancellation is reported as executor failure #8092; this draft does not decide the separate foreign-cancellation policy. The two direct cancellation regressions fail before the fix. All twelve focused cases pass on net10.0 and net472; all 780 workflow tests pass. The full .NET solution builds with zero warnings/errors and changed-file formatting passes. The latest broader net10.0 unit run completed with 8,512 passed, 69 skipped, and zero failures. The solution-disabled FeatureRegistry test project was built/run separately and passed all three tests.

Related Issue

Fixes #8092 for cooperative runtime cancellation. No other open PR for this issue was found. The issue reporter had offered to implement it; a scope/coordination comment was posted before preparing this draft.

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.

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.

🟡 Changes recommended

Foreign cancellation is unintentionally reclassified, and the public exception contract needs updating.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Preserves cooperative .NET workflow cancellation instead of reporting executor failure.

Changes:

  • Propagates runtime cancellation before terminal executor events.
  • Adds eight delegate, reflection, and streaming regression cases.
File summaries
File Description
Executor.cs Handles canceled handler results.
ExecutorCancellationTests.cs Covers cancellation and failure boundaries.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 2
  • Review effort level: Balanced

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment thread dotnet/src/Microsoft.Agents.AI.Workflows/Executor.cs Outdated
Comment thread dotnet/src/Microsoft.Agents.AI.Workflows/Executor.cs
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]: Workflow handler cancellation is reported as executor failure

2 participants