Skip to content

Orchestrator leaks worktrees and branches when dispatcher fails before claude runs #17

@oscarvalenzuelab

Description

@oscarvalenzuelab

Summary

When the dev pipeline fails before the Claude subprocess successfully completes (e.g. [Errno 2] No such file or directory: 'claude', or any early subprocess/exec failure), the orchestrator leaves behind:

  1. A git worktree under ~/.dev-sync/worktrees/<repo>-dev-<repo>-<n>-<hash>/
  2. A local branch fix/issue-<n> in the bare repo

On the next attempt for the same issue, worktree creation fails with:

git failed: Preparing worktree (new branch 'fix/issue-13')
fatal: a branch named 'fix/issue-13' already exists

...so the issue can never be retried without manual cleanup.

Repro

  1. Break the dispatcher (e.g. PATH doesn't include claude binary under launchd)
  2. Let the poller pick up a new issue → it creates worktree + branch, then fails
  3. Fix the dispatcher
  4. Retry the same issue → fails on "branch already exists"

Expected

On any failure path in run_dev_issue (dispatcher error, checkpoint FAILED, uncaught exception), the orchestrator should remove the worktree and delete the fix/issue- branch so the issue is safe to retry.

Suggested fix

Wrap the pipeline body in a try/finally (or an async context manager) that:

  • git worktree remove --force <worktree_path> on any failure exit
  • git branch -D fix/issue-<n> in the bare repo on any failure exit
  • Leaves both intact on BLOCKED (user may still want to inspect / continue)
  • Leaves both intact on DONE (PR may still reference the branch)

Evidence

Seen today in AInvirion/dev-sync for issues #13, #14, #15. Required manual:

BARE=~/.dev-sync/repos/AInvirion-dev-sync.git
git -C "$BARE" worktree remove --force <path>
git -C "$BARE" branch -D fix/issue-<n>

...plus clearing the issue from ~/.dev-sync/poller_state.json seen_issues before the poller would retry.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions