Skip to content

Fix V2 dependency resolution thread-affinity failure#2008

Open
Gijsreyn wants to merge 2 commits into
PowerShell:masterfrom
Gijsreyn:fix/main/v2-dependency-thread-affinity
Open

Fix V2 dependency resolution thread-affinity failure#2008
Gijsreyn wants to merge 2 commits into
PowerShell:masterfrom
Gijsreyn:fix/main/v2-dependency-thread-affinity

Conversation

@Gijsreyn
Copy link
Copy Markdown

PR Summary

Fixes a regression in V2 dependency resolution where Install-PSResource and Find-PSResource -IncludeDependencies could call PowerShell cmdlet output APIs from worker threads while resolving large dependency graphs.

The fix changes recursive dependency discovery so parallel workers only enqueue errors and stream messages. The outer dependency discovery entry point now flushes those queues once it is back on the cmdlet pipeline thread.

Small test added to cover regression so no full Az dependency graph needs to be resolved.

PR Context

Fixes #2006.

PR Checklist

Copilot AI review requested due to automatic review settings May 30, 2026 10:38
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR makes dependency discovery for V2 server protocol more deterministic/testable by introducing a test hook that controls when dependency lookups run in parallel, and by refactoring dependency-finding to aggregate output messages from concurrent execution.

Changes:

  • Added an InternalHooks field to override the parallelization threshold for dependency queries.
  • Updated dependency discovery to pass shared concurrent message queues through recursive calls and flush once.
  • Updated the V2 server protocol test to force parallel dependency resolution and restore the hook afterward.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
test/FindPSResourceTests/FindPSResourceV2Server.Tests.ps1 Sets/resets a test hook to force parallel dependency resolution during the test.
src/code/InternalHooks.cs Adds a new internal hook (FindDependencyPackagesParallelThreshold) with default -1.
src/code/FindHelper.cs Refactors dependency resolution to propagate concurrent message queues and uses the new threshold hook for parallelization.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/FindPSResourceTests/FindPSResourceV2Server.Tests.ps1
Comment thread src/code/FindHelper.cs
Comment on lines +1171 to +1178
ConcurrentQueue<ErrorRecord> errorMsgs = new ConcurrentQueue<ErrorRecord>();
ConcurrentQueue<string> verboseMsgs = new ConcurrentQueue<string>();
ConcurrentQueue<string> debugMsgs = new ConcurrentQueue<string>();
ConcurrentQueue<string> warningMsgs = new ConcurrentQueue<string>();

_cmdletPassedIn.WriteDebug($"In FindHelper::FindDependencyPackages() - {currentPkg.Name}");
FindDependencyPackagesHelper(currentServer, currentResponseUtil, currentPkg, repository, errorMsgs, warningMsgs, debugMsgs, verboseMsgs);
Utils.WriteOutConcurrentQueue(_cmdletPassedIn, errorMsgs, warningMsgs, debugMsgs, verboseMsgs);
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't fix.

Comment thread src/code/FindHelper.cs Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot install modules with dependencies through PowerShell Gallery on 1.3.0-preview1

2 participants