Runtime: Work Graph builder + wave execution - #313
Merged
Conversation
Ship IWorkStep/IWorkGraph/WorkGraphBuilder plus attributes so consumers can assemble async fork-join DAGs with Build-time validation and fail-fast waves. Co-authored-by: 落笔wys <Skymly@users.noreply.github.com>
Reject null/whitespace DependsOn with InvalidWorkGraphException and document that overlapping unsynchronized context writes are forbidden. Co-authored-by: 落笔wys <Skymly@users.noreply.github.com>
Skymly
marked this pull request as ready for review
August 5, 2026 10:50
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.


Summary
Implements the Runtime module for Fork–Join Work Graph (#309): consumers can register steps with
WorkGraphBuilder<TContext>,Build()validates the DAG, andIWorkGraph<TContext>.RunAsyncexecutes topological waves with same-wave concurrency and fail-fast cancellation.Related Issue
Closes #309
Claim note: this automation could not add
agent-working/ assignee via the GitHub token (issues write 403); treating this PR as the claim for #309.Solution module
DesignPatterns/)DesignPatterns.Diagnostics/)DesignPatterns.SourceGenerators/)DesignPatterns.Analyzers/+DesignPatterns.CodeFixes/)DesignPatterns.Extensions.DependencyInjection/)DesignPatterns.Package/)docs/,.github/,AGENTS.md,build/)Type of change
Test plan
dotnet test tests/DesignPatterns.Tests/DesignPatterns.Tests.csproj -c Release --filter FullyQualifiedName~WorkGraphTests(14 passed)dotnet build DesignPatterns/DesignPatterns.csproj -c Release(netstandard2.0 + net8.0, 0 warnings)./build.ps1 --target Ci --configuration Release(SDK installed ad-hoc in this environment; targeted Runtime tests + dual-TFM build verified)Breaking changes
Checklist
CURSOR_SUMMARY, "Made with …")Documentation checklist
Design Doc / ROADMAP / CHANGELOG land in Docs ticket #312 after Diagnostics (#310) and SourceGenerators (#311).
Note
Medium Risk
New public concurrency API with shared-context semantics; behavior is covered by tests but callers must avoid unsynchronized same-wave writes.
Overview
Adds a fork–join work graph runtime under
DesignPatterns.Behavioral: consumers register steps with string ids andDependsOnedges viaWorkGraphBuilder<TContext>,Build()validates the DAG (empty graph, duplicate ids, bad dependencies, cycles) and materializes topological waves, andIWorkGraph<TContext>.RunAsyncruns each wave—steps in the same wave concurrently on one shared context, later waves after predecessors finish.Execution is fail-fast: the first step failure cancels in-flight peers through a linked
CancellationTokenand rethrows the real exception (not peer cancel noise). Caller cancellation is honored.WorkGraphAttribute/WorkStepAttribute(plus generic attribute on .NET 7+) are included for upcoming source-generator wiring but are not used to build graphs in this PR.Tests:
WorkGraphTestscovers validation, diamond ordering, fail-fast peer cancel, and caller cancellation.Reviewed by Cursor Bugbot for commit 5b9d798. Configure here.