Skip to content

Isolate MSBuild workers between DCP runs - #22638

Draft
Karol Zadora-Przylecki (karolz-ms) wants to merge 1 commit into
mainfrom
dev/karolz/issue-22560-investigation
Draft

Karol Zadora-Przylecki (karolz-ms) wants to merge 1 commit into
mainfrom
dev/karolz/issue-22560-investigation

Conversation

@karolz-ms

Copy link
Copy Markdown
Contributor

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: 4757cded3af081ad39cf12716cfda68a384cdbda

Dimension Assessment Rationale
Change confidence 7/10 ↑ 28 targeted macOS tests passed, including a real DCP build; an SDK 10.0.403 worker probe confirmed reuse boundaries.
↓ The reported Windows workload and warm-start impact remain unvalidated.
Diagnosis confidence 5/10 ↑ DCP's Windows cleanup job terminates its processes, consistent with a possible cross-run worker race.
↓ The affected worker's job ownership and timing have not been established.
Evidence fit 5/10 ↑ The issue reports 3/6 failures with node reuse and 0/6 without it.
↓ No Windows reproduction or worker-ownership trace confirms this hypothesis.

Description

A reported Windows AppHost can encounter MSB4166 with MSBuild node reuse enabled. This draft mitigates a possible race where a new DCP run reuses a worker owned by the previous run's cleanup job. The root cause is not yet confirmed.

Assign each DCP run a fresh MSBuild handshake salt for coordinated builds and project rebuilders. Builds with the same original salt can still reuse workers within that run. Preserve existing build properties, run-property inputs, IDE metadata, runtime environments, and publishing behavior. No dependencies or public APIs are added.

Relates to #22560

User-facing usage

Existing aspire run and Rebuild workflows automatically use the isolation; no opt-in is required. Cross-run worker reuse is lost, which can increase warm-start time. On Linux and macOS, previous workers can remain idle until MSBuild's timeout.

Security considerations

MSBuild's undocumented handshake salt is not a security boundary: its handshake value is 32-bit and collisions are possible. A configured salt may contain sensitive data, so its composed value is registered with the existing backchannel redaction history before the DCP object is created. No formal threat model or security review has been completed.

Validation

All commands ran on macOS with MSBUILDTERMINALLOGGER=false; the coordinator integration run also used a local NuGet mirror and NuGetAudit=false.

  • Passed (18): dotnet test --project tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj --no-restore --no-launch-profile -- --filter-class '*.ExecutableLaunchPlanTests' --filter-not-trait 'quarantined=true' --filter-not-trait 'outerloop=true'
  • Passed (3): dotnet test --project tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj --no-restore --no-launch-profile -- --filter-method '*.ManagedBuildEnvironmentIsIsolatedOnCreationAndRestart' --filter-method '*.EnsureDcpHostRunning_TransfersSessionFolderOwnershipToDcpOnlyWhenDcpStarts' --filter-not-trait 'quarantined=true' --filter-not-trait 'outerloop=true'
  • Passed (5): dotnet test --project tests/Aspire.Hosting.Dotnet.Tests/Aspire.Hosting.Dotnet.Tests.csproj --no-restore --no-launch-profile -- --filter-method '*.MultipleBuildGroupsRunSeriallyBeforeServicesStart' --filter-method '*.HandshakeSaltIsolationDoesNotChangeBuildPropertiesOrProjectMetadata' --filter-method '*.PublishModeDoesNotCreateCoordinatedBuildOrSuppressProjectBuild' --filter-method '*.ContextSpecificBuildEnvironmentIsSharedWithinEachBuildAttempt' --filter-method '*.ProjectWithBuildEnvironmentUsesSerializedDirectBuild' --filter-not-trait 'quarantined=true' --filter-not-trait 'outerloop=true' --hangdump --hangdump-timeout 4m
  • Passed (2): dotnet test --project tests/Aspire.Hosting.Blazor.Tests/Aspire.Hosting.Blazor.Tests.csproj --no-restore --no-launch-profile -- --filter-method '*.AddBlazorGateway_RendersCompleteProcessLaunchPlan' --filter-method '*.AddDotnetProjectBlazorGateway_RendersCompleteProcessLaunchPlan' --filter-not-trait 'quarantined=true' --filter-not-trait 'outerloop=true'
  • Passed: An SDK 10.0.403 MSBuild worker probe using implementation-generated salts reused a worker within one run and used separate workers for a new run and an unsalted external build.
  • Not run: The reported Windows 11 / SDK 10.0.402 restart sequence and representative warm-build timing comparison. Windows validation is required before this draft is ready to ship.

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 22638

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 22638"

@github-actions github-actions Bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Nov 25, 2026
@aspire-repo-bot
aspire-repo-bot Bot requested a balanced review from Copilot November 25, 2026 01:05
@github-actions

Copy link
Copy Markdown
Contributor

Tests selector

52 / 101 PR test projects · 4 PR jobs, from 10 changed files.

Selected PR test projects (52 / 101)

Aspire.Cli.EndToEnd.Tests, Aspire.Hosting.Analyzers.Tests, Aspire.Hosting.Azure.EntraId.Tests, Aspire.Hosting.Azure.Kubernetes.Tests, Aspire.Hosting.Azure.Kusto.Tests, Aspire.Hosting.Azure.Provisioning.Tests, Aspire.Hosting.Azure.Tests, Aspire.Hosting.Blazor.Tests, Aspire.Hosting.Browsers.Tests, Aspire.Hosting.CodeGeneration.Go.Tests, Aspire.Hosting.CodeGeneration.Java.Tests, Aspire.Hosting.CodeGeneration.Python.Tests, Aspire.Hosting.CodeGeneration.Rust.Tests, Aspire.Hosting.CodeGeneration.TypeScript.Tests, Aspire.Hosting.Containers.Tests, Aspire.Hosting.DevTunnels.Tests, Aspire.Hosting.Docker.Tests, Aspire.Hosting.Dotnet.Tests, Aspire.Hosting.DotnetTool.Tests, Aspire.Hosting.EntityFrameworkCore.Tests, Aspire.Hosting.Foundry.Tests, Aspire.Hosting.Garnet.Tests, Aspire.Hosting.Go.Tests, Aspire.Hosting.Java.Tests, Aspire.Hosting.JavaScript.Tests, Aspire.Hosting.Kafka.Tests, Aspire.Hosting.Keycloak.Tests, Aspire.Hosting.Kubernetes.Tests, Aspire.Hosting.Maui.Tests, Aspire.Hosting.Milvus.Tests, Aspire.Hosting.MongoDB.Tests, Aspire.Hosting.MySql.Tests, Aspire.Hosting.Nats.Tests, Aspire.Hosting.OpenAI.Tests, Aspire.Hosting.Oracle.Tests, Aspire.Hosting.Orleans.Tests, Aspire.Hosting.PostgreSQL.Tests, Aspire.Hosting.Python.Tests, Aspire.Hosting.Qdrant.Tests, Aspire.Hosting.RabbitMQ.Tests, Aspire.Hosting.Radius.Tests, Aspire.Hosting.Redis.Tests, Aspire.Hosting.RemoteHost.Tests, Aspire.Hosting.Rust.Tests, Aspire.Hosting.Seq.Tests, Aspire.Hosting.SqlServer.Tests, Aspire.Hosting.Testing.Tests, Aspire.Hosting.Tests, Aspire.Hosting.Valkey.Tests, Aspire.Hosting.Yarp.Tests, Aspire.Playground.Tests, Aspire.Templates.Tests

Selected PR jobs (4)

cli-starter-validation, extension-e2e, polyglot, typescript-api-compat


How these were chosen — grouped by what changed

⚠️ 46 of the 52 selected test projects come from a single change — src/Aspire.Hosting/Dcp/DcpHost.cs.

🔧 src/Aspire.Hosting/Dcp/DcpHost.cs (changed source)
→ 46 via the project graph

show 46

Aspire.Hosting.Analyzers.Tests (2 hops), Aspire.Hosting.Azure.EntraId.Tests (2 hops), Aspire.Hosting.Azure.Kubernetes.Tests (2 hops), Aspire.Hosting.Azure.Kusto.Tests (2 hops), Aspire.Hosting.Azure.Provisioning.Tests (3 hops), Aspire.Hosting.Azure.Tests, Aspire.Hosting.Browsers.Tests (2 hops), Aspire.Hosting.CodeGeneration.Go.Tests, Aspire.Hosting.CodeGeneration.Java.Tests, Aspire.Hosting.CodeGeneration.Python.Tests, Aspire.Hosting.CodeGeneration.Rust.Tests, Aspire.Hosting.CodeGeneration.TypeScript.Tests, Aspire.Hosting.Containers.Tests (2 hops), Aspire.Hosting.DevTunnels.Tests (2 hops), Aspire.Hosting.Docker.Tests (2 hops), Aspire.Hosting.DotnetTool.Tests (2 hops), Aspire.Hosting.EntityFrameworkCore.Tests (2 hops), Aspire.Hosting.Foundry.Tests (2 hops), Aspire.Hosting.Garnet.Tests (2 hops), Aspire.Hosting.Go.Tests (2 hops), Aspire.Hosting.Java.Tests (2 hops), Aspire.Hosting.JavaScript.Tests (2 hops), Aspire.Hosting.Kafka.Tests (2 hops), Aspire.Hosting.Keycloak.Tests (2 hops), Aspire.Hosting.Kubernetes.Tests (2 hops), Aspire.Hosting.Maui.Tests, Aspire.Hosting.Milvus.Tests (2 hops), Aspire.Hosting.MongoDB.Tests (2 hops), Aspire.Hosting.MySql.Tests (2 hops), Aspire.Hosting.Nats.Tests (2 hops), Aspire.Hosting.OpenAI.Tests (2 hops), Aspire.Hosting.Oracle.Tests (2 hops), Aspire.Hosting.Orleans.Tests (2 hops), Aspire.Hosting.PostgreSQL.Tests (2 hops), Aspire.Hosting.Python.Tests (2 hops), Aspire.Hosting.Qdrant.Tests (2 hops), Aspire.Hosting.RabbitMQ.Tests (2 hops), Aspire.Hosting.Redis.Tests (2 hops), Aspire.Hosting.RemoteHost.Tests, Aspire.Hosting.Rust.Tests (2 hops), Aspire.Hosting.Seq.Tests (2 hops), Aspire.Hosting.SqlServer.Tests (2 hops), Aspire.Hosting.Testing.Tests (2 hops), Aspire.Hosting.Valkey.Tests (2 hops), Aspire.Hosting.Yarp.Tests (2 hops), Aspire.Playground.Tests

📦 affected project Aspire.Hosting.Dotnet
→ 2 tests: Aspire.Cli.EndToEnd.Tests, Aspire.Templates.Tests

🧪 tests/Aspire.Hosting.Tests/Dcp/DcpExecutorTests.cs (changed test)
→ 1 directly: Aspire.Hosting.Tests
→ 1 via the project graph: Aspire.Hosting.Radius.Tests

📦 affected project Aspire.Hosting
→ 1 test: Aspire.Cli.EndToEnd.Tests

🧪 tests/Aspire.Hosting.Blazor.Tests/AddBlazorGatewayTests.cs (changed test)
→ 1 directly: Aspire.Hosting.Blazor.Tests

🧪 tests/Aspire.Hosting.Dotnet.Tests/DotnetProjectBuildCoordinatorTests.cs (changed test)
→ 1 directly: Aspire.Hosting.Dotnet.Tests

🧪 tests/Aspire.Hosting.Tests/Dcp/DcpHostNotificationTests.cs (changed test)
→ 1 directly: Aspire.Hosting.Tests

🧪 tests/Aspire.Hosting.Tests/Dcp/ExecutableLaunchPlanTests.cs (changed test)
→ 1 directly: Aspire.Hosting.Tests

Job reasons

Job Triggered by
cli-starter-validation affected project Aspire.Hosting.Redis
extension-e2e • src/Aspire.Hosting/Dcp/DcpHost.cs, src/Aspire.Hosting/Dcp/ExecutableCreator.cs, src/Aspire.Hosting/Dcp/MsBuildNodeReuseIsolation.cs, src/Aspire.Hosting/DistributedApplicationBuilder.cs, src/Aspire.Hosting/Lifecycle/DotnetBuildCommandEventingSubscriber.cs
• affected project Aspire.Hosting
polyglot • affected project Aspire.Hosting
• affected project Aspire.Hosting.Azure.Provisioning
typescript-api-compat affected project Aspire.Hosting

Selection computed for commit 4757cde.

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.

🔵 Needs a closer look

The mitigation relies on undocumented MSBuild handshake and Windows job-lifetime behavior, while macOS checks cannot validate the reported Windows restart fix or representative warm-start cost.

No open issues 🎉

What changed in this PR

This PR isolates MSBuild worker reuse by DCP run to mitigate the suspected cross-run cleanup race behind Windows MSB4166 failures in #22560. The reported Windows restart scenario remains unvalidated.

Changes:

  • Composes a per-run handshake salt for coordinated builds and rebuilders, preserving configured build properties, runtime environments, and IDE metadata.
  • Registers composed salts for secret redaction and adds coverage for reuse boundaries, overrides, restarts, and publishing behavior.
  • Documents the warm-start and idle-worker memory tradeoffs.
File Description
tests/​Aspire.Hosting.Tests/​Dcp/​ExecutableLaunchPlanTests.cs Tests salt composition, isolation, redaction, casing, and unaffected executables.
tests/​Aspire.Hosting.Tests/​Dcp/​DcpHostNotificationTests.cs Checks inherited salt initialization when DCP starts.
tests/​Aspire.Hosting.Tests/​Dcp/​DcpExecutorTests.cs Tests isolation on resource creation and restart.
tests/​Aspire.Hosting.Dotnet.Tests/​DotnetProjectBuildCoordinatorTests.cs Verifies build isolation while preserving properties, metadata, runtime settings, and publishing.
tests/​Aspire.Hosting.Blazor.Tests/​AddBlazorGatewayTests.cs Updates renderer calls for the new dependencies.
src/​Aspire.Hosting/​Lifecycle/​DotnetBuildCommandEventingSubscriber.cs Exposes the managed-build predicate for internal reuse.
src/​Aspire.Hosting/​DistributedApplicationBuilder.cs Registers the DCP-owned isolation service.
src/​Aspire.Hosting/​Dcp/​MsBuildNodeReuseIsolation.cs Implements per-run salt composition and redaction registration.
src/​Aspire.Hosting/​Dcp/​ExecutableCreator.cs Applies isolation when rendering executable environments.
src/​Aspire.Hosting/​Dcp/​DcpHost.cs Initializes isolation before launching DCP.
src/​Aspire.Hosting.Dotnet/​README.md Documents worker reuse boundaries and operational tradeoffs.

Review effort: Balanced

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

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.

🔵 Needs a closer look

The mitigation relies on an undocumented MSBuild handshake, while the suspected Windows DCP cleanup race and warm-build impact remain unvalidated and require human runtime verification before shipping.

No open issues 🎉

Review effort: Max

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants