Skip to content

Python: Fix deadlock in Magentic workflow - #1325

Merged
Tao Chen (TaoChenOSU) merged 2 commits into
mainfrom
taochen/python-fix-magentic-deadlock
Oct 9, 2025
Merged

Python: Fix deadlock in Magentic workflow#1325
Tao Chen (TaoChenOSU) merged 2 commits into
mainfrom
taochen/python-fix-magentic-deadlock

Conversation

@TaoChenOSU

@TaoChenOSU Tao Chen (TaoChenOSU) commented Oct 8, 2025

Copy link
Copy Markdown
Contributor

Motivation and Context

Fix #1222

Description

  1. Remove the lock on the orchestrator executor as executors are not designed to be thread safe. Executor instances are not meant to use in multiple workflows.
  2. Add a test to make sure resetting works.

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.

@TaoChenOSU Tao Chen (TaoChenOSU) self-assigned this Oct 8, 2025
@TaoChenOSU Tao Chen (TaoChenOSU) added the python Usage: [Issues, PRs], Target: Python label Oct 8, 2025
Copilot AI review requested due to automatic review settings October 8, 2025 21:15
@TaoChenOSU Tao Chen (TaoChenOSU) added the workflows Usage: [Issues, PRs], Target: Workflows label Oct 8, 2025
@github-actions github-actions Bot changed the title Fix deadlock in Magentic workflow Python: Fix deadlock in Magentic workflow Oct 8, 2025

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 deadlock issue in the Magentic workflow by removing thread synchronization mechanisms and adding proper test coverage for the reset functionality.

Key changes:

  • Removed the asyncio.Lock from the orchestrator executor to prevent deadlocks since executors are not designed to be thread-safe
  • Added a test to verify that stall and reset mechanisms work correctly
  • Cleaned up unnecessary context initialization code

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
python/packages/core/agent_framework/_workflows/_magentic.py Removed the inner loop lock and associated synchronization code, renamed helper method
python/packages/core/tests/workflow/test_magentic.py Added test class and test function to verify stall/reset functionality works properly

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread python/packages/core/agent_framework/_workflows/_magentic.py
@markwallace-microsoft

Copy link
Copy Markdown
Contributor

@TaoChenOSU
Tao Chen (TaoChenOSU) added this pull request to the merge queue Oct 9, 2025
Merged via the queue into main with commit 2397795 Oct 9, 2025
20 checks passed
@crickman
Chris (crickman) deleted the taochen/python-fix-magentic-deadlock branch October 9, 2025 19:12
Reuben Bond (ReubenBond) pushed a commit to ReubenBond/agent-framework that referenced this pull request Oct 28, 2025
* Fix deadlock in Magentic workflow

* Fix unit test
Aris Nguyen (arisng) pushed a commit to arisng/agent-framework that referenced this pull request Feb 2, 2026
* Fix deadlock in Magentic workflow

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

Labels

python Usage: [Issues, PRs], Target: Python workflows Usage: [Issues, PRs], Target: Workflows

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Python: Deadlock in MagenticOrchestratorExecutor when resetting and replanning due to recursive lock acquisition

5 participants