Improve cross-platform node discovery for reuse with NodeMode filtering#13256
Open
Improve cross-platform node discovery for reuse with NodeMode filtering#13256
Conversation
Copilot
AI
changed the title
[WIP] Improve cross-platform MSBuild node discovery for reuse
Improve cross-platform node discovery for reuse with NodeMode filtering
Feb 12, 2026
baronfel
requested changes
Feb 12, 2026
src/Build/BackEnd/Components/Communications/NodeProviderOutOfProcBase.cs
Outdated
Show resolved
Hide resolved
baronfel
reviewed
Feb 13, 2026
baronfel
reviewed
Feb 13, 2026
src/Build/BackEnd/Components/Communications/NodeProviderOutOfProcBase.cs
Outdated
Show resolved
Hide resolved
baronfel
approved these changes
Feb 13, 2026
baronfel
reviewed
Feb 13, 2026
baronfel
reviewed
Feb 13, 2026
baronfel
reviewed
Feb 13, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request implements cross-platform MSBuild node discovery improvements to enable better node reuse. The key change is extending node discovery beyond just Process.GetProcessesByName() to also inspect dotnet processes hosting MSBuild.dll and filter candidates by NodeMode type, ensuring worker nodes only reuse worker nodes and task host nodes only reuse task host nodes.
Changes:
- Added cross-platform
ProcessExtensions.GetCommandLine()to retrieve process command lines via WMI (Windows/.NET Framework), native Windows APIs (Windows/.NET Core+), /proc filesystem (Linux), and sysctl (macOS) - Enhanced
GetPossibleRunningNodes()to discover both msbuild.exe and dotnet processes, filter by MSBuild.dll presence, and validate/filter by NodeMode using regex extraction - Added NodeMode helper methods
ToCommandLineArgument()andTryParse()for consistent command line formatting and parsing
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 13 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Shared/ProcessExtensions.cs | Implements cross-platform command line retrieval with platform-specific implementations for Windows (WMI + native APIs), Linux (/proc), and macOS (sysctl) |
| src/Utilities/Microsoft.Build.Utilities.csproj | Adds System.Management reference for .NET Framework to support WMI-based command line retrieval |
| src/Build/Microsoft.Build.csproj | Adds System.Management reference for .NET Framework in Build project |
| src/Build/BackEnd/Components/Communications/NodeProviderOutOfProcBase.cs | Enhances node discovery to search both msbuild.exe and dotnet processes, extracts NodeMode via regex, and filters candidates by matching NodeMode values |
| src/Framework.UnitTests/NodeMode_Tests.cs | Adds comprehensive unit tests for NodeMode command line formatting and parsing (integers, enum names, invalid values) |
| src/Utilities.UnitTests/ProcessExtensions_Tests.cs | Adds tests for GetCommandLine() including null process, running process, exited process, and Unix-specific scenarios |
src/Build/BackEnd/Components/Communications/NodeProviderOutOfProcBase.cs
Outdated
Show resolved
Hide resolved
src/Build/BackEnd/Components/Communications/NodeProviderOutOfProcBase.cs
Outdated
Show resolved
Hide resolved
src/Build/BackEnd/Components/Communications/NodeProviderOutOfProcBase.cs
Show resolved
Hide resolved
src/Build/BackEnd/Components/Communications/NodeProviderOutOfProcBase.cs
Outdated
Show resolved
Hide resolved
src/Build/BackEnd/Components/Communications/NodeProviderOutOfProcBase.cs
Outdated
Show resolved
Hide resolved
| bool nodeReuseRequested = Handshake.IsHandshakeOptionEnabled(hostHandshake.HandshakeOptions, HandshakeOptions.NodeReuse); | ||
|
|
||
| // Extract the expected NodeMode from the command line arguments | ||
| NodeMode? expectedNodeMode = ExtractNodeModeFromCommandLine(commandLineArgs); |
There was a problem hiding this comment.
This assignment to expectedNodeMode is useless, since its value is never read.
baronfel
reviewed
Feb 13, 2026
rainersigwald
approved these changes
Feb 17, 2026
Member
|
…iscovery Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
…for parsing Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
…al tests Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
…posal Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
…, logging, TOCTOU fix Co-authored-by: rainersigwald <3347530+rainersigwald@users.noreply.github.com>
…it across both locations that tried to parse node modes
Co-authored-by: rainersigwald <3347530+rainersigwald@users.noreply.github.com>
…ttern constant, use ValueSpan Co-authored-by: rainersigwald <3347530+rainersigwald@users.noreply.github.com>
Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
0eddd86 to
dfa51d7
Compare
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
Improves MSBuild node discovery to enable better node reuse by filtering candidate processes by NodeMode type. This ensures worker nodes only reuse worker nodes and task host nodes only reuse task host nodes, preventing incompatible node reuse.
Customer Impact
Positive Impact:
Opt-out Mechanism:
MSBUILDDISABLEFEATURESFROMVERSION=18.6if issues ariseRegression?
This is new functionality for improved node discovery. The feature is opt-in via change wave and includes defensive error handling:
Testing
Unit Tests:
ProcessExtensions.GetCommandLine()tests covering Windows, Linux, and macOSCode Quality:
ValueSpanon .NET to avoid string allocation when parsing NodeMode from command linesMacOSOnlyFactAttributefromMicrosoft.DotNet.XUnitExtensionsImplementation Details:
Process command line retrieval (
ProcessExtensions.cs)/proc/{pid}/cmdlinewith UTF-8 encoding, fixed TOCTOU issue(CTL_KERN, KERN_PROCARGS2, pid), properly handles padding nulls between executable path and argumentsEnhanced node discovery (
NodeProviderOutOfProcBase.cs)expectedProcessName(maintains framework vs core separation)expectedProcessNameis dotnet, filters by MSBuild.dll presence in command line/nodemode:<value>parameter usingNodeModeHelper.ExtractFromCommandLine()(consistent withDebugUtils)expectedNodeModeis providedConstants.DotnetProcessNamefor cross-platform dotnet detectionCommunicationsUtilities.Trace()at every decision point for debuggingNodeMode helpers (
NodeMode.cs)ToCommandLineArgument(): Format as/nodemode:{value}TryParse(): Parse integer or enum name (case-insensitive)ExtractFromCommandLine(): Extract NodeMode from command line using regex (with source generator for .NET 10+, static compiled regex for .NET Framework)Risk
Risk Mitigation:
ValueSpanon .NET to avoid string allocation during parsingOriginal prompt
This pull request was created from Copilot chat.
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.