.NET: Add parallel declarative Foreach execution - #7679
Open
KirschQAQ (KirschBluteX) wants to merge 3 commits into
Open
.NET: Add parallel declarative Foreach execution#7679KirschQAQ (KirschBluteX) wants to merge 3 commits into
KirschQAQ (KirschBluteX) wants to merge 3 commits into
Conversation
KirschQAQ (KirschBluteX)
requested review from
SergeyMenshykh,
chetantoshniwal,
Peter Ibekwe (peibekwe),
Roger Barreto (rogerbarreto) and
westey (westey-m)
as code owners
August 15, 2026 14:47
KirschQAQ (KirschBluteX)
deployed
to
github-app-auth
August 15, 2026 14:47 — with
GitHub Actions
Active
KirschQAQ (KirschBluteX)
had a problem deploying
to
github-app-auth
August 15, 2026 14:47 — with
GitHub Actions
Error
KirschQAQ (KirschBluteX)
deployed
to
github-app-auth
August 15, 2026 14:47 — with
GitHub Actions
Active
KirschQAQ (KirschBluteX)
deployed
to
github-app-auth
August 15, 2026 14:48 — with
GitHub Actions
Active
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds opt-in parallel execution for declarative Foreach, including isolated per-iteration formula state, deterministic commit ordering, timeout/cancellation behavior, and documentation + end-to-end tests validating concurrency and failure semantics.
Changes:
- Introduces
ForeachExecutionOptionsandParallelForeachIterationRunnerto executeForeachbodies concurrently with bounded parallelism and per-iteration timeouts. - Extends
WorkflowFormulaStateto snapshot/branch state and track variable writes for deterministic, ordered commits. - Adds unit tests and README documentation describing parallel
Foreachbehavior and limitations.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/ParallelForeachWorkflowTests.cs | New E2E behavioral tests covering concurrency, ordering, failures, cancellation, and timeouts. |
| dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/README.md | Documents how to opt into parallel Foreach, limits/timeouts, and checkpointing constraints. |
| dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/PowerFx/WorkflowFormulaState.cs | Adds state snapshotting, branch creation, and change tracking for parallel iteration isolation/commit. |
| dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/ObjectModel/ParallelForeachIterationRunner.cs | Executes a single iteration in an isolated runtime and returns buffered state changes/events. |
| dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/ObjectModel/ForeachExecutor.cs | Adds parallel execution path, bounded worker pool, and ordered commit replay into parent context. |
| dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/ObjectModel/ForeachExecutionOptions.cs | Parses/validates Foreach execution options from extension data (mode, maxParallelism, timeoutInMilliseconds). |
| dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/Interpreter/WorkflowElementWalker.cs | Prevents walking into parallel Foreach descendants to avoid double-compiling its body. |
| dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/Interpreter/WorkflowActionVisitor.cs | Passes workflow options into ForeachExecutor and short-circuits visitor logic for parallel loops. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
KirschQAQ (KirschBluteX)
deployed
to
github-app-auth
August 15, 2026 15:03 — with
GitHub Actions
Active
Author
|
@microsoft-github-policy-service agree |
KirschQAQ (KirschBluteX)
deployed
to
github-app-auth
August 15, 2026 17:32 — with
GitHub Actions
Active
KirschQAQ (KirschBluteX)
deployed
to
github-app-auth
August 16, 2026 00:07 — with
GitHub Actions
Active
KirschQAQ (KirschBluteX)
deployed
to
github-app-auth
August 16, 2026 00:09 — with
GitHub Actions
Active
KirschQAQ (KirschBluteX)
deployed
to
github-app-auth
August 16, 2026 00:14 — with
GitHub Actions
Active
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation & Context
Declarative
Foreachworkflows currently execute each iteration serially, even when iterations are independent. This adds bounded, opt-in parallel fan-out while preserving the existing sequential behavior by default.Description & Review Guide
mode: Parallel,maxParallelism, and per-iterationtimeoutInMillisecondsthrough the ObjectModel extension-data contract. Parallel iterations run as isolated in-process sub-workflows, buffer state and events, and commit them in source-index order. External-input checkpoints and loop control targeting the parallel loop are rejected explicitly. Configuration validation also rejects numeric strings such asmode: "1", combined enum values, non-positive parallelism, and invalid timeouts.net10.0andnet472, including 40 focused parallel-Foreachtests on each framework.Related Issue
Fixes #2793
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.