Skip to content

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

Backlog

Description

@SamuelZ12

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions