Skip to content

test: use async rm for Windows locked-executable temp cleanup - #2210

Merged
YishenTu merged 1 commit into
mainfrom
test/deflake-opencode-fork-cleanup
Nov 12, 2026
Merged

YishenTu merged 1 commit into
mainfrom
test/deflake-opencode-fork-cleanup

Conversation

@YishenTu

Copy link
Copy Markdown
Owner

Why

ForkSource.opencode.test.ts > keeps a configured CLI sibling Node directory on PATH when forking flaked on windows-latest (run 43172864375). Its assertions passed, but the afterEach cleanup failed with EPERM, Permission denied: \\?\C:\...\claudian-opencode-fork-*. On Windows the test copies node.exe into the temp directory and runs it, and Windows briefly keeps the just-exited image locked. Teardown already passed maxRetries: 10, retryDelay: 100 to cover this, but rmSync never actually retried.

Root cause (from Node v24.16.0 src/node_file.cc, RmSync): rmSync is a native std::filesystem implementation.

  • The CI message says "Permission denied", which means the error was std::errc::permission_denied. That error is not in RmSync's retryable set, so the call fails on the first attempt.
  • Even for retryable errors, the Windows wait is Sleep(i * retryDelay / 1000). With retryDelay: 100 that truncates to about 2 ms total.

Both issues are fixed upstream in nodejs/node#64698, which is not in the Node version pinned in .node-version (24.16.0). fs/promises rm still uses the JS rimraf. That path retries EPERM with setTimeout(i * retryDelay), about 5.5 s in total.

What Changed

  • ForkSource.opencode.test.ts: afterEach now returns rm from node:fs/promises (same options) instead of calling rmSync. The comment explains why only the async path retries.
  • cliBinaryLocator.test.ts: the same one-line change. It has the same guard for the same reason (a copied executable on Windows) and the same ineffective rmSync retries.

Why This Approach

The fix removes the cause: the retry options never took effect. Async rm with the same options is already the cleanup used by the DeepSeek and WSL native suites. It also yields to the event loop between attempts instead of blocking the worker.

Alternatives considered:

  • Raising the rmSync numbers does nothing, because the error is never retried.
  • Replacing the copied node.exe with a hardlink or symlink could not be verified without Windows. Hardlinking the running Node image may make deletion fail outright, and symlinks depend on runner privileges. The copy also keeps the test exercising a real sibling runtime.

Validation

  • npm run typecheck, npm run lint: pass.
  • npm run test:unit on both files, 5 consecutive runs on macOS: 17/17 each time. On macOS this only shows the change causes no regression.
  • npm run test:affected -- --base origin/main: 2 files, 17 tests passed.
  • The Windows failure cannot be reproduced locally. Both suites are native and run in this PR's "Cross-platform tests (windows-latest)" job, which I will check passes (and rerun once). The original flake rate is unknown, so green runs are supporting evidence, not proof.

Impact and Follow-ups

Test-only; no production code changes. Once .node-version moves to a Node release that includes nodejs/node#64698, sync rmSync retries would work again, but the async form stays correct either way.

Checklist

  • This pull request addresses one focused problem, and I have explained why this change is necessary.
  • I linked the relevant issue, or explained why no issue is needed. (No issue; the failing CI run is linked.)
  • I added or updated tests for behavior changes, or explained why tests are not applicable. (Test-only change.)
  • I ran the relevant typecheck, lint, test, and build commands. (Build/performance not run: test-only change.)
  • I updated user-facing documentation when needed. (Not needed.)

Node 24's native rmSync does not retry std::errc::permission_denied and
truncates the Windows retry sleep to ~0ms (fixed upstream in
nodejs/node#64698), so maxRetries/retryDelay never covered the briefly
locked copied node.exe. Async rm retries EPERM with real backoff.
@YishenTu
YishenTu merged commit e341af5 into main Nov 12, 2026
51 checks passed
@YishenTu
YishenTu deleted the test/deflake-opencode-fork-cleanup branch November 12, 2026 07:21
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.

1 participant