Skip to content

Worktree creation reports ref_not_found when the branch is checked out in another worktree #38027

Closed as duplicate

Description

@mihaisavezi

What happens. Creating a thread worktree for a PR head branch fails with ref_not_found when that branch is already checked out in a sibling worktree. The branch exists; git refuses because it is in use elsewhere.

Expected. Say so: "branch X is checked out in worktree Y". Better: offer a detached worktree at the branch head.

Seen. 3 separate agent sessions in one week. Each made a detached worktree by hand.

Activity

  1. juliusmarminge commented on Nov 17, 2026

    @juliusmarminge
    Member

    @mihaisavezi Which action produced the ref_not_found error (opening a PR as a worktree thread in the app, t3_thread_launch from an agent with which baseRef/branch/startFromOrigin values, or something else), and what was the full error text?

  2. added
    needs more info
    on Nov 17, 2026
  3. mihaisavezi commented on Nov 17, 2026

    @mihaisavezi
    Author

    Thanks, and a correction first: after pulling the exact calls from the logs, my original diagnosis was wrong. The branch being checked out in another worktree was a guess the agents made from the error; it wasn't the cause.

    Action: t3_thread_launch from an agent in another thread (not the app UI), 2 occurrences (3 Nov and 10 Nov), each retried a few times with the same result:

    {"workspaceStrategy": {"type": "worktree", "baseRef": "origin/<feature-branch-name>", "startFromOrigin": true}}

    No branch was passed. In both cases the baseRef was wrong: the launching agent built the branch name from memory, and no such branch existed on origin (git ls-remote origin confirms it). The PR head was a similar but different name (for example origin/feature/<id>-overview-header passed, real branch feature/<id>-overview).

    Full error text (thread activity item, identical every time):

    Workspace preparation failed during provision worktree: Git command failed in GitVcsDriver.createWorktree.createBranch (/path/to/project): git worktree add failed (ref_not_found)
    

    So ref_not_found was correct. What went wrong is that the message never names the ref, and it is reported from createBranch. Both agents (and I) misread it: one decided the local base branch was missing and created it, the other decided the PR branch was checked out in another worktree. On Retry the same bad baseRef failed again.

    Suggested fix (smaller than my original ask):

    1. Name the ref and where it was looked up: baseRef "origin/feature/x" not found on origin.
    2. Optionally, have t3_thread_launch check the baseRef before creating the thread and return the error to the calling agent, so it can correct the name instead of leaving a failed thread behind.

    Happy to retitle the issue to match this.

  4. removed
    needs more info
    on Nov 17, 2026
  5. juliusmarminge commented on Nov 17, 2026

    @juliusmarminge
    Member

    This is the same problem as #36268, so I'm closing it in favour of that one. If it is different, say how and it will be reopened.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions