Skip to content

fix(windows): stop recursive deletes from retry-storming when a file is held open - #33722

Merged
brennanb2025 merged 7 commits into
mainfrom
OrcaWin/fix-windows-rm-retry-storm
Oct 26, 2026
Merged

brennanb2025 merged 7 commits into
mainfrom
OrcaWin/fix-windows-rm-retry-storm

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​249 $\color{#cf222e}{\Huge{\mathbf{−}}}$​56 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​193
Prod 14 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​112 $\color{#cf222e}{\Huge{\mathbf{−}}}$​65 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​47

Deleting a Windows workspace containing a live Edge or Chrome profile could multiply Node’s recursive-delete retries at every directory level. Orca could continue filesystem work after reporting failure, grow to gigabytes of memory and stop responding. This PR removes those per-entry retries and prevents a lost file-transaction lock from throwing out of its refresh timer.

What changes

  • Async recursive removal uses Node’s own rm with recursive: true, force: true, without maxRetries. Windows makes at most five whole-pass attempts, with 250/500/1000/2000 ms waits between attempts. Other platforms make one plain pass. This bounds attempts per helper invocation, not filesystem-call duration or all work in a user action. Node may finish already-started sibling removals after the helper reports failure. The embedded Windows host-state script retains its existing separate six-attempt/1500 ms budget.
  • removeHostTree preserves original-fs handling for .asar files and Windows long paths. It names the held file in plain words. Cancellation works between passes and during backoff; a running filesystem pass is not interrupted.
  • If Git has already unregistered a failed checkout, the stored failed-row tooltip now says manual folder cleanup may be needed after closing the program. Literal dollar characters in folder names stay intact. The generic request-error toast and other callers retain their existing advice.
  • A compromised file-transaction lock rejects the transaction with an uncertain-save message and avoids releasing a lock another process may own. It does not promise rollback of an already completed write. If the transaction itself fails, that error retains precedence even if the lock was also compromised.

The plain Node deletion follows the common pattern. The short whole-pass Windows retry is intentional for handles released late after Orca stops its terminals. Sync removal, existing deletion ownership checks, explicit WSL/SSH routing and saved/wire formats are unchanged.

Temporary recovery limitation

Closing the browser and choosing Delete again can still leave the folder and failed row. Windows QA reproduced this: Git registration and .git were gone, and the existing replacement-folder safety guard refused further recursive deletion. This PR’s new stored tooltip acknowledges that limitation; it does not fix or claim successful recovery. Metadata-last ordering and safe successful retry belong to the follow-up PR #34058. Brennan approved this staged delivery on 2026-10-26. The lane owner owns that separately planned work and its safety, review, performance and Windows acceptance checks. No saved path alone authorizes recursive deletion.

Validation

Full review path: retries, file deletion, cancellation and failure handling; the architecture plan and reference comparison retained Node’s walker. Five review rounds and bounded correction/readiness checks completed. Fresh CI passed on 7daa1fa56ee4f5d0520fb5eaf61e1c57a279648c, including static analysis/typecheck, all five Node 24 test shards and Windows packaging; the full PR check watcher exited 0 after the remaining platform checks passed.

  • Native Windows focused tests at e5a19507be4: 50 passed, 0 failed, 1 skipped across clipboard staging, failed-worktree storage/listing/reload and renderer failure display. The skip is POSIX owner/mode validation. A later test-comment-only commit documents the fake-clock adapter without changing test behavior.
  • Fresh UI-created workspace with a genuine live Edge profile: rendered Delete produced the held-file failure and exact persisted manual-cleanup tooltip. Whole-window screenshot.
  • Unchanged runtime evidence at cf400fac250 carries: held-file failure in 6.374 s; 180.52 s of responsive navigation/resource observation with 3.359 CPU seconds and private memory ending 2.6 MB lower; normal deletion with a real PowerShell terminal open succeeded in 3.142 s, removing the path and shells. These are bounded observations, not a long-term leak or controlled speedup claim.
  • Previous-build workspace/terminal IDs survived graceful quit and same-profile upgrade. A stale CDP-port collision required an extra branch launch, so continuity is qualified rather than a clean single-launch upgrade.
  • Real Windows Node 24.18 operation-count contract: 100/1000 nested branches, 2301/22101 operations, five whole passes at both sizes, pending sibling operations drained. The unchanged helper’s existing PASS carries and was not rerun for copy/tests.
  • Historical six-file Windows invocation was 79 passed, 4 failed, 1 skipped, exit 1. Its clipboard assertions are repaired and pass above; the unchanged mocked WSL-prune expectation and Windows-permission-blocked symlink fixture are not claimed green.
  • The original QA round and the focused copy-screenshot run stopped their own recorded processes. Latest screenshot run: 16 recorded identities, no owned survivors or admitted-port listeners; 40 readable config hashes unchanged, 19 paths still absent, 10 inaccessible inputs disclosed as unverified.

Main-process shutdown that permits a new instance beside an old hung process is outside this PR. Non-shipped scripts/test teardowns retaining async retry options are also outside its scope.

…is held open

Node's async recursive rm retries every nested entry separately and orphans
sibling walkers when it rejects, so deleting a workspace holding a live
browser profile multiplied filesystem work per directory level until the
main process hung. Delete Windows host trees with a walker that retries
whole passes from one shared budget and leaves nothing running on failure.

Also bound and log detached worktree removal, and fail a file transaction
whose proper-lockfile lock is compromised instead of throwing from its timer.
@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1b9696b9-2e7a-4215-9afb-2ce35cb1da40
Commits

Reviewing files that changed from the base of the PR and between e5a1950 and 7daa1fa.

Files selected for processing: 1
  • src/main/window/clipboard-remote-file-staging.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.

Walkthrough

Recursive cleanup now retries whole removal passes for selected transient errors. Staging, scratch-directory, and host-tree cleanup paths use the shared removal helper. Worktree removal passes abort signals through host-filesystem recovery. Selected deletion errors receive path-specific guidance. File transactions record lock compromise and reject after the action completes if the lock was compromised.

Priority: Normal

Merge Risk: Moderate · up to 7daa1

Lock-loss reporting and Windows cleanup retries still have material correctness risks that should be resolved before merging.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 40.54% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 37 functions across 29 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check Warning The description covers most required template sections. It has a clear ELI5-style summary of the problem, a detailed What changes section, a Why-style rationale (the staged delivery and the removal of… Add a linked issue number in the 'Linked Issue' section (for example 'Fixes #NNNN'). Provide a BEFORE and AFTER visual for the stored failed-row tooltip change, or state N/A with a reason. Add a short, explicit ELI5 paragraph under the ELI5…
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly describes the primary change: preventing recursive Windows deletion retries from multiplying when files remain open.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description covers most required template sections. It has a clear ELI5-style summary of the problem, a detailed What changes section, a Why-style rationale (the staged delivery and the removal of per-entry Node retries), a Validation section with CI and native Windows test evidence, and a Notes section that discusses cross-platform impact. Several template items are missing or incomplete. The 'Linked Issue' section still says 'Fixes #' with no issue number. The 'Visual Proof' section has a screenshot link, but the required BEFORE and AFTER pair is not clearly presented, and the UI-visible tooltip change has no before state. The 'Testing' checkboxes are not ticked. The 'AI Disclosure' section is empty. The 'Review' and 'Agent skill upstream boundary' sections are not filled in. The Checklist is not ticked. The 'ELI5' heading is not clearly separate from the opening paragraph. The description also has a large amount of run-level detail that does not help a reviewer.

Resolution

Add a linked issue number in the 'Linked Issue' section (for example 'Fixes #NNNN'). Provide a BEFORE and AFTER visual for the stored failed-row tooltip change, or state N/A with a reason. Add a short, explicit ELI5 paragraph under the ELI5 heading. Tick the Testing checkboxes that apply and state which platforms were tested. Complete the AI Disclosure section if an AI tool was used. Fill in the Review and Agent skill upstream boundary sections (check the box or state the applicable case). Tick the Checklist items that are satisfied, or note why they are not. Trim the run-level timing and screenshot-run details to the facts a reviewer needs to verify the change.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 38381112-68f5-4065-a18e-a4e4b5fb4efa
Commits

Reviewing files that changed from the base of the PR and between b23e456 and 200e297.

Files selected for processing: 21
  • src/main/asar-transparent-fs.ts
  • src/main/browser/browser-client-upload-staging.ts
  • src/main/codex/codex-hook-trust-derivation.ts
  • src/main/file-transaction-lock.test.ts
  • src/main/file-transaction-lock.ts
  • src/main/git/worktree-removal.ts
  • src/main/host-tree-removal.ts
  • src/main/ipc/worktrees/removal/remove-registered-local-worktree.ts
  • src/main/local-worktree-filesystem.test.ts
  • src/main/local-worktree-filesystem.ts
  • src/main/local-worktree-removal-recovery.ts
  • src/main/managed-server/host-state/orcad-windows-host-state-ops.ts
  • src/main/observability/instrumentation.ts
  • src/main/runtime/runtime-registered-local-worktree-removal.ts
  • src/main/window/owned-temp-staging-root.ts
  • src/main/worktree-background-removal.test.ts
  • src/main/worktree-background-removal.ts
  • src/main/worktree-removal-deadline.ts
  • src/shared/bounded-tree-removal.test.ts
  • src/shared/bounded-tree-removal.ts
  • src/shared/windows-transient-lock-removal.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

Comment thread src/main/file-transaction-lock.ts Resolved
Comment thread src/shared/bounded-tree-removal.test.ts Resolved
…om walker

Replace the hand-rolled tree walker with Node's own recursive rm and no
per-entry retries. Async rm gives each nested entry its own retry counter and
never stops siblings, which is what multiplied the work; with retries off each
pass is one bounded walk, and a transient Windows lock repeats the whole pass
from the existing 250/500/1000/2000 ms budget, checking the job's signal
between passes.

A failed delete now names the file another program holds open instead of
Node's EBUSY/EPERM text. Drop the 30-minute background deadline. The lost-lock
error no longer embeds the library's message and says the write may or may not
have been saved.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8200e74e-5d90-4dab-816a-25279da59b68
Commits

Reviewing files that changed from the base of the PR and between 200e297 and d7a5411.

Files selected for processing: 5
  • src/main/file-transaction-lock.ts
  • src/main/host-tree-removal.ts
  • src/main/local-worktree-filesystem.test.ts
  • src/shared/windows-path-access.ts
  • src/shared/windows-transient-lock-removal.ts
Files skipped from review as they are similar to previous changes: 1
  • src/main/file-transaction-lock.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

@brennanb2025

Copy link
Copy Markdown
Contributor

Windows workspace deletion could multiply Node’s retries at every directory level when another program held a file open. Orca could keep doing filesystem work after reporting failure, exhaust memory and stop responding.

This PR uses plain Node recursive deletion and at most five whole-folder attempts per shared Windows helper call. Failure names the held file. When Git already unregistered the incomplete checkout, the stored failed-row tooltip says manual folder cleanup may be needed after closing the program; generic request-error toast wording is unchanged. A lost file-transaction lock now rejects the transaction instead of throwing from its refresh timer. The whole-pass policy and original-fs handling are intentional differences from the common plain-delete pattern. No deadline or cancellation of an in-flight filesystem call is promised. Node may finish already-started sibling removals after the helper reports failure. If the transaction itself fails, its error remains primary even if lock ownership was also lost.

Temporary limitation: the observed close-and-retry attempt FAILED and remains open. Metadata-last ordering and successful safe retry belong to the follow-up PR in this lane (tracked in the lane, not yet opened), owned by the lane owner with separate planning, review, tests, Windows QA and performance acceptance. Brennan approved this staged delivery on 2026-10-26. This cut retains the existing replacement-folder safety guard and does not grant recursion from a saved path. No recovery finding is marked passed by removing its unshipped mechanism from this PR.

Five review rounds completed; final copy correction and test-comment verification were bounded continuations of round five. No open P0/P1 remains in this shipped cut. The final whole-PR source/reference/readiness audit and the real Windows operation contract were completed. Fresh CI passed on 7daa1fa56ee4f5d0520fb5eaf61e1c57a279648c: static analysis/typecheck, all five Node 24 shards and Windows packaging passed, as did the remaining platform checks; the complete PR check watcher exited 0.

Native Windows focused tests at e5a19507be47d3101267a6b97617235dc5c866ee: 50 passed / 0 failed / 1 POSIX-only skip. Fresh UI-created checkout, real Edge profile, rendered Delete, actual saved failure and tooltip matched; no successful retry is claimed. The later 7daa1fa56ee4f5d0520fb5eaf61e1c57a279648c commit adds only the fake-clock annotation and changes no expression/assertion/runtime flow.

The unchanged run-row deletion mechanics carry from cf400fac250d6640e11084436e6043293568cf87: initial held-file failure 6.374 s, responsive 180.52 s observation (3.359 CPU seconds; private memory ended 2.6 MB lower), normal real-terminal-open delete 3.142 s, and qualified previous-build continuity. Upgrade needed an extra branch launch after a CDP-port collision; it is not a clean single-launch upgrade. The existing real Node 24 Windows scaling PASS at 100/1000 branches counted 2301/22101 operations, five passes each and no pending operations; it was not rerun. These establish bounded observations and operation counts, not a universal wall-clock or long-term resource guarantee.

The old six-file Windows invocation remains 79 passed / 4 failed / 1 skipped, exit 1; current clipboard repairs pass above, while unchanged mocked WSL-prune/symlink-policy fixture failures are qualified, not called passing. Latest launch cleanup: 16 recorded identities, zero owned survivors/listeners; 40 readable real-config hashes unchanged, 19 absent, 10 inaccessible inputs unverified. Earlier audit checked 24 recorded process identities, with no owned survivors or used-port listeners. Ticket 2547 released; no test copy remains running.

For Brennan’s review:

@brennanb2025
brennanb2025 merged commit c2ceb52 into main Oct 26, 2026
67 checks passed
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.

2 participants