Repository navigation
Honor multithreadable attributes on inline task classes - #15128
JanProvaznik merged 6 commits into
Conversation
Keep the supported-factory gate and forced-isolation precedence while honoring the existing task attribute. Add routing and factory-rejection regressions and document class-mode support. Co-authored-by: Copilot App <[email protected]>
Compare inline and assembly task PIDs in one C# MT test. Remove the VB fixture and mode matrix, and focus custom-factory coverage on rejection before task creation. Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
Preserve explicit MSBuildRuntime and MSBuildArchitecture parameters when routing attributed inline tasks.
Review effort: Lite
Findings: None
What changed in this PR
Updates MSBuild routing so attributed Roslyn inline task classes can run in-process during multithreaded builds.
Changes:
- Routes supported factories using the concrete task’s multithreadable attribute.
- Adds inline-task and unsupported-factory regression tests.
- Documents inline class opt-in and focused test guidance.
| File | Summary |
|---|---|
src/Tasks.UnitTests/RoslynCodeTaskFactory_Tests.cs |
Adds PID-based inline routing regression coverage. |
src/Build/BackEnd/TaskExecutionHost/TaskExecutionHost.cs |
Applies attribute-aware routing while preserving forced isolation; explicit identity parameters require correction. |
src/Build.UnitTests/BackEnd/TaskExecutionHost_Tests.cs |
Verifies unsupported factories remain rejected. |
documentation/specs/multithreading/thread-safe-tasks.md |
Documents inline task opt-in. |
.github/instructions/tests.instructions.md |
Adds focused routing-test guidance. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
| # | Dimension | Verdict |
|---|---|---|
| 22 | Correctness & Edge Cases | 🔴 1 BLOCKING |
✅ 23/24 dimensions clean.
- Correctness — repeated in-process Roslyn inline-task invocation can lose its external-assembly resolver after the first cleanup
Warning
Firewall blocked 3 domains
The following domains were blocked by the firewall during workflow execution:
api.github.comgithub.compatchdiff.githubusercontent.com
[!TIP]
api.github.com is blocked because GitHub API access uses the built-in GitHub tools by default. Instead of adding api.github.com to network.allowed, use tools.github.mode: gh-proxy for direct pre-authenticated GitHub CLI access without requiring network access to api.github.com:
tools:
github:
mode: gh-proxySee GitHub Tools for more information on gh-proxy mode.
To allow these domains, add them to the network.allowed list in your workflow frontmatter:
network:
allowed:
- defaults
- "api.github.com"
- "github.com"
- "patchdiff.githubusercontent.com"See Network Configuration for more information.
Generated by Expert Code Review (on open) for #15128 · copilot · gpt56 · 941.4 AIC · ⌖ 6.96 AIC · ⊞ 17.8K
Cache the resolver with the compiled assembly and balance subscriptions per task instance, preserving initialization-time resolution and overlapping invocations. Ignore TaskHost wrapper cleanup and release subscriptions on failed initialization or construction. Co-authored-by: Copilot App <[email protected]>
MSBuild code reviewScope: Assessment: request changes. No blocking correctness defect was identified. Backward compatibility checks out, and no ChangeWave is needed: Must fix
Recommended in this PR
Follow-up considerations
What's goodThe routing fix is minimal and preserves the unsupported-factory gate before attribute routing. The resolver-lifetime bug being addressed is real, happy-path registration accounting balances, and concurrent first-task handoff uses |
Include initialization in batch cleanup, preserve assembly-load tracking through cleanup, and cover a throwing BuildEngine setter. Protect resolver test cleanup on assertion failures and remove PR-specific test guidance. Co-authored-by: Copilot App <[email protected]>
|
Thanks @ViktorHofer. Addressed the cleanup issues in dda9b94:
H2: not adding more PID/isolation end-to-end cases. The negative routing and forced-isolation paths are covered elsewhere; duplicating those runs adds flakiness without useful additional coverage for this change. For the remaining points: the short documentation is intentional (H1), and the subscription ownership comments plus inner-task/wrapper cleanup sequence are already covered (H3). Binlogs are intentional diagnostics (L1). M3/M4: supported factories instantiate their declared task type; CodeTaskFactory already has a persistent resolver, and generated XAML tasks remain unattributed. M6: a weak routing cache would not make these statically cached, noncollectible assemblies unloadable, so I am leaving that redesign out. M2 is worth separate investigation, rather than expanding this PR into a dependency-loader redesign. Full build passed. TaskBuilder and Roslyn factory tests passed on both .NET and .NET Framework (185 tests total, none skipped). |
Related issue(s): #14138 (partial)
Context
Roslyn inline task classes run in a TaskHost during multithreaded builds even when marked
[MSBuildMultiThreadableTask].Changes Made
Respect the concrete task class's attribute when routing tasks from supported factories. Keep dependency resolvers available across repeated and overlapping invocations, including compiled-assembly cache hits. Add focused C# regressions and document class-based opt-in.
Compatibility
Unannotated tasks and generated
Fragment/Methodtasks remain isolated. Unsupported custom factories remain rejected, and forced isolation still takes precedence. No public API changes.Testing
Full build passed. Roslyn factory tests passed: 68 on .NET and 66 on .NET Framework 4.7.2. The reviewer's delayed-dependency repro now passes. PID routing and unsupported-factory regressions passed on both target frameworks. Earlier full-suite validation had one desktop test fail because
msbuildwas missing fromPATH; its isolated retry passed with Visual Studio MSBuild onPATH.Dependencies and Follow-up
Possible follow-up: support
TaskEnvironmentconstructor injection for Roslyn task classes. Pass the invocation's environment through the internal factory context and reuse the existing environment-constructor/parameterless-constructor selection. Also avoid creating a throwaway task in the parent on the sidecar path; use the factory's task type for metadata, preserving cleanup responsibilities. This PR retains the public parameterless-constructor requirement.Fragment/Method authoring support is deferred.
Fixes: #14138