Skip to content

fix(worktrees): keep failed orphan cleanup retryable - #22409

Merged
nwparker merged 3 commits into
mainfrom
nwparker/external-21954-removal-retry
Sep 26, 2026
Merged

nwparker merged 3 commits into
mainfrom
nwparker/external-21954-removal-retry

Conversation

@nwparker

@nwparker nwparker commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​234 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​228
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​84 $\color{#cf222e}{\Huge{\mathbf{−}}}$​79 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​5

ELI5

A workspace stays in Orca when its folder could not safely be removed, so you can retry cleanup.

What Changed

Both runtime and desktop IPC removal reuse one cleanup helper that confirms that the execution-host path is absent before pruning registration and removing metadata. WSL uses a C-locale stat probe so permission failures cannot masquerade as absence.

Why

Reuse the existing directory proof and missing-path check. Silently forgetting a folder after a refused or failed removal loses the only retry handle. PTY-stop policy is unchanged.

Linked Issue

Related to #21954. Reported by @SiinXu. This covers orphan cleanup metadata ordering; broader leftover-process force cleanup and #22161 are not assessed.

Visual Proof

N/A — backend cleanup and filesystem error classification only; no renderer change. Disposable fixture and failure tests establish retained metadata and retry behavior.

Testing

1,381 focused filesystem, safety, desktop IPC and runtime tests pass; one skipped. Two new desktop regression cases fail before the shared absence gate and pass afterward, including a successful retry. Node typecheck and changed-code quality pass. Native execution was macOS only; WSL uses controlled tests, with no native Windows/Linux/WSL/live SSH claim.

  • Native end-to-end flow manually tested
  • Focused automated regression tests added and run with ORCA_BACKGROUND_LAUNCH=1

AI Disclosure

Review

Reviewed cleanup ordering, execution-host routing, failed stat/removal and watcher restoration. Addressed Pullfrog’s desktop-path finding by sharing the same cleanup and absence-proof function between desktop IPC and runtime removal. The existing stat-to-remove race is not redesigned.

Agent skill upstream boundary

  • Not applicable; no upstream skill source is copied.

Notes

No full application build, full lint, or full suite is claimed; CI covers broader validation.

Checklist

  • Small and focused
  • Before/after, mechanism and rationale explained
  • Visual proof attached or N/A explained
  • Reviewed for correctness, security and performance
  • Cross-platform, SSH/remote and compatibility impact considered
  • Required CI checks pass, including the verify aggregate

@coderabbitai

coderabbitai Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 360f8cfe-52c1-4ecb-946c-455a4645e98a

📥 Commits

Reviewing files that changed from the base of the PR and between 8757e40 and 2458c27.

📒 Files selected for processing (5)
  • src/main/local-worktree-filesystem.test.ts
  • src/main/local-worktree-filesystem.ts
  • src/main/runtime/orca-runtime-tests/worktree-removal-and-reconciliation-part-04.spec.ts
  • src/main/runtime/runtime-registered-local-worktree-removal.ts
  • src/main/worktree-removal-safety.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

The WSL filesystem probe now uses stat output to identify path types and distinguishes missing-path errors from other stat failures. Orphaned worktree cleanup now checks whether the directory is gone and reports an error when it remains. Tests cover WSL permission errors, orphan cleanup failures, metadata retention, and permission errors during path checks.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 2458c

No concrete issue blocks merging after normal checks. The change is intended to keep failed orphan cleanup retryable rather than discard its registration.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly identifies the main change: failed orphan cleanup remains retryable.
Description check ✅ Passed The description is complete and aligned with the template. It explains the user impact, implementation, rationale, linked issue, lack of visual changes, testing scope, review notes, and checklist stat…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

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.

@pullfrog pullfrog 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.

Important

The runtime removal path now keeps a failed orphan cleanup retryable, but the equivalent local-desktop removal path still drops the retry handle. The desktop renderer routes local deletes through window.api.worktrees.remove → removeRegisteredLocalWorktree, which was not updated, so the linked issue's local-desktop surface keeps the old behavior.

Reviewed changes

  • Runtime orphan cleanup is now retryable — cleanupOrphanedDirectory reports whether the path is gone, and removeRuntimeRegisteredLocalWorktree throws ORPHANED_WORKTREE_DIRECTORY_MESSAGE before git worktree prune, push-target cleanup, or metadata removal when it is not. The watcher gate's finish(false) still restores watchers.
  • WSL stat no longer conflates denial with absence — the shell [ -f/-d ] probe (which exited 2 for an unreadable path) is replaced by LC_ALL=C stat -c %F; only the stat No such file or directory / Not a directory stderr maps to ENOENT, and permission failures propagate. %F kinds are mapped back to symlink/file/directory, else other.
  • Coverage — WSL permission-vs-missing classification, isWorktreePathMissing on EACCES, and both runtime retention paths (unproven directory, and a proven directory whose removal fails) plus a retry.

⚠️ The local desktop removal path still drops the retry handle

removeRegisteredLocalWorktree (src/main/ipc/worktrees/removal/remove-registered-local-worktree.ts:159) mirrors the pre-fix runtime logic: after an orphan cleanup that can silently leave the directory in place, it calls git worktree prune, removeWorktreeMetadataAndTransientState and returns success. Since dispatch-worktree-removal.ts:34 sends local deletes over window.api.worktrees.remove, this is the transport the UI uses, so a failed local orphan cleanup still removes the row and the retry handle. The linked report is a macOS local-desktop one, and the renderer already knows how to offer force-delete on ORPHANED_WORKTREE_DIRECTORY_MESSAGE (store-worktree-removal-cascade.test.ts:623), which this path never throws.

Technical details
# Apply the same missing-path gate to the desktop local-removal path

## Affected sites
- `src/main/ipc/worktrees/removal/remove-registered-local-worktree.ts:159-211` — orphan branch prunes registration and removes metadata unconditionally after `removeLocalWorktreePath(...).catch(() => {})`.
- `src/main/runtime/runtime-registered-local-worktree-removal.ts:164-223` — the fixed twin, for reference.

## Required outcome
- The desktop path should throw `ORPHANED_WORKTREE_DIRECTORY_MESSAGE` and leave metadata (and Git registration) intact whenever the orphan directory is not absent after the cleanup attempt, matching the runtime path.

## Suggested approach (optional)
- `cleanupOrphanedDirectory` already exists in the runtime module; consider lifting the shared "cleanup, then prove absence" helper so both entry points use one implementation instead of a third copy.

## Open questions for the human
- Is the local desktop path intentionally out of scope here (e.g. the local case is blocked earlier by PTY proof), or should this land too / in a follow-up?

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@nwparker

Copy link
Copy Markdown
Contributor Author

Addressed the desktop IPC path in 8d3d89f. Runtime and desktop removal now share cleanupLocalOrphanedWorktreeDirectory, which proves execution-host path absence before either caller prunes registration or removes metadata. Two desktop regressions fail before the fix and pass after; they cover refused proof, failed recursive removal, watcher restoration, retained metadata and successful retry. The combined 1,381 focused tests (one skipped), Node typecheck and changed-code quality pass.

@nwparker

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • Extracted one shared orphan-cleanup helper — cleanupLocalOrphanedWorktreeDirectory now owns the "prove it is a safe orphan, delete if proven, then throw ORPHANED_WORKTREE_DIRECTORY_MESSAGE if the path still exists" sequence.
  • Fixed the desktop registered-removal path — removeRegisteredLocalWorktree routes its orphan branch through that helper, so a failed cleanup now throws before git worktree prune, push-target cleanup, and metadata removal, and the watcher gate restores watchers via finish(false). The renderer already maps this message to the orphan-directory force reason (src/shared/worktree/removal.ts:136).
  • Removed the runtime path's private copy — runtime-registered-local-worktree-removal.ts now calls the same helper, keeping the two entry points in lockstep.
  • Added desktop regression coverage — a new it.each covers both the unproven-directory and removal-failure retention cases plus a successful retry; verified these two cases fail if the helper's throw is removed.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

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