Skip to content

[Bug]: Automatically pull runs ~45 git commands every 40 s across 8 projects, mostly when there is nothing to pull #45610

Done

Description

@offchan42

Steps to reproduce

  1. On Windows, add several projects. Mine are 4 Git repositories with an origin remote (300, 611, 2,837 and 33,819 tracked files) and 4 folders that are not repositories.
  2. Turn Automatically pull on, with the default 30 s automatic fetch interval.
  3. Leave the server running for a while.
  4. Count the Git commands under each autoPullProjects span in the server trace logs:
# python count.py <T3 data dir>/userdata/logs
import collections, glob, json, sys
spans = {}
for f in glob.glob(sys.argv[1] + "/server.trace.ndjson*"):
    for line in open(f, encoding="utf-8", errors="replace"):
        try: d = json.loads(line)
        except ValueError: continue
        spans[d["spanId"]] = d
passes = collections.Counter()
for d in spans.values():
    if d["name"] != "runGitCommand": continue
    p = d.get("parentSpanId")
    while p in spans and spans[p]["name"] != "autoPullProjects":
        p = spans[p].get("parentSpanId")
    if p in spans: passes[p] += 1
n = sorted(passes.values())
print(len(n), "auto-pull passes, median git commands per pass:", n[len(n) // 2])

Expected behavior

A project that is already up to date costs close to nothing per pass: a fetch and one cheap check of whether it is behind.

Actual behavior

Over 129 full minutes on 2026-11-29, on a machine in active use with agents running (the stretch in my logs during which the auto-pull loop was running; it stopped afterwards, consistent with its pause on a constrained host such as a locked screen, which I did not record):

Measure Value
Git commands the server ran, all causes 16,685 (median 122/min, p90 198, max 273)
…from the auto-pull loop 51.4%
…from status subscription polling 22.8%
…from pull request lookups 17.8%
…from checkpoints and other callers 8.1%
Auto-pull passes 185, median 40.3 s between starts (the 30 s wait plus a pass of about 10 s)
Git commands per pass (median) 45, over 8 projects
git status runs per pass / diff-index --numstat runs per pass 4 / 4
git pull runs in total, over all passes and projects 21

Where the work goes, from autoPullProjects in serverRuntimeStartup.ts:

  • Full status before the cheap answer. It calls statusDetails, which runs git status and git diff-index -M --numstat (among others), and only afterwards returns on behindCount <= 0. The numstat result is not used by auto-pull at all.
  • Folders that are not repositories are probed again every pass. Each of my 4 cost 3 Git commands per pass (12 of the 45).

Cost of status plus numstat alone, timed outside T3 with the same subcommands on the same 4 repositories (5 runs each, process CPU time): about 2.2 CPU-seconds per pass, of which 1.8 is the 33,819-file repository. Every command is also a new process on Windows (see #40140 for console hosts).

Proposed change

  1. In the auto-pull pass, after the fetch, check the cheap conditions first (current branch is the default branch, has an upstream, behind count > 0). Run the working tree check only for a project that is behind, and skip numstat.
  2. Remember that a project root is not a repository instead of probing it each pass, and re-check cheaply (for example, whether a .git entry has appeared).

Pull behaviour stays the same: the pass already returns without pulling when the project is not behind.

Trade-offs:

  • The "Skipped automatic project pull" debug log would no longer report working-tree-changes for a project with nothing to pull.
  • It needs a lighter path than the shared statusDetails, so the default-branch and upstream rules must not drift from it.

Not verified

  • Measured on one machine and one install, not reproduced on a fresh isolated server.
  • The CPU figure covers status and numstat only, measured with my own invocations rather than the server's environment.
  • I have not shown that this churn makes the UI lag. The CPU cost here is modest (under 1% of 16 hardware threads); the point is that most of it is avoidable work that grows with the number and size of projects.
  • The automatic fetches themselves are expected behaviour and are not part of this report.

Version and environment

Workaround

Turn Automatically pull off.

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