Skip to content

[Bug]: Worktree threads fail with ref_not_found when origin/HEAD points at a deleted default branch #36261

Closed

Description

@NotPellew

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/server

Steps to reproduce

  1. Clone a repository whose default branch is development, so the clone has refs/remotes/origin/HEAD -> refs/remotes/origin/development.
  2. On the remote, make main the default branch and delete development.
  3. In the clone, run git fetch --prune. Git does not update origin/HEAD on fetch, so it is now a dangling symref pointing at the deleted branch.
  4. Start a thread in New worktree mode without picking a base branch, for example through the MCP tools or t3 thread start as an agent would.

Git-only reproduction of the repository state:

git init -q --bare -b development remote.git
git clone -q remote.git seed && cd seed && git commit -q --allow-empty -m one && git push -q origin development development:main && cd ..
git clone -q remote.git clone
git -C remote.git symbolic-ref HEAD refs/heads/main && git -C seed push -q origin --delete development
git -C clone fetch -q --prune
git -C clone symbolic-ref refs/remotes/origin/HEAD   # still refs/remotes/origin/development
git -C clone rev-parse --verify -q origin/HEAD || echo dangling

Expected behavior

The worktree is created from the remote's actual default branch (main). If the stored default can't be resolved, T3 falls back to the remote's real HEAD or asks for a base, instead of failing.

Actual behavior

Every such thread fails before the agent starts:

Workspace preparation failed during provision worktree: Git command failed in GitVcsDriver.createWorktree.createBranch (/home/agent/Projects/Thalvi): git branch failed (ref_not_found)

GitVcsDriver.resolveDefaultBranchName (and listRefs' defaultRef) read git symbolic-ref refs/remotes/origin/HEAD. That succeeds for a dangling symref and returns development, which is then used as the worktree base without checking that refs/remotes/origin/development exists (remoteBranchExists is there, but not used on this path).

Related: retrying such a failed thread ran the agent in the project root without a worktree (worktreePath null, the checkout switched to the thread's branch), so a retry can collide with other threads in the same checkout.

Impact

Minor bug or occasional failure

Version or commit

0.1.10-nightly.20261112.4606 (server, headless systemd user service)

Environment

Ubuntu 26.04, git 2.53.0, T3 server as a background service; threads started by a linked environment's agents.

Logs or stack traces

See actual behavior. Workarounds: `git remote set-head origin --auto` per clone, or `git config remote.origin.followRemoteHEAD always` (git ≥ 2.48), so every fetch updates `origin/HEAD`.

Related to #25719 / #35103, which fix the web branch picker's seeding while a project is still cloning. This report is the server-side path with a dangling `origin/HEAD` after the default branch changed, which #35103 doesn't touch

Screenshots, recordings, or supporting files

No response

Workaround

Run git remote set-head origin --auto in the affected clone; new worktree threads work again right away. To keep it from recurring, set git config --global remote.origin.followRemoteHEAD always (git ≥ 2.48), so every git fetch updates origin/HEAD when the remote's default branch changes. A thread that already failed at workspace preparation should be started fresh rather than retried, because a retry runs without a worktree in the project root.

Activity

  1. added
    bug
    needs-triage
    on Nov 13, 2026
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

    bugneeds-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions