Repository navigation
test(windows): give the Windows lane's teardowns the repo's rm retry policy - #17227
brennanb2025 wants to merge 3 commits into
Conversation
Greptile SummaryThe PR centralizes transient-lock deletion options and updates Windows-lane teardown paths to use retrying removal helpers.
Confidence Score: 5/5The PR appears safe to merge because no blocking failure remains. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| src/shared/windows-transient-lock-removal.ts | Defines the shared Windows retry policy and synchronous/asynchronous removal helpers. |
| src/shared/windows-transient-lock-removal.test.ts | Verifies platform-specific options and prevents duplicate retry-policy declarations. |
| src/shared/windows-lane-tree-removal-boundary.test.ts | Scans workflow-selected Windows specs for raw recursive removals. |
| src/main/host-tree-removal.ts | Reuses the centralized removal options while preserving the existing outer retry behavior. |
| src/main/codex-accounts/service.ts | Imports the centralized retry constants while retaining unconditional retries for host-driven managed-home deletion. |
Reviews (5): Last reviewed commit: "test(windows): put the policy ratchet on..." | Re-trigger Greptile
📝 WalkthroughWalkthroughThe change adds shared synchronous and asynchronous tree-removal helpers with Windows retry options. Production code uses the shared retry configuration. Test suites use the helpers for temporary-directory cleanup. Existing direct file removal remains unchanged where needed. New tests verify platform-specific options, enforce a single retry-policy declaration, and scan the Windows CI lane to reject raw recursive tree removal. Merge Risk: 🟡 Moderate · up to The PR centralizes Windows cleanup retries and adds a guard against regressions, but the guard is not run by the Windows-specific test command and does not recognize all recursive removal call forms. Future Windows cleanup flakes could therefore pass CI unnoticed, so merge should wait for these gaps to be corrected. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description gives a detailed explanation of the failure, implementation, scope, and validation. However, it does not include the required Linked Issue entry, and it omits several template sections such as Visual Proof, AI Disclosure, Review, Notes, and the Checklist. Resolution Add the missing required template sections. Include a real issue reference after "Fixes #"; write "N/A" with a reason under Visual Proof; document AI usage or leave the section according to repository policy; complete Review, Agent skill upstream boundary, Notes, and Checklist items. Keep the existing technical explanation and testing evidence.
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 96b9898a-08d7-4ad4-b4be-c822a1265188
📒 Files selected for processing (12)
config/scripts/rebuild-native-deps.test.mjssrc/main/agent-hooks/windows-hook-payload-delivery.test.tssrc/main/cli/wsl-cli-powershell-boundary.test.tssrc/main/cursor/hook-service.test.tssrc/main/orca-profiles/profile-index-store.test.tssrc/main/runtime/repo-worktree-admin-fingerprint.test.tssrc/main/windows/windows-host-job.win32.test.tssrc/shared/child-process/windows-command-line.win32.test.tssrc/shared/secure-file-fsync-flags.test.tssrc/shared/windows-lane-tree-removal-boundary.test.tssrc/shared/windows-transient-lock-removal.test.tssrc/shared/windows-transient-lock-removal.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.
| /** Every recursive removal that does not go through the retrying helper. */ | ||
| function findRawRecursiveRemovals(source: string): number[] { | ||
| const offenders: number[] = [] | ||
| const call = /(?<![\w$.])(?:fs\.)?rm(?:Sync)?\(/g |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- applicable repository knowledge files ---'
find /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4 -maxdepth 2 -type f -name '*.md' -print
printf '%s\n' '--- knowledge headers ---'
for f in /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/*/*.md; do
[ -f "$f" ] && { printf '\n### %s\n' "$f"; head -80 "$f"; }
done
printf '%s\n' '--- target outline ---'
ast-grep outline src/shared/windows-lane-tree-removal-boundary.test.ts
printf '%s\n' '--- target source ---'
cat -n src/shared/windows-lane-tree-removal-boundary.test.ts
printf '%s\n' '--- direct references ---'
rg -n -C 3 'findRawRecursiveRemovals|windows-lane|fs\.promises\.rm|rmSync|recursive:\s*true' src package.json .github 2>/dev/null || trueRepository: stablyai/orca
Length of output: 50370
🏁 Script executed:
#!/bin/bash
set -e
log=/tmp/coderabbit-shell-logs/shell-output-ojcnNd
printf '%s\n' '--- target/scanner excerpts from prior output ---'
rg -n -C 8 'windows-lane-tree-removal-boundary|findRawRecursiveRemovals|Detect|fs\.promises\.rm' "$log" | head -240 || true
printf '%s\n' '--- target file ---'
cat -n src/shared/windows-lane-tree-removal-boundary.test.ts
printf '%s\n' '--- scoped knowledge filenames ---'
find /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4 -maxdepth 2 -type f -name '*.md' -print | sort
printf '%s\n' '--- knowledge entries mentioning removal or Windows ---'
rg -l -i 'remov|windows|lane' /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/*/*.md 2>/dev/null | while read -r f; do
printf '\n### %s\n' "$f"
head -120 "$f"
doneRepository: stablyai/orca
Length of output: 47233
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- src conventions ---'
cat /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/conventions/src.md
printf '%s\n' '--- repo-wide conventions ---'
cat /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/conventions/repo-wide.md
printf '%s\n' '--- removal API forms ---'
rg -n -C 2 'fs\.promises\.rm|fs\.rm(?:Sync)?|from .node:fs/promises.|import .*fs.* from .node:fs.|import \* as fs' src tests config .github 2>/dev/null | head -300Repository: stablyai/orca
Length of output: 23886
🌐 Web query:
Node.js fs.promises.rm recursive force maxRetries API documentation
💡 Result:
The fsPromises.rm(path[, options]) API, introduced in Node.js v14.14.0, is designed to remove files and directories, modeling the standard POSIX rm utility [1][2][3]. The following options are relevant to your query: force: When set to true, exceptions are ignored if the path does not exist. The default value is false [1][4]. recursive: When set to true, the operation performs a recursive directory removal. In this mode, operations are retried on failure. The default value is false [1][4]. maxRetries: This option specifies the number of retries the operation will attempt if it encounters an EBUSY, EMFILE, ENFILE, ENOTEMPTY, or EPERM error [1][4]. The default is 0 [1][4]. If an error occurs, Node.js retries the operation with a linear backoff, waiting for an amount of time determined by the retryDelay option [1][4]. This option is ignored if recursive is not set to true [1][4]. retryDelay: This option sets the amount of time in milliseconds to wait between retries. The default is 100 milliseconds [1][4]. Like maxRetries, this option is ignored if the recursive option is not true [1][4]. To achieve behavior similar to the Unix rm -rf command, it is recommended to use fsPromises.rm(path, { recursive: true, force: true }) [1][4]. The method returns a promise that fulfills with undefined upon success [1][4].
Citations:
- 1: https://nodejs.org/api/fs.html
- 2: https://nodejs.org/docs/latest-v26.x/api/fs.html
- 3: https://nodejs.org/docs/latest-v23.x/api/fs.html
- 4: https://github.com/nodejs/node/blob/master/doc/api/fs.md
Detect fs.promises.rm calls.
fs.promises.rm(path, { recursive: true }) is a valid recursive removal API, but the matcher skips it because rm is preceded by a dot. Extend the matcher or use an AST-based scan, and add this exact form to the scanner self-test.
96b7790 to
1258809
Compare
…policy
`config/scripts/rebuild-native-deps.test.mjs` fails on `package (windows)` with
EPERM from the `finally` of "rebuilds a loadable ConPTY native that lacks Orca
job ownership". Every assertion in that test had already passed; the throw is
the cleanup. The test's whole job is to build and load a ConPTY native, and on
Windows a freshly dlopen'd DLL keeps a handle on the directory it came from for
a moment after the child exits — so `rmSync(projectDir, { recursive: true,
force: true })`, which is `maxRetries: 0`, loses the race.
The repo already knows this: `WINDOWS_RM_MAX_RETRIES = 8` in
`src/main/host-tree-removal.ts` and again in `codex-accounts/service.ts`. Only
product code was using it.
Adds `src/shared/windows-transient-lock-removal.ts` as one home for the policy
and moves all 21 raw recursive removals in the Windows CI lane onto it, plus a
boundary test that reads the lane's spec list out of `.github/workflows/pr.yml`
so a new spec cannot hand-roll the removal and reintroduce this.
Census, since the pattern is not confined to that lane: 1,633 recursive
removals across 1,028 files pass no `maxRetries` — 1,368 in tests and fixtures,
265 in product code. Only the Windows lane's 21 are changed here.
…d past `fs.` Two review findings on this PR. The policy was about to be stated three times. `host-tree-removal.ts` and `codex-accounts/service.ts` already each declared `WINDOWS_RM_MAX_RETRIES = 8`, and this PR's `transientLockRemovalOptions` made a third — in a change whose whole point is "one retry policy". Both existing sites now import it, and a ratchet in the module's own spec fails on a fourth declaration. `removeManagedHomeTreeSync` keeps its unconditional shape deliberately: it removes WSL-hosted managed homes from this process, so its retries are not gated on the host being Windows the way `transientLockRemovalOptions()` is. The lane guard's matcher only understood a bare `rm(` or a literal `fs.` prefix, so `fsp.rm`, `fsPromises.rm` and `nodeFs.rmSync` — all spellings this repo already uses — walked past it, and the guard would have gone on reporting zero offenders. It now accepts any namespace prefix and reads renamed bindings out of the import clause, with a planted spelling of each form as the proof.
`src/shared/source-scan` exists because four guards had each grown their own `collectSourceFiles` and drifted — one of them scanned the cross-version e2e checkouts and reported 21 offenders that were copies of shipped releases. This ratchet had just become the fifth. It now uses `scanSourceTree`, which also gets it dot-directory skipping and `/`-normalised paths on Windows for free, and `stripComments` so a commented-out declaration is not an offender.
1258809 to
4547469
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 9875b691-fec6-4a0b-b43b-bdffc70573a6
📒 Files selected for processing (14)
config/scripts/rebuild-native-deps.test.mjssrc/main/agent-hooks/windows-hook-payload-delivery.test.tssrc/main/cli/wsl-cli-powershell-boundary.test.tssrc/main/codex-accounts/service.tssrc/main/cursor/hook-service.test.tssrc/main/host-tree-removal.tssrc/main/orca-profiles/profile-index-store.test.tssrc/main/runtime/repo-worktree-admin-fingerprint.test.tssrc/main/windows/windows-host-job.win32.test.tssrc/shared/child-process/windows-command-line.win32.test.tssrc/shared/secure-file-fsync-flags.test.tssrc/shared/windows-lane-tree-removal-boundary.test.tssrc/shared/windows-transient-lock-removal.test.tssrc/shared/windows-transient-lock-removal.ts
🚧 Files skipped from review as they are similar to previous changes (11)
- src/main/orca-profiles/profile-index-store.test.ts
- src/main/runtime/repo-worktree-admin-fingerprint.test.ts
- src/shared/windows-transient-lock-removal.ts
- src/shared/child-process/windows-command-line.win32.test.ts
- src/main/agent-hooks/windows-hook-payload-delivery.test.ts
- src/main/host-tree-removal.ts
- src/shared/windows-transient-lock-removal.test.ts
- config/scripts/rebuild-native-deps.test.mjs
- src/shared/secure-file-fsync-flags.test.ts
- src/main/codex-accounts/service.ts
- src/main/cursor/hook-service.test.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.
| 'g' | ||
| ) | ||
| let match: RegExpExecArray | null | ||
| while ((match = call.exec(source)) !== null) { |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
🔎 Supported by static analysis
🏁 Script executed:
#!/bin/bash
set -euo pipefail
target='src/shared/windows-lane-tree-removal-boundary.test.ts'
python - <<'PY'
from pathlib import Path
import re
workflow = Path('.github/workflows/pr.yml').read_text()
target = 'src/shared/windows-lane-tree-removal-boundary.test.ts'
start = workflow.find('- name: Test Windows-specific boundaries')
end = workflow.find('\n - name:', start + 1)
step = workflow[start:] if end == -1 else workflow[start:end]
print(f'listed_in_windows_step={target in step}')
source = Path(target).read_text()
call = re.compile(r'(?<![\w$.])(?:[\w$]+\.)?(?:rmSync|rm)\s*\(')
offenders = []
for match in call.finditer(source):
depth = 0
end = match.start() + len(match.group()) - 1
while end < len(source):
if source[end] == '(':
depth += 1
elif source[end] == ')':
depth -= 1
if depth == 0:
break
end += 1
args = source[match.start():end + 1]
if 'recursive' in args and 'maxRetries' not in args:
offenders.append(source[:match.start()].count('\n') + 1)
print(f'self_scan_offenders={offenders}')
PYRepository: stablyai/orca
Length of output: 209
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '%s\n' '--- repository conventions ---'
find /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4 -path '*/learnings/*.md' -o -path '*/architecture/*.md' -o -path '*/conventions/*.md' | sort | while read -r f; do
echo "--- $f"
head -80 "$f"
done
printf '%s\n' '--- workflow boundary step ---'
rg -n -A35 -B8 'Test Windows-specific boundaries|windows-lane-tree-removal-boundary|boundary' .github/workflows/pr.yml
printf '%s\n' '--- test file relevant sections ---'
cat -n src/shared/windows-lane-tree-removal-boundary.test.ts | sed -n '1,130p'
printf '%s\n' '--- scanner definitions and callers ---'
rg -n -A35 -B8 'findRawRecursiveRemovals|windows-lane-tree-removal-boundary|spec list|Windows-specific' src .githubRepository: stablyai/orca
Length of output: 50369
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '%s\n' '--- complete Windows boundary command ---'
sed -n '688,735p' .github/workflows/pr.yml
printf '%s\n' '--- boundary test ---'
cat -n src/shared/windows-lane-tree-removal-boundary.test.ts
printf '%s\n' '--- source-tree scanner ---'
rg -n -A45 -B12 'findRawRecursiveRemovals|recursive.*rm|source-tree-scan|windows-lane-tree-removal' src/shared .githubRepository: stablyai/orca
Length of output: 50369
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '%s\n' '--- references to the boundary test ---'
rg -n 'windows-lane-tree-removal-boundary|windows lane tree removal' .github package.json config src --glob '!src/shared/windows-lane-tree-removal-boundary.test.ts'
printf '%s\n' '--- workflow test commands near unit-test steps ---'
rg -n -A12 -B8 'vitest run|pnpm test|Test .*unit|Unit test' .github/workflows/pr.yml
printf '%s\n' '--- exact matcher-like calls in Windows-listed source files ---'
python3 - <<'PY'
from pathlib import Path
import re
workflow = Path('.github/workflows/pr.yml').read_text()
start = workflow.index('- name: Test Windows-specific boundaries')
end = workflow.index('\n - name:', start + 1)
specs = [
line.strip() for line in workflow[start:end].splitlines()
if re.fullmatch(r'(?:src|tests|config)/.+\.(?:test|spec)\.(?:ts|tsx|mjs)', line.strip())
]
call = re.compile(r'(?<![\w$.])(?:[\w$]+\.)?(?:rmSync|rm)\s*\(')
for spec in specs:
source = Path(spec).read_text()
hits = []
for m in call.finditer(source):
# Match the reviewed function's parenthesis scan closely enough to identify
# comments/string hits and real calls without executing repository code.
depth = 0
endpos = m.start() + len(m.group()) - 1
while endpos < len(source):
if source[endpos] == '(':
depth += 1
elif source[endpos] == ')':
depth -= 1
if depth == 0:
break
endpos += 1
args = source[m.start():endpos + 1]
if 'recursive' in args and 'maxRetries' not in args:
hits.append(source.count('\n', 0, m.start()) + 1)
if hits:
print(f'{spec}: {hits}')
PYRepository: stablyai/orca
Length of output: 191
🏁 Script executed:
#!/bin/bash
set -u
printf '%s\n' '--- workflow test commands near unit-test steps ---'
rg -n -A12 -B8 'vitest run|pnpm test|Test .*unit|Unit test' .github/workflows/pr.yml || true
printf '%s\n' '--- exact matcher-like calls in Windows-listed source files ---'
python3 - <<'PY'
from pathlib import Path
import re
workflow = Path('.github/workflows/pr.yml').read_text()
start = workflow.index('- name: Test Windows-specific boundaries')
end = workflow.index('\n - name:', start + 1)
specs = [
line.strip() for line in workflow[start:end].splitlines()
if re.fullmatch(r'(?:src|tests|config)/.+\.(?:test|spec)\.(?:ts|tsx|mjs)', line.strip())
]
call = re.compile(r'(?<![\w$.])(?:[\w$]+\.)?(?:rmSync|rm)\s*\(')
for spec in specs:
source = Path(spec).read_text()
hits = []
for m in call.finditer(source):
depth = 0
endpos = m.start() + len(m.group()) - 1
while endpos < len(source):
if source[endpos] == '(':
depth += 1
elif source[endpos] == ')':
depth -= 1
if depth == 0:
break
endpos += 1
args = source[m.start():endpos + 1]
if 'recursive' in args and 'maxRetries' not in args:
hits.append(source.count('\n', 0, m.start()) + 1)
if hits:
print(f'{spec}: {hits}')
PYRepository: stablyai/orca
Length of output: 7644
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '%s\n' '--- package test scripts ---'
node - <<'JS'
const pkg = require('./package.json')
for (const [name, value] of Object.entries(pkg.scripts ?? {})) {
if (/test|vitest/i.test(name) || /test|vitest/i.test(value)) {
console.log(`${name}: ${value}`)
}
}
JS
printf '%s\n' '--- main test-job definitions ---'
rg -n -A28 -B10 '^[[:space:]]{2}[A-Za-z0-9_-]+:|name:.*test|vitest|pnpm run test|pnpm test' .github/workflows/pr.yml | sed -n '1,260p'Repository: stablyai/orca
Length of output: 18066
🏁 Script executed:
#!/bin/bash
set -euo pipefail
rg -n -A35 -B12 '^[[:space:]]{2}test:|name:.*test|run:.*pnpm (run )?test|vitest run --config config/vitest.config.ts$' .github/workflows/pr.ymlRepository: stablyai/orca
Length of output: 10223
Add the boundary test to the Windows test command.
The package-wide test runs it, but the Windows-specific command omits it. Add src/shared/windows-lane-tree-removal-boundary.test.ts to that command. If added, prevent the raw matcher from scanning its comments and fixture strings.
🧰 Tools
🪛 OpenGrep (1.26.0)
[ERROR] 70-70: Dynamic command passed to child_process.exec/execSync. Use child_process.execFile or spawn with an argument array instead.
(coderabbit.command-injection.exec-js)
|
Superseded by #17780, which lands the same Windows-lane |
|
Closing as superseded by #17780. |
ELI5
When a test finishes it deletes the temporary folder it was working in. On Windows the folder is often still "in use" for a fraction of a second after the test is done — an antivirus scan, the search indexer, a child process that just exited, or a native
.dllthe OS has not finished unloading. Delete it right then and Windows says operation not permitted.Node has a built-in answer: ask it to retry the delete a few times. Orca's product code already does this and already picked the number — 8. Its tests did not, so a test whose checks had all passed was reported as a failure because tidying up lost a race.
This teaches the Windows CI lane to tidy up the way the rest of the codebase already does.
What the user sees
Nothing at runtime — the product paths already retried. What changes is that
package (windows)stops reporting passing tests as failures.EPERM: operation not permittedfrom thefinally, after every assertion passedrmSync(dir, { recursive: true, force: true })and reintroduce the flakeThe failure
package (windows),config/scripts/rebuild-native-deps.test.mjs, testrebuilds a loadable ConPTY native that lacks Orca job ownership(win32-only).The last assertion is line 238 and it passed. The throw comes from line 240:
That test exists to rebuild node-pty and load the ConPTY native — the same job log carries
node-pty's conpty native is missing listJobProcessIds … Resolved from: ../prebuilds/win32-x64/, so a realdlopenis live in the run. A DLL Windows has just mapped keeps a handle on the directory it came from, andmaxRetries: 0gives that handle no time to go away.The convention it was ignoring
Two copies, both in product code, neither reachable from a test.
The fix
src/shared/windows-transient-lock-removal.ts— one home for the policy, exposingremoveTree/removeTreeSyncand the options behind them. Retries are win32-only; POSIX gets the plain options it had.src/shared/windows-lane-tree-removal-boundary.test.tsreads the lane's spec list out of theTest Windows-specific boundariesstep in.github/workflows/pr.yml— so the gate follows the lane rather than a hand-kept copy of it — and fails on any recursive removal that carries nomaxRetries.Census
The task asked how many other teardowns ignore the convention. Across
src,testsandconfig:1,633 recursive directory removals in 1,028 files pass no
maxRetries— 1,368 in tests and fixtures, 265 in product code.This PR changes only the 21 in the Windows lane. The 265 product-code sites are the ones that matter beyond CI hygiene: a test leaking a temp directory is untidy, a product path that cannot delete a user's directory is a bug. That is a separate change, and worth deciding as a shape question (shared helper plus a lint rule that makes the raw call the exception) rather than as a sweep.
Proof
Ablations, one at a time, mutation verified applied, tree restored between runs, run serially. Suite:
windows-transient-lock-removal.test.ts+windows-lane-tree-removal-boundary.test.ts, 6 tests.rebuild-native-deps.test.mjsline 240 to the rawrmSynctransientLockRemovalOptions()The third ablation first came back 0 red — the boundary test passed because the scanner found nothing, which is indistinguishable from finding nothing wrong.
actually detects a raw recursive removalwas added to pin the detector against a synthetic source, and the scanner-blinding ablation then reds.Honest limit: the EPERM itself is a
win32-only teardown failure and I could not reproduce it on macOS —it.skipIf(process.platform !== 'win32')skips the convicted test here. What is proved failing-first is the gate: the boundary test reds on the exact line that threw in CI, and it runs on every platform. The EPERM itself is settled by CI onpackage (windows).Local gates:
pnpm tcexit 0, 0error TS(foreground).oxlinton all 12 changed files exit 0, including the native-plugin and type-aware code-quality configs. The 11 touched/affected test files: 9 passed, 2 skipped, 47 tests passed, 0 failed.