Skip to content

ci: run PSScriptAnalyzer's two racing rules apart - #174

Merged
eizedev merged 2 commits into
mainfrom
ci/pssa-race
Nov 23, 2026
Merged

eizedev merged 2 commits into
mainfrom
ci/pssa-race

Conversation

@eizedev

@eizedev eizedev commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Fixes #168

Invoke-ScriptAnalyzer in the powershell job crashes now and then. Main failed this way after #172 was merged, and #173 failed twice in a row. This pull request removes the cause instead of retrying.

Cause

PSScriptAnalyzer 1.25.0 runs the rules for a file in parallel. PSProvideCommentHelp and PSReservedCmdletChar both read the parameters of Export-ModuleMember through a runspace that the other rules use at the same time. Every module file here calls Export-ModuleMember. Now and then one of the two rules gets a NullReferenceException, or the two collide with "You cannot have more than one dynamic module in each dynamic assembly". Both messages are in our failed runs. The analysis and the stacks are in PowerShell/PSScriptAnalyzer#2229 (open, no fixed release; 1.25.0 is the latest). The per-folder calls from #39 never removed this cause: the recent failures came from them.

Change

  • build/Invoke-ScriptAnalysis.ps1 runs the analyzer as CI does:
    • PSProvideCommentHelp is left out. It reports Information only, which this check never counted.
    • PSReservedCmdletChar (a Warning) runs in a pass of its own, with no other rule beside it. This is the workaround from #2229.
    • On a crash it writes the full exception with its stack, so the log names the rule.
  • CI and AGENTS.md call the script instead of each holding a copy of the command.
  • The script's help says to put the rule back once a PSScriptAnalyzer release fixes #2229.

Evidence

  • Upstream measured 0 failures in 85 runs of this workaround, and 30 of 30 clean runs with both rules excluded.
  • I could not reproduce the crash on macOS: 45 fresh runs of the old command, 0 failures. CI: PSScriptAnalyzer crashes now and then with a NullReferenceException #168 reports the same. CI is the proof, so I reran the powershell job three times on this pull request (results in a comment below).
  • Locally the script finds a planted Write-Host and fails, and it passes on the repository.

Not changed

  • If the crash still happened, pwsh may hang after it (upstream reports this). The job's timeout-minutes: 15 bounds that.

🤖 Generated with Claude Code

eizedev and others added 2 commits November 23, 2026 02:39
… longer crashes now and then

PSScriptAnalyzer 1.25.0 runs a file's rules in parallel. PSProvideCommentHelp and PSReservedCmdletChar
read Export-ModuleMember's parameters through a runspace the other rules use at the same time, which
now and then fails the whole call with a NullReferenceException or "more than one dynamic module in
each dynamic assembly" (PowerShell/PSScriptAnalyzer#2229, open). build/Invoke-ScriptAnalysis.ps1 leaves
out PSProvideCommentHelp (Information, which the check does not count) and runs PSReservedCmdletChar
in a pass of its own; on a crash it writes the full exception with its stack. CI and AGENTS.md call
the script instead of each holding the command.

Fixes #168

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@eizedev

eizedev commented Nov 23, 2026

Copy link
Copy Markdown
Owner Author

The powershell job ran four times on this head: the first run and three reruns of the job (https://github.com/eizedev/powershell-universal-components/actions/runs/45096405440, attempts 1 to 4). All four passed, with PSScriptAnalyzer clean and Pester 358 passed, 0 failed, 13 skipped.

@eizedev
eizedev merged commit 2a8c623 into main Nov 23, 2026
38 checks passed
@eizedev
eizedev deleted the ci/pssa-race branch November 23, 2026 02:23
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.

CI: PSScriptAnalyzer crashes now and then with a NullReferenceException

1 participant