Skip to content

Conversation

@moonbox3
Copy link
Contributor

@moonbox3 moonbox3 commented Feb 4, 2026

Motivation and Context

When a workflow is cancelled via asyncio.create_task() + task.cancel(), executors that are mid-execution continue running to completion instead of being cancelled. This only affects executors after the first one (Step2+), because the CancelledError is raised in the polling loop but the iteration_task created via asyncio.create_task() is orphaned and keeps running.

Description

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

@moonbox3 moonbox3 self-assigned this Feb 4, 2026
Copilot AI review requested due to automatic review settings February 4, 2026 02:58
@moonbox3 moonbox3 added python workflows Related to Workflows in agent-framework labels Feb 4, 2026
@moonbox3 moonbox3 changed the title Python: fix(core: fix workflow cancellation not propagating to active executors Python: fix(core): fix workflow cancellation not propagating to active executors Feb 4, 2026
@github-actions github-actions bot changed the title Python: fix(core): fix workflow cancellation not propagating to active executors Python: fix(core: fix workflow cancellation not propagating to active executors Feb 4, 2026
@moonbox3 moonbox3 moved this to In Review in Agent Framework Feb 4, 2026
@markwallace-microsoft
Copy link
Member

markwallace-microsoft commented Feb 4, 2026

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework/_workflows
   _runner.py2203285%132–133, 173–176, 180, 221–223, 248–249, 251, 286–288, 312–316, 320, 355, 359, 361, 367, 375–378, 391, 431
TOTAL16345198287% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
3823 221 💤 0 ❌ 0 🔥 1m 12s ⏱️

Copy link
Contributor

Copilot AI left a comment

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 bug where workflow cancellation was not properly propagating to active executors. When a workflow was cancelled during the execution of the second or subsequent executor, the active executor would continue running to completion instead of being cancelled.

Changes:

  • Added cancellation handling in the workflow runner's polling loop to cancel orphaned iteration tasks
  • Added comprehensive test coverage for workflow cancellation behavior

Reviewed changes

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

File Description
python/packages/core/agent_framework/_workflows/_runner.py Added try-except block to catch CancelledError in polling loop, cancel iteration_task, and properly clean it up before re-raising
python/packages/core/tests/workflow/test_runner.py Added SlowExecutor test helper class and test_runner_cancellation_stops_active_executor test to verify cancellation propagates correctly

@moonbox3 moonbox3 changed the title Python: fix(core: fix workflow cancellation not propagating to active executors Python: fix(core): workflow cancellation not propagating to active executors Feb 4, 2026
@markwallace-microsoft markwallace-microsoft added this pull request to the merge queue Feb 4, 2026
Merged via the queue into microsoft:main with commit d742364 Feb 4, 2026
23 checks passed
@github-project-automation github-project-automation bot moved this from In Review to Done in Agent Framework Feb 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python workflows Related to Workflows in agent-framework

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: Workflow cancellation ignored by subsequent agents

3 participants