Skip to content

[Bug]: A stale worktree preparation whose .git file is missing is never reclaimed #26885

Closed

Description

@VincentMenard76

Operating system

Windows

Orca version

1.4.221

Details

Short summary: A crashed worktree preparation whose .git file is gone stays locked forever. Stale-preparation cleanup runs and then ignores the failure.

What happened?

On Windows, D:\GIT\_worktrees\.orca-preparing\ still contained six detached worktrees after Orca had quit. Each one was registered on the main repo and locked:

locked orca-create-preparation:v1:4744:4744-<uuid>
detached

The owner pid 4744 was no longer running. The worktree directory still had a partial checkout, but its .git gitlink was missing. The admin entry under <repo>/.git/worktrees/<id>/gitdir still pointed at that missing file.

Recovery then fails closed:

  • git worktree remove --force <path> exits 128: validation failed, cannot remove working tree: '<path>/.git' does not exist
  • git worktree prune skips the entry because it is locked
  • git worktree unlock also cannot validate the working tree while .git is missing

startStalePreparationCleanup (src/main/worktree-create-preparation-stale-cleanup.ts) does see these rows: the lock reason parses to a dead pid, and the directory name .orca-preparing/<pid>-<uuid> parses to the same pid. It calls discardPreparedWorktree(...) and discards the rejection with .catch(() => {}). The next composer open scans again, Git refuses again, and the directories stay.

This is the hole left by the existing reclaim path (#17290, #17899, #18058, #18951, #18967). #18967 keeps the ownership lock when removal cannot start, so a later scan can retry. A missing gitlink makes that retry unable to succeed.

Turning off "Ask before deleting workspaces" does not cover this. That setting only skips the delete confirmation.

How can we reproduce it?

  1. Let Orca create a locked detached preparation at <workspaceDir>/.orca-preparing/<pid>-<uuid> (git worktree add --detach --no-checkout --lock --reason orca-create-preparation:v1:<pid>:<id>).
  2. Kill Orca, then delete only that directory's .git file. Leave .git/worktrees/<id>/ in place, including locked and gitdir.
  3. Start Orca and open the worktree create composer for that repo, so startStalePreparationCleanup runs.
  4. git worktree list --porcelain still shows the locked detached worktree.

Expected

When the lock owner is dead, the path is still .orca-preparing/<same pid>-<uuid>, and the worktree is detached:

  1. If .git is missing and the admin gitdir file still names it, rewrite that gitlink.
  2. Remove the preparation with one locked-worktree remove. Unlock first only if Git still rejects the locked remove.
  3. If removal still fails, keep the lock, but record the failure instead of swallowing it. A later scan must not repeat a remove that cannot succeed until the gitlink is restored.

Keep the current safety rule: a user worktree is not force-removed from the path shape alone. Only a matching orca-create-preparation:v1: lock authorizes cleanup.

Activity

  1. AmethystLiang commented on Oct 9, 2026

    @AmethystLiang
    Contributor

    Thanks for reporting. Looking into it

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions