Skip to content

fix: Retry the analyzer in the Analyze task - #148

Merged
tablackburn merged 2 commits into
mainfrom
claude/powershellbuild-136-rca-tnas0k
Aug 3, 2026
Merged

fix: Retry the analyzer in the Analyze task#148
tablackburn merged 2 commits into
mainfrom
claude/powershellbuild-136-rca-tnas0k

Conversation

@tablackburn

Copy link
Copy Markdown
Contributor

Summary

  • Retry the Invoke-ScriptAnalyzer call in the Analyze task up to three times, rethrowing on the last attempt, so the intermittent PSScriptAnalyzer crash tracked in CI: Intermittent PSScriptAnalyzer crash in the Analyze task #136 no longer fails the build
  • Pass -ErrorAction Stop explicitly rather than relying on build.ps1 setting $ErrorActionPreference process-wide, so the try/catch does not depend on an ambient caller preference

The crash is a thread-safety defect inside PSScriptAnalyzer, which runs its script rules in parallel against a process-wide unsynchronised singleton. It has no relationship to the code being analyzed, which is why re-running the job always succeeded. Full root cause analysis, reproduction, and upstream links are in this comment on #136.

The retry is deliberately unconditional rather than matched against the known crash signatures. Those signatures are symptoms of an upstream race rather than a fixed contract — four distinct exception types appeared during the analysis — so matching on them would let a new variant bypass the mitigation. The cost is that a genuine analyzer failure takes three attempts before failing, which is a few seconds on a path already headed for red.

Test Plan

  • ./build.ps1 -Task Test passes (422 passed, 0 failed, 15 skipped)
  • Validated against a reproduction of the race: 45 runs of the real Analyze task, zero build failures, with the crash occurring and being absorbed
  • Confirmed a non-transient failure still fails the build, since the final attempt rethrows
  • CI green across the ubuntu-latest / windows-latest / macOS-latest matrix

Breaking Changes

None. This changes only this repository's own build, not the shipped module.

Notes

  • Test-PSBuildScriptAnalysis in the shipped module is exposed to the same race but behaves differently, since it calls Invoke-ScriptAnalyzer without -ErrorAction Stop and so does not fail. Tracked separately in Test-PSBuildScriptAnalysis does not fail on the PSScriptAnalyzer rule crash from #136 #147 and deliberately out of scope here.
  • No CHANGELOG.md entry, per the changelog scope rule in instructions/repository-specific.instructions.md: the changelog covers user-facing changes to the shipped module, and this touches only this repository's own build script.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Y2tE5nDWYPfmyWP2yPeWXT


Generated by Claude Code

PSScriptAnalyzer executes its script rules in parallel against a
process-wide, unsynchronised singleton, so concurrent rules can observe
half-updated PowerShell session state and crash. The failure has no
relationship to the code being analyzed, which is why re-running the job
always succeeded.

Retry the analyzer call up to three times, rethrowing on the last
attempt. The retry is unconditional: the observed crash signatures are
symptoms of an upstream race rather than a fixed contract, and matching
on them would let a new variant bypass the mitigation.

Pass -ErrorAction Stop explicitly rather than relying on build.ps1
setting ErrorActionPreference process-wide, so the try/catch does not
depend on an ambient caller preference.

Validated over 45 runs of the Analyze task against a reproduction of the
race: zero build failures, with the crash occurring and being absorbed.

Refs #136

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y2tE5nDWYPfmyWP2yPeWXT
Copilot AI review requested due to automatic review settings August 2, 2026 22:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds resilience to the repository build’s Analyze psake task by retrying Invoke-ScriptAnalyzer to mitigate intermittent upstream PSScriptAnalyzer crashes, while also making failure semantics explicit via -ErrorAction Stop.

Changes:

  • Wrap Invoke-ScriptAnalyzer in a bounded (3-attempt) retry loop with a short delay between attempts.
  • Pass -ErrorAction Stop via a splatted parameter hashtable to avoid relying on ambient $ErrorActionPreference.
  • Add inline documentation referencing the tracked flake (issue #136).

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

Comment thread psakeFile.ps1 Outdated
@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown

Test Results

    4 files  +    3    696 suites  +522   3m 1s ⏱️ + 2m 42s
  436 tests ±    0    434 ✅ +   13   2 💤  - 13  0 ❌ ±0 
1 748 runs  +1 311  1 701 ✅ +1 279  47 💤 +32  0 ❌ ±0 

Results for commit 4ad9320. ± Comparison against base commit 64b7207.

♻️ This comment has been updated with latest results.

The retry warning named only the attempt number, so a crash absorbed
before the final attempt left no record of what actually failed. That
undercuts the reason the retry is unconditional: a new crash variant
would be retried away silently instead of being visible in the log.

Include the error id and message in the warning. The id is the useful
discriminator - RULE_ERROR marks the upstream rule crash, while anything
else, such as PathNotFound, indicates a genuine analyzer failure that
happens to be getting retried.

Also copy $_ into a variable at the top of the catch block, per the error
handling convention in instructions/powershell.instructions.md.

Raised in review on #148.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y2tE5nDWYPfmyWP2yPeWXT
@tablackburn
tablackburn merged commit f726f48 into main Aug 3, 2026
9 checks passed
@tablackburn
tablackburn deleted the claude/powershellbuild-136-rca-tnas0k branch August 3, 2026 01:08
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.

3 participants