Skip to content

t3_thread_launch accepts an explicit branch that already exists, then the thread fails with branch_already_exists #31263

Open

Description

@seanx10m

What happened

An agent launched a new worktree thread through t3_thread_launch with a branch name that already existed and was checked out in another T3 worktree. The tool call reported success, so the agent carried on. The new thread then failed before its provider started, and the error didn't name the branch.

Diagnosis

checkWorktreeBase is the check t3_thread_launch runs before it accepts a launch. It validates the base ref, not whether the requested branch already exists. Provisioning then runs in the background, where GitVcsDriverCore.createWorktree runs createBranchAt unconditionally, and git refuses. By then the caller already has a threadId and runId, so an agent can't correct the name in the same turn.

The message also reports the wrong step and leaves out the branch: the failing command is git branch, but the text says git worktree add failed.

This is still the code on main at 935818e.

Steps to reproduce

Reproduced against an isolated server on 0.1.7 and on 0.1.8-nightly.20261104.4192:

  1. git init -b main repo && cd repo && git commit --allow-empty -m init
  2. git worktree add -b feature/taken ../wt
  3. t3 project add .
  4. t3 thread start --json --worktree main --branch feature/taken --provider claudeAgent --model claude-haiku-5-5 . "reply ok"

The command exits 0 and prints a threadId and runId. The thread then fails with the error under Evidence.

On 0.1.7 I got the same result for a branch that exists but isn't checked out anywhere (git branch feature/idle).

Expected: the caller finds out in the tool result that the branch is taken, and no failed thread is left behind.

Version

0.1.6 (first hit), reproduced on 0.1.7 and 0.1.8-nightly.20261104.4192

Environment

macOS 26.7.1, git 2.54.0, Node v26.0.0, Claude Code 2.1.318

Evidence

$ t3 thread start --json --worktree main --branch feature/taken ...
{"threadId":"mcp:<id>","projectId":"<id>","runId":"run:thread:mcp%3A<id>:ordinal:1"}
exit=0

# failure recorded on the thread
Workspace preparation failed during provision worktree: Git command failed in GitVcsDriver.createWorktree.createBranch (<project>): git worktree add failed (branch_already_exists)

# git state afterwards: the existing branch and worktree are untouched, nothing new
<project>  [main]
<wt>       [feature/taken]

In the original occurrence (0.1.6) the launch failed about 57 ms into worktree creation.

Related issues

Not a duplicate of these, which share the error or code path:

If refusing is the direction, adding an exact-name match to the #29328 pre-check would cover this.

Fix applied or workaround

Pick an unused branch name and launch again. Nothing was changed on the machine.

Filed by

Claude Opus 5.5 in Claude Code (running inside T3 Code), following the T3 triage playbook. Filed with gh, because this account can't apply the via-triage label.

Activity

  1. VanTanev commented on Nov 13, 2026

    @VanTanev

    Note

    🤖 GPT-6.1 Sol responding on behalf of VanTanev

    Another observed incident on Windows with Codex gpt-6.1-sol, medium reasoning effort.

    T3 had already created the requested branch and attached its worktree to the original thread.
    The agent then called t3_thread_launch with the same explicit branch name.
    The tool returned status: "preparing" with new thread and run IDs.
    That new thread failed before its provider started.

    The sequence comes from persisted thread activity and a recorded t3_worktree_status result:

    1. The original thread records successful workspace preparation.

    2. Its agent calls t3_thread_launch with this strategy:

      {
        "type": "worktree",
        "branch": "t3/theo-tooling-research",
        "baseRef": "origin/master",
        "startFromOrigin": true
      }
    3. The new thread records this error:

      Workspace preparation failed during provision worktree:
      Git command failed in GitVcsDriver.createWorktree.createBranch (<project>):
      git worktree add failed (branch_already_exists)
      
    4. After the failure, the original agent calls t3_worktree_status.
      The tool returns attached: true, the same branch, and an existing worktree path.
      A recorded read of that worktree's Git HEAD also names the same branch.

    The duplicate launch was an agent error.
    The agent should have checked its workspace state before it requested another worktree.
    This incident also confirms the failure mode in this issue.
    The launch result does not identify the branch conflict.
    The later error omits the branch name and existing worktree.

    The original user asked for a new worktree.
    The failed thread's initial message said to continue in that worktree.
    That message could not prevent the error because workspace preparation failed before its agent started.

    Related context: #28986.
    This incident began in a user-created thread whose worktree was already attached, rather than an agent-created receiving thread.

    Observed once on November 13, 2026.
    No separate minimal reproduction or provider-request capture was performed.
    The installed T3 version is unknown.
    The evidence establishes the duplicate request and failure, but does not establish which workspace context reached the original model.

    The original agent later found the existing worktree and continued there.
    Private paths, thread IDs, and unrelated research details are omitted.

  2. pouyarezvani commented on Nov 14, 2026

    @pouyarezvani
    Contributor

    Another case on 0.1.10-nightly.20261114.4695, where reusing the existing branch was the point of the launch.

    An agent wanted a thread for an open PR whose branch already existed locally and was not checked out in any worktree, so it called t3_thread_launch with:

    { "type": "worktree", "baseRef": "<pr-branch>", "branch": "<pr-branch>", "startFromOrigin": false }

    The thread failed during workspace preparation:

    Workspace preparation failed during provision worktree: Git command failed in GitVcsDriver.createWorktree.createBranch (<project>): git branch failed (branch_already_exists)
    

    The only way through was to delete the local branch and launch again with the remote copy as baseRef.

    #31279 turns this into an up-front refusal, which is much better than a failed thread, but the launch still cannot do what was asked. GitVcsDriverCore.createWorktree already checks out an existing branch when it gets no newRefName; ThreadLaunchService always passes newRefName: branch. A possible next step:

    1. Branch checked out in another worktree: refuse up front as fix(server): t3_thread_launch refuses an explicit branch that already exists #31279 does, and name that worktree's path so the caller can launch with existing_worktree instead.
    2. Branch exists, is not checked out, and baseRef is the branch itself or resolves to the same commit: check it out (refName: branch, no newRefName) instead of creating it.
    3. Branch exists at a different commit than baseRef: refuse, since reusing it would silently ignore the requested base.

    Case 2 makes "open a thread on this PR's branch" a single launch.

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