Skip to content

[Bug]: Workspace deletion leaves an undeletable record when git worktree remove partially fails (metadata_purge skipped, retries refused as unregistered) #21763

Open

Description

@koupent

Operating system

Windows

Orca version

1.4.205

Details

Short summary: When git worktree remove --force partially fails during workspace deletion, Orca keeps the workspace record but git has already dropped its registration. Every retry is then refused with Refusing to delete unregistered worktree path, so the card can never be removed from the UI. The card is labelled Detached HEAD @ <sha> because no branch resolves for it.

This is the same error string as #5864 (closed as fixed in v1.4.134 by #5888), but the cause is different: in #5864 the guard fired spuriously on a registered path; here the guard fires correctly — the path really is unregistered — and that is exactly the state Orca needs to be able to clean up. Related: #10629 (registration dropped, files left behind, Windows), #10951 (ghost worktreeMeta rows), #17654 (a different "cannot delete" dead end).

What the trace shows

worktree.remove runs watcher_gate → pty_sweep → git_remove (trash_rename, branch_delete) → metadata_purge → cache_invalidation. When git_remove fails, the parent span fails and metadata_purge never runs. From main.trace.ndjson (SSH execution host, the worktree lives on a 9p bind mount of a Windows folder inside a dev container):

time path error
11:20:48 /workspaces/<repo>/244-2 Request "git.removeWorktree" timed out after 30000ms
19:32:19 /workspaces/<repo>/seacucumber Command failed: git worktree remove --force … → error: failed to delete '…': Directory not empty
19:32:55 same (retry) Refusing to delete unregistered worktree path: …
19:33:24 same (retry) Refusing to delete unregistered worktree path: …
20:53:12 /workspaces/<repo>/npm Request "git.removeWorktree" timed out after 30000ms

After the first seacucumber attempt, git worktree list no longer showed the path (registration gone), but 29,335 files remained on disk. Orca's record survived because metadata_purge was skipped, and from then on the guard blocked every retry.

How to reproduce

  1. Add a repo on an SSH execution host where the checkout is a bind mount (Docker Desktop 9p/drvfs mount of a Windows folder works). Create a workspace inside that mount (set the host's workspace directory to the mount or its parent with nested workspaces on).
  2. Make the directory undeletable by git worktree remove --force from inside the container: e.g. a node_modules tree with files held open on the Windows side, or a root-owned file.
  3. Delete the workspace from the UI → fails with Directory not empty. git worktree list no longer lists it.
  4. Delete again → Refusing to delete unregistered worktree path. Repeat forever.

A 30 s git.removeWorktree RPC timeout on a large tree (steps 1–3 with a big node_modules over 9p) ends in the same state.

Expected

  1. Treat partial success as partial success. Once git's registration is gone, run metadata_purge and report the leftover directory as a separate warning instead of keeping a record that points at nothing.
  2. "Not registered in git" should not block deletion. It is the normal end state after a half-failed remove; the right action is to drop Orca's record (and optionally offer to delete the leftover directory).
  3. Always offer an escape hatch — "Remove from Orca (keep files)" — so a record can never become permanent.
  4. The fixed 30 s timeout for git.removeWorktree is too short for large worktrees over SSH/9p; scale it or make it long-running with progress.

Evidence (trace spans, config snapshot, container git worktree list --porcelain) is archived and can be attached on request.

Activity

  1. AmethystLiang commented on Sep 20, 2026

    @AmethystLiang
    Contributor

    thanks for reporting. looking into it

  2. added a commit that references this issue on Oct 7, 2026
    fb1121f
  3. MatiasOlivera commented on Oct 30, 2026

    @MatiasOlivera

    Confirmed still reproducible on Linux / Orca 1.4.239, with a different trigger than the Windows/9p case reported here: a root-owned file inside the worktree makes git worktree remove fail with Permission denied instead of Directory not empty.

    Trace (local execution host, plain local checkout — no bind mount)

    2026-10-28T14:48:41  worktree.remove          FAIL
      worktree.remove.git_remove  FAIL
        git worktree remove <workspaces>/<repo>/<worktree>
        error: failed to delete '<worktree-path>': Permission denied
    2026-10-28T14:48:53  worktree.remove          FAIL  "<worktree-path> is no longer a Git worktree, so its folder was left on disk. Delete the folder yourself to finish removing this workspace."
    2026-10-28T14:49:14  worktree.remove          FAIL  (same)
    2026-10-28T14:49:23  worktree.remove          FAIL  (same)
    2026-10-28T21:32:59  worktree.remove          FAIL  (same)
    2026-10-29T09:33:17  worktree.remove          FAIL  (same)
    

    A second workspace reproduced it independently at 2026-10-30T08:51:47 with the same Permission denied, after a root-owned dist/ directory was produced inside it. In both cases git had already dropped the worktree's admin entry under .git/worktrees/<id> before failing, so the checkout was no longer a git worktree while its directory remained on disk.

    Differences from the original report

    1. The error string changed in 1.4.239. The guard now says "is no longer a Git worktree, so its folder was left on disk. Delete the folder yourself to finish removing this workspace." (emitted from out/main/chunks/orcad-migration-source-retention-*.js), rather than "Refusing to delete unregistered worktree path".
    2. --force does not help. orca worktree rm --worktree <path> --force fails with the identical error.
    3. The message is a dead end. It instructs the user to delete the folder manually, but there is no supported way to finish the removal inside Orca afterwards:
      • orca worktree rm against the same selector then returns selector_not_found (an error) rather than success.
      • The workspace record disappears only via a background reconcile (a git worktree list pass) a few seconds later, so scripted and CLI flows get no success signal at all.
    4. The trigger is common on Linux: any root-owned file inside the worktree is enough — Docker or sudo builds and CI helpers produce these routinely. In both of my cases the only offending path was a dist/ directory owned by root.

    Expected (same as the original report)

    • Treat partial success as partial success: once git's registration is gone, run metadata_purge and report the leftover directory as a separate warning instead of keeping a record that points at nothing.
    • "Not registered in git" must not block deletion — it is the normal end state after a half-failed remove.
    • Always offer an escape hatch — "Remove from Orca (keep files)" — so a record can never become permanent.

    Version matrix

    report OS Orca version
    this comment Linux 1.4.239
    #21763 Windows 1.4.205
    #14435 macOS —

    Requesting the os:linux label: this reproduces on Linux with a plain local checkout and no bind mount.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions