Skip to content
Source
Sign inSign up
pingdotgg/t3code

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

OpenProject516(GitHub profile, opens in a new tab) opened this issue 4 comments

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:

Workspace 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

$ git init -q -b main repo && cd repo
$ git worktree add -b t3/x ../wt main
fatal: 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.
  1. 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.

  2. 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.

  3. 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.

  4. tanstack-source added labelsbug

  5. Still happening on nightly 0.1.12-nightly.20261122.5111, and it also breaks scheduled tasks. An unbound task created with the schedule_task MCP tool gets a worktree strategy whose baseRef falls back to main when no branch ref resolves (scheduledTaskWorkspaceStrategy / resolveScheduledTaskBaseRef in OrchestratorMcpService.ts, main 6b38ec9). ScheduledTaskService.upsert only switches that to the project folder for Scratch or non-Git projects, so in a repo with no commits every such task fails when it fires, before the model starts:

    Workspace preparation failed during provision worktree: Base ref "main" does not resolve to a commit in project "<project>" (<workspace root>).

    This happened to me twice (19 and 22 Nov, in a repo with no commits and no remote). A follow-up message sent to the failed thread then stayed queued without starting.

    Unbound scheduled runs go through ThreadLaunchService.launch, so the fallback in #34968 should cover them too (and #39760 would let schedule_task choose the project checkout directly). Until then, binding the task to a thread, or making an initial commit, avoids it.

Sign in to join this conversation.