Repository navigation
Lint: replace the cmdlet ban with a cross-runspace scriptblock check - #3
Merged
Merged
Conversation
Stress testing showed cmdlets are safe in worker runspaces: with cmdlets put back in every Full Pipeline worker path, 2,000 one-run-per-process Full Pipeline runs (fake and real cjxl/magick) never hung. The old hang came from a scriptblock running on another runspace's thread: a shared System.Lazy factory created by one engine ran on the other engine's thread, every scriptblock it ran inside (a Where-Object filter, a nested delegate) was queued back to the first engine, and that engine was blocked on the same Lazy. The current caches already avoid this. Lint Rule 7 no longer bans cmdlets. It now flags a scriptblock crossing into a worker: a scriptblock value in a -JobParams or -NextJobProvider hashtable, or a scriptblock variable passed to a .NET method or constructor from runspace-reachable code (Rule 8 covers the literal and cast forms). Rule 8's comment, the worker-runspace rules in module-descriptions.md and two code comments now describe the real mechanism. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
What was wrong
Lint Rule 7 banned cmdlets in worker-runspace code, on the theory that two fresh runspaces calling a cmdlet for the first time at once can deadlock in Windows PowerShell 5.1. Stress testing shows that theory is wrong. The Full Pipeline hang it was written for came from a scriptblock running on another runspace's thread: a shared
System.Lazyfactory created by one engine ran on the other engine's thread. Every scriptblock it ran inside (aWhere-Objectfilter, a nested delegate) was queued back to the first engine, which was blocked on the sameLazy. Removing cmdlets only looked like a fix because it removed most of those scriptblock calls. The current caches no longer do this.What changed
-JobParamsentry, or in a hashtable the-NextJobProviderreturnsmodule-descriptions.md, and two code comments inController.ps1andFileDeletion.ps1now describe the real mechanism. No behavior changes in the modules. The existing .NET calls stay.How it was tested
cjxl/magick.Lazycaches plus cmdlets hung 116 times in 600 runs. All six process dumps show the same cross-runspace deadlock.Lazy. Plain cmdlets in the factory never hang. A factory that runs a scriptblock hangs 5 out of 5 when the owning runspace is blocked.mainpasses it. Rule 8 still flags all three sites in the old cache code.Follow-up: #4 (review fixes and a runtime guard, pushed after this was merged).
🤖 Generated with Claude Code