Repository navigation
fix(worktrees): finish a delete Git left half-done on macOS and Linux - #33209
Conversation
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review.
|
There was a problem hiding this comment.
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:
cb55913f-e2ab-454e-8b53-99e1d678320a
Files selected for processing: 6-
src/main/ipc/worktrees/removal/remove-registered-local-worktree.tssrc/main/local-worktree-removal-recovery-live.test.tssrc/main/local-worktree-removal-recovery.test.tssrc/main/local-worktree-removal-recovery.tssrc/main/runtime/runtime-failed-local-worktree-removal.test.tssrc/main/runtime/runtime-registered-local-worktree-removal.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
-
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

Major · Keep the orphan-directory gate ahead of… · local-worktree-removal-recovery.ts:130-141
src/main/local-worktree-removal-recovery.ts:130-141
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick winKeep the orphan-directory gate ahead of partial-removal recovery.
With the platform gate removed,
isRecoverablePartialRemovalFailureaccepts an orphan error whenever Git no longer lists the worktree. The orphan path refuses recursive deletion unlesscanSafelyRemoveOrphanedWorktreeDirectoryproves the directory is safe to remove. Recovery never runs that check, so an unproven directory can be deleted recursively.Recovery runs before
isOrphanedWorktreeErrorin both the IPC and runtime catch blocks. Once an error matches/is not a working tree/and the row is absent, the recovery predicate returns true. Recovery then callsremoveLocalWorktreePathon the canonical path. This skips the proof gate thatcleanupLocalOrphanedWorktreeDirectoryapplies first. That function deletes only whencanSafelyRemoveOrphanedWorktreeDirectoryreturns true. Otherwise it logs "Refusing recursive cleanup for unproven worktree directory" and throwsORPHANED_WORKTREE_DIRECTORY_MESSAGEwhile the directory remains.The trigger needs the Git row to disappear between Orca's registered-worktree lookup and the
removeWorktreecall. Such a race is feasible, for example through a concurrentgit worktree pruneor another process. The consequence is an irreversible recursive delete of a directory that the orphan path would keep. Fix the predicate so orphan errors return to the existing fallback. This restores the pre-change orphan behavior on macOS and Linux and leaves recovery for its intended filesystem-failure case.Suggested fix
import { removeLocalWorktreePath } from './local-worktree-filesystem' +import { isOrphanedWorktreeError } from './ipc/worktree-logic'async function isRecoverablePartialRemovalFailure( args: LocalPartialRemovalRecoveryArgs ): Promise<boolean> { - if (typeof args.error !== 'object' || args.error === null) { + if (typeof args.error !== 'object' || args.error === null || isOrphanedWorktreeError(args.error)) { return false }

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:
e8d23018-6df3-4b3d-bacb-480505229c88
Files selected for processing: 2-
src/main/local-worktree-removal-recovery.test.tssrc/main/local-worktree-removal-recovery.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
-
git worktree remove drops the registration even when its recursive delete fails partway, on every OS. The in-operation recovery that finishes that delete was gated to win32, so on macOS and Linux the leftover folder was recorded as failed and every retry was refused. Run the recovery on all platforms with its existing gates (Git lock, strict listing without the path, watchers closed first). Later retries and the startup finish still never delete an unregistered folder. Fixes stablyai#33023
…must stay listed Git-deregistered partial deletes are now finished by Orca on every OS, so the mocked IPC and runtime leftover tests make that follow-up delete fail too. Co-authored-by: Anmol Bhardwaj <anmolbhardwajinv@gmail.com>
Skip the repo-wide git worktree prune (Git already dropped the row; prune can unregister checkouts on unmounted drives) and verify the row is gone instead. Delete the branch with the normal -d policy rather than always preserving it, so merged branches go and unmerged ones are kept.
…-delete test on macOS Co-authored-by: Anmol Bhardwaj <anmolbhardwajinv@gmail.com>
… in partial-delete tests Co-authored-by: Anmol Bhardwaj <anmolbhardwajinv@gmail.com>
… race test Windows-only The recovery swallowed the nested-worktree guard into 'not recoverable', so users saw Git's 'Directory not empty' instead of the nested-worktree message. The live churn race flaked on macOS when Git won the race; real-Git darwin runtime tests already cover it.
…heck in partial-delete recovery The predicate already proved Git dropped the row; re-listing after the rm only turned a listing failure into a misleading stale-registration error after the folder was gone. The force argument is now always true for the remaining stale-registration caller.
4fe75ae to
9bc8e48
Compare
|
Thanks @anmol0b! I rebased this onto the latest main cleanly. No fixups were needed. This will merge once CI is green. |
ELI5
When deleting a workspace on macOS or Linux, Git sometimes fails partway: it forgets the workspace but leaves its folder on disk. Orca then refused every later Delete and told you to remove the folder yourself. Now Orca finishes the delete right away, as it already did on Windows.
What Changed
git worktree removedeletes the checkout and then, even when that fails, still removes.git/worktrees/<id>, on every OS. Both local delete paths (desktopfinishLocalWorktreeRemovaland runtimefinishRuntimeLocalWorktreeRemoval) then call the partial-removal recovery. That recovery returned early off Windows because of aprocess.platform !== 'win32'check inisRecoverableWindowsFilesystemRemovalFailure. The delete was recorded as failed, and #25075's rule then refused every retry with "… is no longer a Git worktree, so its folder was left on disk."This removes the platform check and renames the function to
recoverPartialLocalWorktreeRemoval. Its existing safeguards are unchanged: a Git lock still blocks it, a strict worktree listing must no longer contain the path, file watchers are closed first, andremoveLocalWorktreePathstill handles WSL. It runs only inside the same delete call, right after Git deregistered a checkout Orca had just listed. That is the one place #25075 still lets Orca delete files.Behaving the same as before: retrying a failed row and the delete that resumes at startup still never delete an unregistered folder. If Orca's own follow-up delete also fails, the row stays listed and the branch is handled as #25075 defines. In that case the error is now Node's, naming the exact file, as on Windows.
Why
rm -rf <path>to the refusal (Expected 3): skipped. It's wrong on Windows, and the row already goes away once the folder is gone.Linked Issue
Fixes #33023
Visual Proof
N/A. This changes delete behaviour in the main process, with no UI change. Before: on macOS, the real-Git runtime tests show the leftover recorded with Git's
Operation not permittedand Orca never trying to finish the delete. After: Orca's own follow-up delete runs, which theEPERM: operation not permitted, unlinkerror proves.Testing
First I reproduced the bug on
upstream/mainon macOS (git 2.54). The live-Git test that races a file writer againstgit worktree removeis Windows-only, so I ran it on macOS with the gate removed. It fails: Git exits non-zero, deregisters the worktree and leaves the folder, and the recovery returnsundefined. That test stays Windows-only in this PR.runtime-failed-local-worktree-removal.test.ts(darwin, real Git, immutable file), the startup-finish and runtime-delete tests now assertEPERM: operation not permitted, unlink. Only Orca's follow-up delete produces that error, so they prove the recovery ran on macOS. The row stays listed and retries are still refused.Tested on macOS only. Not tested on Windows (no change in behaviour there), Linux or SSH (not on this path).
AI Disclosure
Review
Agent skill upstream boundary
Notes
Security: Orca deletes files only within the same delete call, after Git deregistered the checkout; later retries and the startup finish still never delete an unregistered folder. Cross-platform: Windows behaviour is unchanged; macOS and Linux now get the same recovery. Remote SSH: not on this path. Mobile: same runtime path, no client change. Backwards compatibility: no persisted data or client–host protocol changes. Performance: no new work on successful deletes.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)