Skip to content
Source
Sign inSign up
pingdotgg/t3code

[Bug]: New worktree threads look up the same git dir 8 times before the agent starts #42550

OpenSamuelZ12(GitHub profile, opens in a new tab) opened this issue 0 comments

Area: apps/server

Steps to reproduce

  1. Start a server with a fresh base dir and add a small repo (here 1,602 tracked files): t3 serve --base-dir /tmp/sb --port 13991, then t3 project add --base-dir /tmp/sb <repo>.
  2. Launch worktree threads: t3 thread start --base-dir /tmp/sb --provider codex --model gpt-6-luna --worktree main . "Reply with just ok", five times.
  3. In server.trace.ndjson, list the runGitCommand spans inside each ThreadLaunchService.prepareInBackground.

Expected behavior

Preparation looks up the repository's common git dir once and reuses it, since it can't change during the launch.

Actual behavior

On 0.1.12-nightly.20261124.5209, each launch runs 34 git commands before the agent starts, one after another. 8 of them look up the same repository location (63 ms median over 5 launches, ~7 ms each, nearly all process start):

  • rev-parse --git-common-dir 5 times, from invalidateStatusStaticCaches (after the fetch and after the rename), createWorktree (the identity hash), releaseWorktreeRegistration and invalidateWorktreeCreationCaches. All call readGitCommonDir directly instead of the repository paths cache.
  • rev-parse --git-common-dir --show-toplevel 3 times, from writeConfigValue (twice) and renameBranch. These look like cache misses after invalidateListRefsSnapshot drops the repository paths entry.

listRemoteNames also runs twice (~6 ms each).

So 7 of the 8 lookups (~55 ms) repeat an answer the launch already had. On 0.1.11 it was 14 lookups and 121 ms; the layout read on main already merged part of it. The calls are unchanged on main as of 5e3bc17 (GitVcsDriverCore.ts).

Suggested fix

Read the common dir once at the start of preparation and pass it through createWorktree, releaseWorktreeRegistration and the two invalidation helpers (invalidateStatusStaticCaches already takes an optional gitCommonDir). The dir can't change during a launch, so this doesn't change behavior.

Impact: Minor bug or occasional failure Version: 0.1.12-nightly.20261124.5209 and 0.1.11 Environment: macOS (Apple silicon), Git 2.56.0 Workaround: none

  1. tanstack-source added labelsbug

Sign in to join this conversation.