On Windows, concurrent writeInstallState calls (and real-time antivirus
scans of each freshly published file) can hold replacement sharing locks
for over a second. renameAtomic retried at a fixed 25 ms interval, which
kept contenders in lockstep, so one writer could lose every round and
give up with EPERM at the 2 s deadline. This made
tests/lib/install-state.test.js fail in about half of isolated runs.
- Retry with a uniform random wait of 1-25 ms instead of a fixed 25 ms.
Exponential backoff was measured and made starvation worse.
- Add a renameRetryBudgetMs option to writeFileAtomic. The default stays
2 s, so hook callers keep their latency bound, and the attempt cap is
derived from the budget (81 for the default).
- writeInstallState uses a 10 s budget, since it runs only during installs.
Measured on Windows 11 with Defender on: install-state test 0/12
failures (previously 4/8).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reject directory replacement after temporary file creation or staging, preserve unrelated files during cleanup, and retry settings edits observed before the final rename. Add three regression tests for the review findings.