[Bug]: New worktree threads fail in a repository with no commits#22017

opened10d agobyPProject516

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. Run git init in an empty folder. Do not commit anything.
  2. Add the folder as a project in T3 Code.
  3. Set new threads to start in a new worktree (Settings, or the project's default).
  4. Start a new thread and send a message.

Expected behavior

The thread starts. A repository with no commits has nothing to check out, so the thread should run in the project folder, as it does for a non-Git project.

Actual behavior

Setup fails at the checkout step and no turn starts:

1Workspace preparation failed during provision worktree: Git command failed in GitVcsDriver.createWorktree (<repo>): git worktree add failed

Git itself reports fatal: invalid reference: main, because main has no commit yet. Retry fails the same way. The only way forward is to make a commit or switch the thread to the main checkout.

Impact

Blocks work completely

Version or commit

main @ 673c5e3b3

Environment

Linux, git 2.43+. Reproduced by hand with git init -b main repo && cd repo && git worktree add -b t3/x ../wt main, which exits 128 with fatal: invalid reference: main. Not provider specific.

Logs or stack traces

shell
1$ git init -q -b main repo && cd repo
2$ git worktree add -b t3/x ../wt main
3fatal: invalid reference: main

Workaround

Make an initial commit, or start the thread in the main checkout.

Prior work

  • #2148 was closed as not reproducible for the dead-route symptom. The closing comment notes that worktree creation without a commit still fails and that a local-mode fallback was not implemented.
  • #15580 added that fallback in ThreadLaunchService and was closed in favor of #17791.
  • #17791 only adds a pre-launch check for the MCP t3_thread_launch tool. It accepts a repository whose HEAD has no commit and leaves that case to #15580, so the failure above still happens on current main for every launch path.

Reproduced on Linux in the web dev app at 70e5e384da: added a folder initialized with git init -b main, selected New worktree, and sent a message. Checkout failed with git worktree add failed (ref_not_found) before the agent started; Retry failed identically. The same flow in a repository with one initial commit created the worktree and completed the turn.

The candidate fix passes all 40 focused launch-service tests. Review identified a maintainer decision: the shared fallback also changes t3_thread_launch, so an explicit new-worktree request can execute in the project folder instead. Stopped before publishing a PR under the triage rule for MCP tool-surface changes. The issue remains open.

Reproduced again in the Linux web dev app on 05b697f6a2: added a folder initialized with git init -b main, selected New worktree, and sent a message. Workspace preparation failed with git worktree add failed (ref_not_found) before a provider turn started. A regression test and focused fix are in progress.