Python: Fix Foreach body exit wiring in declarative workflows#6050
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a declarative workflow graph-wiring bug where Foreach loops could advance to the next iteration after the first body action completes, instead of waiting for the final body action (including nested If/Switch exits). This aligns Foreach iteration semantics with sequential execution expectations and prevents unintended cross-iteration parallelism.
Changes:
- Update
Foreachbuilder wiring to connect the loop’s “advance” edge from the last body action’s exit(s), not the body entry. - Clarify
_get_branch_exitdocumentation to match its behavior for downstream wiring (linear chains vs. nested structures vs. terminators). - Add regression tests covering sequential multi-action bodies, terminator-at-end behavior, and trailing
Ifbranch exits.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| python/packages/declarative/agent_framework_declarative/_workflows/_declarative_builder.py | Fix Foreach “advance to next iteration” wiring to use the exit(s) of the last body action/structure. |
| python/packages/declarative/tests/test_graph_workflow_integration.py | Add end-to-end regression asserting multi-action Foreach bodies execute sequentially per item. |
| python/packages/declarative/tests/test_graph_coverage.py | Add graph-level edge-wiring tests for last-action advance wiring, terminator handling, and trailing If branch exits. |
ghost
left a comment
There was a problem hiding this comment.
Automated Code Review
Reviewers: 4 | Confidence: 91% | Result: All clear
Reviewed: Correctness, Security Reliability, Test Coverage, Design Approach
Automated review by peibekwe's agents
ghost
left a comment
There was a problem hiding this comment.
Automated Code Review
Reviewers: 4 | Confidence: 90% | Result: All clear
Reviewed: Correctness, Security Reliability, Test Coverage, Design Approach
Automated review by peibekwe's agents
Description
Fixes Foreach loop wiring so multi-action loop bodies advance only after the final body action completes. Adds regression coverage for sequential body actions, terminator handling, and nested If branch exits.
Fixes #5520
Contribution Checklist