[Bug]: New worktree threads look up the same git dir 8 times before the agent starts #42550
Area: apps/server
Steps to reproduce#
- 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, thent3 project add --base-dir /tmp/sb <repo>. - Launch worktree threads:
t3 thread start --base-dir /tmp/sb --provider codex --model gpt-6-luna --worktree main . "Reply with just ok", five times. - In
server.trace.ndjson, list therunGitCommandspans inside eachThreadLaunchService.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-dir5 times, frominvalidateStatusStaticCaches(after the fetch and after the rename),createWorktree(theidentityhash),releaseWorktreeRegistrationandinvalidateWorktreeCreationCaches. All callreadGitCommonDirdirectly instead of the repository paths cache.rev-parse --git-common-dir --show-toplevel3 times, fromwriteConfigValue(twice) andrenameBranch. These look like cache misses afterinvalidateListRefsSnapshotdrops 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
tanstack-source added labelsbug
Sign in to join this conversation.