t3code icon indicating copy to clipboard operation
t3code copied to clipboard

[Bug]: Worktree launch reported an immediate "branch already exists" failure 7 hours after it was requested

Open MichaelHabermas opened this issue 1 month ago • 0 comments

What happened

An agent launched a new worktree thread through the T3 MCP. The thread showed "Preparing workspace" for almost seven hours, then reported a failure that git returns immediately:

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

The requested branch really was already checked out in the project's main checkout, so the failure itself is correct. The problem is that it took 6 h 56 m to be reported, and the thread was unusable for that whole time.

Diagnosis

  • Timeline (from statev2.sqlite). Thread mcp:664d2717-… was created by an agent (creationSource: "mcp") with the existing branch <existing branch>.

    • The run's requestedAt and the preparation item's startedAt are both 2026-10-28T04:35:19.562Z. The run's startedAt is null.
    • The preparation item and the run completed as failed at 2026-10-28T11:31:55.561Z.
    • A follow-up run in the same thread started 18 s later (11:32:13Z) and worked normally.
  • Not explained by machine sleep. pmset -g log shows the Mac asleep for about 18% of that window. It was awake for about 5 h 40 m of it.

  • Not explained by a slow git command. Every git command in the provisioning path is bounded:

    • DEFAULT_TIMEOUT_MS = 30_000 (apps/server/src/vcs/GitVcsDriverCore.ts:55) covers resolveWorktreeBaseRemote, fetchWorktreeBaseCommit and hasCommit.
    • WORKTREE_ADD_TIMEOUT_MS = 300_000 (:64) covers createWorktree.
    • The failure was not a timeout. It is the branch_already_exists pattern (:437) matched from git's own stderr, and git worktree add -b <existing branch> exits at once.

    So the time was spent outside those git commands: either before ThreadLaunchService's provisioning (apps/server/src/orchestration-v2/ThreadLaunchService.ts lines 378–446) began, or between git failing and failPreparedRun dispatching prepared-run.fail (:705, called at :789 and :1053). I couldn't tell which: the server trace logs had rotated past 04:35–11:31Z, and the thread's v2 events had been compacted.

  • The server process (pid in server-runtime.json, started 2026-10-27T22:12:54Z) was not restarted during the window.

  • Context: this is 1 of 252 workspace preparations on this machine since 2026-10-09. The others took a median of 1.1 s and a maximum of 3 s.

Steps to reproduce

No deterministic repro yet. The conditions were:

  1. A project whose main checkout has branch X checked out.
  2. Through the T3 MCP (t3_thread_launch), an agent launches a thread with a new-worktree strategy that requests the existing branch X.
  3. Expected: the failure appears within seconds. Observed once: "Preparing workspace" stayed running for about 7 h before the same failure appeared.

Version

0.1.4-nightly.20261027.3783

Environment

macOS 26.6.2 (arm64), git 2.54.0 (Apple Git-157), Node v24.22.1, Claude Code 2.1.312 as the thread's provider

Evidence

# orchestration_v2_projection_turn_items (type=command_execution, input="Preparing workspace")
startedAt   2026-10-28T04:35:19.562Z
completedAt 2026-10-28T11:31:55.561Z
status      failed
output      Workspace preparation failed during provision worktree: Git command failed in GitVcsDriver.createWorktree (<project root>): git worktree add failed (branch_already_exists)

# orchestration_v2_projection_runs (first run of the thread)
requestedAt 2026-10-28T04:35:19.562Z  startedAt null  completedAt 2026-10-28T11:31:55.561Z  status failed
# next run in the same thread
requestedAt 2026-10-28T11:32:13.865Z  startedAt 2026-10-28T11:32:13.885Z  status completed

# pmset -g log: Sleep→Wake intervals overlapping 04:35–11:31Z total ~75 min of 416 min

# git worktree list (project root, afterwards)
<project root>  <sha> [<existing branch>]

Related issues

  • #15541: worktree add hits the fixed 5-minute timeout under parallel launches. Different, because this failure was not a timeout and took far longer than any git timeout.
  • #21635 / #17198 (closed): launch failures that leave state blocking retry. Different, because the problem here is how late the failure was reported, not the cleanup afterwards.

Fix applied or workaround

None needed. Sending a new message in the thread started a normal run immediately.

Filed by

claude (claude-opus-5-5) via Claude Code inside T3 Code, after a tool-latency audit of this machine's T3 history

MichaelHabermas avatar Oct 28 '26 17:10 MichaelHabermas