Skip to content

Recover partially deleted local worktrees - #6657

Merged
OrcaWin merged 1 commit into
stablyai:mainfrom
brennanb2025:brennanb2025/scorpionfish
Jun 29, 2026
Merged

OrcaWin merged 1 commit into
stablyai:mainfrom
brennanb2025:brennanb2025/scorpionfish

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

Summary

Handles the local partial-delete recovery case where Git no longer registers a worktree and the worktree .git marker is gone, but the directory still exists on disk. Orca now prompts before force cleanup for Orca-owned leftover directories, then removes the leftover directory and metadata without invoking Git worktree removal on a non-repo path.

The change also tightens destructive cleanup safety around WSL/runtime path translation, protected home/root paths, nested registered worktrees, and WSL missing-path stat behavior.

Design Review

Design doc created as scratch context and reviewed before implementation. The reviewed design narrowed no-marker cleanup to local paths, required directory/no-.git/not-a-repo proof, kept SSH no-marker cleanup out of scope, and required cross-platform path checks.

Implementation

  • Added a no-marker leftover cleanup helper for Orca-owned local worktree directories with persisted provenance.
  • Wired IPC and runtime removal paths to prompt on non-force and force-delete through local filesystem cleanup.
  • Preserved existing SSH behavior and existing .git-marker orphan cleanup.
  • Added safety coverage for files/symlinks, standalone repos, nested worktrees, original/runtime path-space checks, POSIX home protection, and WSL missing-path errors.
  • Localized pre-existing workspace cleanup filter labels and synced locale catalogs so required localization gates pass.

Completeness Verification

Completeness verification initially found missing coverage; added helper and integration tests. A follow-up verification pass confirmed the implementation matched the design, with only non-blocking notes about live WSL/SSH coverage.

Code Review

Two-reviewer rounds were run until both reviewers returned clean in the same round.

Actionable findings fixed during review:

  • WSL nested-worktree checks comparing runtime paths to registered original paths.
  • Dangerous path checks obscured by WSL runtime translation.
  • No-marker cleanup trusting path shape without persisted metadata.
  • WSL missing .git stat errors not shaped as ENOENT.
  • POSIX home/root paths not protected when host home has a different shape.
  • Existing .git orphan cleanup needed original-path danger and nested checks.

Final round: both reviewers returned no issues.

Brennan Test Changes

Recommendation: land.

Validated:

  • no-marker local leftover prompt-before-force behavior
  • force cleanup deletes the leftover directory and metadata
  • arbitrary existing unregistered directories remain rejected
  • .git directories / still-repo paths remain rejected
  • nested registered worktrees remain protected
  • WSL runtime path/stat behavior and protected path handling
  • SSH no-marker cleanup remains out of scope and local-only behavior is preserved

No screenshot evidence was captured because the changed behavior is backend/destructive-delete logic exercised through IPC/runtime tests with temporary filesystem fixtures. The small UI localization cleanup is covered by lint/localization checks.

Checks

  • pnpm test -- --run src/main/worktree-removal-safety.test.ts src/main/local-worktree-filesystem.test.ts src/main/ipc/worktrees.test.ts src/main/runtime/orca-runtime.test.ts - 680 passed
  • pnpm test -- --run src/main/worktree-removal-safety.test.ts src/main/local-worktree-filesystem.test.ts src/main/ipc/worktrees.test.ts src/main/runtime/orca-runtime.test.ts -t "unregistered|orphan|local worktree filesystem runtime access|canCleanupUnregisteredOrcaLeftoverDirectory" - 35 passed
  • pnpm exec tsc --noEmit --pretty false - passed
  • pnpm run lint - passed
  • git diff --check - passed

Post-PR Stabilization

Pending initial PR automation. Will wait for automated review/checks and update if fixes are needed.

Assumptions and Risks

  • SSH no-marker leftover deletion remains intentionally out of scope; remote deletion needs separate proof semantics.
  • Live SSH deletion was not exercised.
  • Live WSL deletion was smoke-checked by validation for path visibility/missing behavior; most safety coverage is mocked/unit-level.

@brennanb2025
brennanb2025 force-pushed the brennanb2025/scorpionfish branch from 3d44895 to 650a4da Compare June 28, 2026 22:34
@coderabbitai

coderabbitai Bot commented Jun 28, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: fd808abb-d95f-4644-bf57-8075ead11a29

📥 Commits

Reviewing files that changed from the base of the PR and between 650a4dabe8bbd5bef4481427945034d566b2d7b5 and aee2730.

📒 Files selected for processing (8)
  • src/main/ipc/worktrees.test.ts
  • src/main/ipc/worktrees.ts
  • src/main/local-worktree-filesystem.test.ts
  • src/main/local-worktree-filesystem.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/worktree-removal-safety.test.ts
  • src/main/worktree-removal-safety.ts
✅ Files skipped from review due to trivial changes (1)
  • src/main/ipc/worktrees.test.ts
🚧 Files skipped from review as they are similar to previous changes (6)
  • src/main/local-worktree-filesystem.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/ipc/worktrees.ts
  • src/main/worktree-removal-safety.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/worktree-removal-safety.test.ts

📝 Walkthrough

Walkthrough

The changes add guarded cleanup for unregistered Orca leftover directories in both the IPC worktrees handler and the Orca runtime flow. A new canCleanupUnregisteredOrcaLeftoverDirectory check applies provenance, dangerous-path, directory, marker, and git-repository conditions before deletion. The safety rules are expanded to cover POSIX home-directory cases. Additional tests cover the new cleanup paths and rejection cases. Separately, WSL-backed statPath now converts exit-code-2 missing-path failures into ENOENT, with tests for that behavior.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: recovering partially deleted local worktrees.
Description check ✅ Passed The description is mostly complete and covers summary, implementation, testing, review, and risks, with only some template sections not fully formalized.
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.

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: 1

🧹 Nitpick comments (4)
src/main/local-worktree-filesystem.ts (1)

106-111: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a short why-comment for the WSL exit-code remap.

Normalizing code === '2' to ENOENT is a non-obvious compatibility contract for the cleanup callers. Please leave a brief “Why” comment here so this does not look like generic exit-code handling. As per coding guidelines, modified TypeScript with non-obvious behavior should include a short explanatory comment.

Suggested change
       ].join('\n')
       ).catch((error) => {
+        // Why: this shell returns exit code 2 for our explicit "missing path"
+        // branch; remap it to ENOENT so callers can treat WSL like native fs.
         if (isWslMissingPathError(error)) {
           throw Object.assign(new Error(`missing ${path}`), { code: 'ENOENT' })
         }
         throw error
       })

Source: Coding guidelines

src/main/ipc/worktrees.ts (2)

258-287: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Centralize and document the conservative Git-repo probe.

gitStatusErrorMeansNotRepository is duplicated in src/main/runtime/orca-runtime.ts; this parser now gates recursive deletion in two paths, so extract a shared helper and add a short note that unknown Git failures are treated as repository-like to fail closed. As per coding guidelines, "When writing or modifying code driven by a design doc or non-obvious constraint, add a comment explaining why the code behaves the way it does."

Source: Coding guidelines


1467-1505: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a short “why” comment for this recovery branch.

This local-only path intentionally deletes an unregistered non-repository directory without calling Git; a brief comment will preserve the safety rationale at the call site. As per coding guidelines, "When writing or modifying code driven by a design doc or non-obvious constraint, add a comment explaining why the code behaves the way it does."

Suggested comment
+          // Why: partially deleted local worktrees are no longer Git repos; only
+          // recursively delete targets proven to be Orca-owned leftovers.
           if (!repo.connectionId) {

Source: Coding guidelines

src/main/runtime/orca-runtime.ts (1)

1207-1236: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Factor the duplicated git-repo probe into one helper. isLocalRuntimeGitRepository/isLocalGitRepository and gitStatusErrorMeansNotRepository are identical in src/main/runtime/orca-runtime.ts and src/main/ipc/worktrees.ts; a shared helper would keep the repo check in sync.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: aa859222-e2f0-42d0-8154-594e29e7aa24

📥 Commits

Reviewing files that changed from the base of the PR and between ef6e643 and 3d448956fc5ad51c10ad109360aa932892318fa3.

📒 Files selected for processing (16)
  • config/localization-coverage-allowlist.json
  • src/main/ipc/worktrees.test.ts
  • src/main/ipc/worktrees.ts
  • src/main/local-worktree-filesystem.test.ts
  • src/main/local-worktree-filesystem.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/worktree-removal-safety.test.ts
  • src/main/worktree-removal-safety.ts
  • src/renderer/src/components/workspace-cleanup/WorkspaceCleanupDialog.tsx
  • src/renderer/src/components/workspace-cleanup/workspace-cleanup-presentation.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/zh.json

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

🧹 Nitpick comments (1)
src/main/local-worktree-filesystem.ts (1)

71-78: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a short why-comment for the WSL exit-code remap.

Treating WSL exit code 2 as ENOENT is a non-obvious contract, so this change should carry a brief rationale near the helper or the catch block.
As per coding guidelines, "When writing or modifying code driven by a design doc or non-obvious constraint, add a comment explaining why the code behaves the way it does."

♻️ Proposed fix
 function isWslMissingPathError(error: unknown): boolean {
+  // Why: the WSL stat probe exits 2 when the target path is missing; callers
+  // already branch on ENOENT, so normalize that shell-specific failure here.
   const code =
     error && typeof error === 'object' && 'code' in error
       ? String((error as NodeJS.ErrnoException).code)
       : ''

Also applies to: 106-109

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: d6a94094-b005-47bc-bb9e-e696e7704d05

📥 Commits

Reviewing files that changed from the base of the PR and between 3d448956fc5ad51c10ad109360aa932892318fa3 and 650a4dabe8bbd5bef4481427945034d566b2d7b5.

📒 Files selected for processing (8)
  • src/main/ipc/worktrees.test.ts
  • src/main/ipc/worktrees.ts
  • src/main/local-worktree-filesystem.test.ts
  • src/main/local-worktree-filesystem.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/worktree-removal-safety.test.ts
  • src/main/worktree-removal-safety.ts
🚧 Files skipped from review as they are similar to previous changes (7)
  • src/main/local-worktree-filesystem.test.ts
  • src/main/worktree-removal-safety.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/worktree-removal-safety.ts
  • src/main/ipc/worktrees.test.ts
  • src/main/ipc/worktrees.ts
  • src/main/runtime/orca-runtime.test.ts

@brennanb2025
brennanb2025 force-pushed the brennanb2025/scorpionfish branch from 650a4da to aee2730 Compare June 28, 2026 22:44
@OrcaWin
OrcaWin merged commit 206a709 into stablyai:main Jun 29, 2026
1 check passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
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.

3 participants