fix(server): worktree launches name their branch while the worktree is created #36904
main fromrefs/pull/36904/head·merged by juliusmarminge View on GitHubThreadLaunchService.prepareInBackground started generateBranchNameFor only after fetch and createWorktree finished, then joined the rename fiber before prepared-run.release, so the whole LLM call sat after checkout on the critical path. The fix forks the name generation (cwd = existing worktree path or the project root; cwd is only the CLI's working directory) as soon as preparation starts, under the same conditions the rename used (no reused worktree, an initial message, a worktree or existing_worktree strategy, a generated or temporary branch). After createWorktree the rename fiber joins that fiber instead of starting the call, so the LLM call overlaps fetch, checkout and the setup script. The join before release (#34781) is unchanged, so the agent still starts on its final branch name. If the launch fails or is cancelled before the rename takes the fiber over, or the late condition no longer holds, the naming fiber is interrupted, and the worktree cleanup path interrupts it alongside the rename fiber, so no stray codex exec is left running. Measured the triage way on this Linux VM: fresh unseeded vp run dev:server --no-seed, a one-commit repo, t3 thread start . '...' --worktree main --provider devReplay --model showcase --json 7 times each, span trees read from server.trace.ndjson. Main: prepareInBackground = 5392, 5419, 5763, 6087, 6190, 6262, 6501 ms (median 6087); generateBranchNameFor started at +114..+1148 ms; prepare time outside the LLM call 625-1280 ms. Fix: prepareInBackground = 4375, 4384, 4412, 4683, 5116, 5571, 6027 ms (median 4683); naming starts at +1..+12 ms; prepare time outside the LLM call 100-372 ms. Renames still landed (t3/add-readme-usage-* branches). The final commit differs from the measured build only in type annotations. What remains is the codex exec latency itself (about 4.2-5.6 s here), which the agent must wait for to start on its final branch; getting below a second would need a timeout that drops the generated name, an off mode, or a visible setup stage, all listed out of scope. No new regex or parser.
Fixes pingdotgg/t3code#36889
Reproduction on main#
Commit 9db3cb1091 (origin/main). Started T3CODE_DEV_SEED=0 vp run dev:server --home-dir <scratch> --no-seed (fresh DB, default settings: textGenerationModelSelection = codex / gpt-6.1-sol, branchNamingMode = static). Created a one-commit git repo, t3 project add ., then ran t3 thread start . 'Add a usage section to the README, take N' --worktree main --provider devReplay --model showcase --json 7 times (agent = free Replay provider; text generation = real Codex CLI through the account proxy). Read the ThreadLaunchService.prepareInBackground span trees from userdata/logs/server.trace.ndjson with a small parser. Results, automatic branch naming (n=7): generateBranchNameFor -> runCodexJson.runCodexCommand = 4224, 4266, 4292, 4303, 4350, 5158, 6191 ms (median 4303 ms); total prepareInBackground = 4730, 5006, 5048, 5401, 5414, 6180, 6665 ms (median 5401 ms); branch naming = 79-93% of prepare time. createWorktree 276-959 ms; renameBranch ~40 ms; naming starts only after createWorktree finishes (offsets 327-1012 ms). Baseline on the same server with a hand-picked branch (--branch manual-N, n=3): prepareInBackground = 456, 656, 939 ms (median 656 ms), no LLM call. A bare codex exec --skip-git-repo-check 'Reply with just: ok' with the same model took 5.4 s, so the cost is the codex exec path, not T3. Branch reflog confirmed the rename landed about 7 s after the branch was created. Confirmed in packages/contracts/src/worktreeSetup.ts that WorktreeSetupStageId has no branch-naming stage (fetch, checkout, submodules, setup-script, agent) and in settings.ts that BranchNamingMode is only static|semantic|custom.
Evidence#
Being captured: before and after in the real app. This section is filled in before the pull request can merge.
Tests#
vp test run src/orchestration-v2/ThreadLaunchService.test.ts: 64/64 pass. New case 'names a new worktree thread's branch while its worktree is being created' (createWorktree waits until generateBranchName has started): times out after 120 s with main's ThreadLaunchService.ts, passes with the fix. vp run typecheck (apps/server): clean. vp run check:changed: format, lint, knip, graphql, typecheck (3 packages) and tests (2 files) all pass.
Not in this change#
- A setup-tracker stage for the branch-naming wait (WorktreeSetupStageId has none): a visible UI and contract change.
- An off value for BranchNamingMode, or a time limit on the pre-release join that falls back to the temporary branch: a new option, or a trade against the feature #34781 protects.
- codex exec latency itself (about 4-5 s even for a bare prompt); CODEX_TIMEOUT_MS already caps the call, but much higher than a launch should wait.
Who did the work#
- Written by Claude Opus 5.5, in Claude Code
- Reviewed by GPT-6.1 Sol, in Codex, and by Claude Opus 5.5, each on its own
- Proof captured by GPT-6.1 Sol and checked by Claude Opus 5.5
Run by the t3code factory in T3 Code.