Skip to content

[Bug]: Server start runs a branch PR lookup per thread, not per (repo, branch): 67 lookups / 760 git processes on one repo, git calls up to 135 s on Windows #40761

Closed as not planned

Description

@OhadC

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/server

Steps to reproduce

  1. On Windows, have one project whose project-root threads (no worktree) share a few branches. Here: 109 threads on one branch (97 settled), about 8 branches overall. The install has 23 projects, 1741 live threads and about 70 git working dirs (projects plus kept worktrees).
  2. Start T3 Code (or restart it).
  3. Watch Task Manager, or count runGitCommand spans in server.trace.ndjson, for the first 2 minutes.

Expected behavior

A start costs about one branch PR lookup per (repo, branch). Settled threads don't trigger lookups at start. Git process count stays bounded, so the machine stays usable.

Actual behavior

CPU is pegged and Git for Windows is the top process in Task Manager. It stops as soon as T3 is closed. No agent turn was running: every active thread had reached end_turn.

From server.trace.ndjson*:

  • 1629 runGitCommand spans in about 20 minutes: 555 in the first minute after start, 760 in the second, then 7-25 per minute.
  • The first start after updating was worse: 1849 git and 291 PR lookups in 3 minutes, peaking at 953 git and 180 lookups in one minute.
  • Up to 14 git processes at once. Under that load a single git rev-parse or git worktree list took 50-135 s.
  • Git calls by entry point: branchPullRequest 675, server.startup 287, ws.rpc.subscribeVcsStatus 182, ws.rpc.vcs.refreshStatus 146, StorageCleanup.sweep 94.
  • The repo from step 1 got 67 branchPullRequest lookups in 2 minutes, which spawned 760 git processes, even though its threads are on only about 8 branches. Up to 21 of those lookups ran on that one repo at the same time, so they aren't coalesced.
  • Each lookup ran 5 git processes on average (between 1 and 9). Lookups took 7.6 s on average and up to 317 s.
  • Each lookup also calls the forge (the remote is Bitbucket Data Center): 102 BitbucketApi.listPullRequests calls in the same window.
  • Most lookups are root spans at start. The rest come from ThreadSettlementServiceV2.sweep and ThreadPullRequestServiceV2.synchronize.

So branch PR lookups seem to run per thread instead of per (cwd, branch), and settled threads still trigger them.

Related, not duplicates:

Impact

Major degradation or frequent failure

Version or commit

0.1.12-nightly.20261122.5085 (desktop, nightly channel). Updated that morning from 0.1.11-nightly.20261118.4877.

Environment

Windows 11, 12 cores / 24 threads, 48 GB RAM (not a slow machine), third-party endpoint protection (EDR) scanning every new process, T3 Code Desktop (nightly), git 2.55.0.windows.3, Bitbucket Data Center remote, Claude provider

Logs or stack traces

# runGitCommand / branchPullRequest spans per minute
# 0.1.11-nightly.20261118.4877, steady state (no server start within the retained logs)
~40-220 git/min, 0-7 PR lookups/min
# 0.1.12-nightly.20261122.5085, first start after the update
start+0: 476 git / 65 lookups   +1: 420 / 46   +2: 953 / 180   +3: 132 / 3
# 0.1.12-nightly.20261122.5085, restart 26 min later
start+0: 555 git / 73 lookups   +1: 760 / 58   +2: 2 / 0

# slowest single git calls (parent span -> duration)
GitVcsDriver.fetchRemoteForStatus          135 s
GitWorkflowService.currentBranch           101 s
GitWorkflowService.currentBranch           100 s
GitWorkflowService.currentBranch            88 s
GitVcsDriver.readWorktreeBranchPaths        72 s

# top call chains into runGitCommand
121 GitManager.readRemoteUrl <- resolveRemoteRepositoryContext <- resolveBranchHeadContext <- resolveLookupHeadContext <- lookupBranchPullRequest <- branchPullRequest
118 GitManager.branchPullRequest.branchRef <- GitManager.rememberPrLookupGitState <- lookupBranchPullRequest <- branchPullRequest
117 GitVcsDriver.readConfigValue <- resolveBranchHeadContext <- resolveLookupHeadContext <- lookupBranchPullRequest <- branchPullRequest

Workaround

None found except closing T3.

Activity

  1. OhadC commented on Nov 22, 2026

    @OhadC
    ContributorAuthor

    Source check against v0.1.12-nightly.20261122.5085 (done during a t3 triage session on the same machine):

    Correction to the original report: the settlement sweep already groups lookups by (cwd, branch). ThreadSettlementService.ts:500-518 (lookupKey / Map.groupBy) builds one group per branch-or-linked-PR key. So the per-thread fan-out described above comes from other branchPullRequest callers. Candidates:

    • ThreadPullRequestService.ts (lines 184, 314, 406)
    • the ws.rpc.subscribeVcsStatus / ws.rpc.vcs.refreshStatus status paths
    • storageCleanup.ts:1702

    I haven't confirmed which one dominates.

    Why concurrent lookups on one repo don't collapse (apps/server/src/git/GitManager.ts):

    • branchPullRequest (L3335) is limited only by a server-wide semaphore of 4 (BRANCH_PR_LOOKUP_CONCURRENCY, L228). Nothing merges callers asking about the same (cwd, branch) at the same time. Each one runs its own lookup.
    • rememberPrLookupGitState (L3014) caches git reads for 5 min, but has no in-flight dedup: N simultaneous misses on the same key run git N times. Any call with freshGitState: true skips the cache entirely.
    • settledPrLookupByBranchKey (L3052), the "closed/merged PR is final" memo, lives only in memory, so it's empty after every server start. On the first call after start, every branch with a closed or merged PR does a second lookup with freshGitState: true (L3369). This fits the burst being concentrated in the first 1–3 minutes after start, and being worst right after the update restart.
    • There's no setting to turn branch PR polling off, so the user has no workaround except closing T3.

    Possible directions:

    • Merge concurrent branchPullRequest calls into one per (cwd, branch).
    • Add in-flight dedup to rememberPrLookupGitState.
    • Persist or warm the settled-PR memo across restarts.

    Related: #28196. The trace volume on this machine (~10 MB per 5 min) matches it.

    Also, the bug / needs-triage labels from the bug-report form didn't get applied to this issue.

    Produced by Claude Code (Claude Opus 5.5) via t3 triage.

  2. OhadC commented on Nov 22, 2026

    @OhadC
    ContributorAuthor

    Closing: the sustained high CPU in this report wasn't caused by T3.

    While these traces were recorded, an agent session on the same machine was deliberately running a CPU stress test for an unrelated flaky-test investigation: a busy-loop script with 40-72 worker threads on a 24-thread CPU, plus looping vitest runs through Git for Windows' bash.exe. That's why CPU was pegged, why "Git for Windows" showed up in Task Manager, and why individual git calls took 50-135 s. The timings above are confounded and shouldn't be used.

    A clean restart with no agent load: T3 server used up to ~3.7 cores and up to 9 git.exe for about 45 s after start (23 projects, ~1,740 threads), then went idle. That startup cost is small, so I'm not pursuing it here.

    The source notes in my earlier comment (no in-flight dedup in branchPullRequest / rememberPrLookupGitState, closed-PR memo not kept across restarts) may still be worth a look as a startup-cost optimization, but they don't cause what this issue describes.

    Produced by Claude Code (Claude Opus 5.5) via t3 triage.

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