Skip to content

Python: fix(core): allow switch-case branches to share a target executor - #9300

Merged
Eduard van Valkenburg (eavanvalkenburg) merged 1 commit into
microsoft:mainfrom
shanto462:fix-switch-case-shared-target
Oct 13, 2026
Merged

Eduard van Valkenburg (eavanvalkenburg) merged 1 commit into
microsoft:mainfrom
shanto462:fix-switch-case-shared-target

Conversation

@shanto462

@shanto462 Md. Shalah Uddin (shanto462) commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Motivation & Context

A switch-case edge group where two cases (or a case and the default) target the same executor failed at build() with EdgeDuplicationError. SwitchCaseEdgeGroup created one edge per case, so a shared target produced the same edge twice. Routing several conditions to one handler is a common pattern, and the .NET SwitchBuilder allows it.

Description & Review Guide

  • What are the major changes? SwitchCaseEdgeGroup creates one edge per distinct target, in the order the targets first appear. The cases list is unchanged, so every case still routes to its own target. A unit test in test_edge.py checks the edges, their order and the selection for each case. A workflow test builds and runs a switch where two cases share a target.
  • What is the impact of these changes? These workflows now build and run. Groups with distinct targets produce exactly the same edges as before. A separate add_edge between the same two executors is still rejected as a duplicate.
  • What do you want reviewers to focus on? The serialized group: cases still lists every case, and edges lists each target once. from_dict rebuilds the targets from edges, so a round trip keeps the same targets and cases.

Related Issue

Fixes #9297

No other open PR covers this issue.

AI Assistance

  • No material AI assistance was used.
  • This is an AI-assisted contribution. I reviewed, understood, and verified all submitted content and accept responsibility for it.

AI assistance details: issue analysis, implementation, tests, and this PR description.

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 links to an agreed issue with no competing open PR, or the Related Issue section documents a trivial-change or repository-automation exception.
  • 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.

Copilot AI balanced review requested due to automatic review settings October 12, 2026 10:37
@agent-framework-automation agent-framework-automation Bot added the python Usage: [Issues, PRs], Target: Python label Oct 12, 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.

🟢 Approval recommended

The focused implementation preserves case routing semantics and includes appropriate unit and workflow regression coverage.

0 open findings

What changed in this PR

Fixes switch-case workflows so multiple cases can safely share one target executor.

Changes:

  • Deduplicates target edges while preserving first-seen order.
  • Adds unit coverage for routing, ordering, and shared defaults.
  • Adds an end-to-end workflow regression test.
File Description
python/​packages/​core/​agent_framework/​_workflows/​_edge.py Creates one edge per distinct switch target.
python/​packages/​core/​tests/​workflow/​test_edge.py Verifies deduplication and case selection.
python/​packages/​core/​tests/​workflow/​test_workflow.py Verifies shared-target workflows build and run.

🧠 Review effort: Balanced


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

Merged via the queue into microsoft:main with commit 7d09721 Oct 13, 2026
53 checks passed
@shanto462
Md. Shalah Uddin (shanto462) deleted the fix-switch-case-shared-target branch October 19, 2026 09:42

This branch was previously deployed

1 inactive deployment
github-app-auth — 108b3dd9 Deployed Oct 13, 2026 by shanto462 via add_label #25117
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.NET: Python: [Bug]: Two switch-case branches cannot route to the same executor (EdgeDuplicationError)

3 participants