Skip to content
Source
Sign inSign up
pingdotgg/t3code

Server start on Windows launches 38 console hosts for read-only git commands that skip the console-free allowlist #40140

Openjuliusmarminge opened this issue 0 comments
juliusmarmingecommented

What is slow

Every git command the server runs on Windows gets its own console host (conhost.exe) unless its exact form is on a short allowlist. At each server start with 6 projects, 38 of the 56–57 git processes the server launches start a console host. That is 38 extra processes per start, all for commands that only read config or refs. The same forms run again in status polls, thread switches and PR lookups, so the cost repeats all day.

Measured

  • Windows Server 2025, 4 vCPU, 16 GB, Defender real-time scanning on. Commit b568fcbaa6, server from source, Git for Windows (ucrt64).
  • Seed: 6 projects, each a ~32k-file clone of this repository. 3 have origin on GitHub and 3 have no remote; each is on a feature-<i> branch with one commit. 18 finished threads.
  • Process creation audited with Windows event 4688 over the first 45 s of 3 warm starts. The result was the same in all 3:
per start
git processes started by the server56–57
…of which started a conhost.exe38 (3/3 starts)
…already console-free (remote, config --get branch.<b>.remote, config --get branch.<b>.merge)18–19

The 38, by form:

formcountspawn path
git -C <root> rev-parse --show-toplevel6RepositoryIdentityResolver → ProcessRunner.run
git -C <root> remote -v6same
git -C <root> config --get-regexp ^remote\..*\.gh-resolved$6same
config --get-all remote.origin.url6GitVcsDriverCore
rev-parse --verify --quiet --symbolic-full-name refs/remotes/origin/HEAD4GitVcsDriverCore
for-each-ref --format=… refs/heads/<b>4GitVcsDriverCore
for-each-ref --format=… refs/heads/<b> refs/remotes/origin/<b>2GitVcsDriverCore
for-each-ref --format=… refs/remotes/origin/<b>2GitVcsDriverCore
for-each-ref --count=1 --format=… refs/remotes2GitVcsDriverCore

How to measure it again

Setup (Windows, fresh machine)

  1. Check out the commit, run vp i, then cd apps/web && vp build. Install the provider CLIs: npm i -g @openai/codex @anthropic-ai/claude-code. Put npm prefix -g on PATH for the server.
  2. Seed 6 projects of ~32k files each: git clone --local <a t3code checkout> p<i> for i = 0..5. For p0–p2, set origin to https://github.com/pingdotgg/t3code.git, git fetch origin main and git branch -u origin/main main. For p3–p5, run git remote remove origin. In every repo, check out feature-<i> and commit one file.
  3. From apps/server, start a seeding server: T3CODE_DEV_SEED=0 node src/bin.ts serve --base-dir H --port 4800 --host 127.0.0.1 --dev-url http://localhost:5733. For each repo, run node src/bin.ts project add <repo> --base-dir H and then 3× node src/bin.ts thread start --base-dir H --provider devReplay --model todo-list --wait --json <projectId> "task". Stop the server.
  4. Start the measured server without --dev-url, with Defender real-time scanning on and no exclusion: T3CODE_DEV_SEED=0 SPAWNLOG=spawn.ndjson node --require ./spawnlog.cjs src/bin.ts serve --base-dir H --port 4800 --host 127.0.0.1. Discard the first start after a Defender change, because it is a cold scan.
// spawnlog.cjs: logs every child process the server starts (pid, args, start epoch, duration, exit code)
const cp = require('child_process'); const fs = require('fs'); const out = process.env.SPAWNLOG || 'spawn.ndjson'; const main = require('worker_threads').isMainThread;
const log = (o) => { try { fs.appendFileSync(out, JSON.stringify(o) + '\n'); } catch {} };
for (const name of ['spawn', 'execFile', 'exec', 'fork']) { const orig = cp[name]; cp[name] = function (...a) { const t0 = Date.now(); const c = orig.apply(this, a);
  c.once && c.once('exit', (code) => log({ k: name, main, pid: c.pid, cmd: String(a[0]), args: Array.isArray(a[1]) ? a[1].map(String) : [], at: t0, ms: Date.now() - t0, code })); return c; }; }
require('module').syncBuiltinESMExports();

Turn on process-creation auditing (auditpol /set /subcategory:"Process Creation" /success:enable and the registry value HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System\Audit\ProcessCreationIncludeCmdLine_Enabled=1). Then run this script 3 times. Its serve.cmd holds the step 4 command.

# audstart.ps1: start the server, wait 45 s, dump every process created (event 4688) since the start
$t0 = Get-Date
Invoke-CimMethod -ClassName Win32_Process -MethodName Create -Arguments @{ CommandLine = "cmd.exe /c $PSScriptRoot\serve.cmd" } | Out-Null
Start-Sleep 45
$rows = foreach ($x in Get-WinEvent -FilterHashtable @{LogName='Security'; Id=4688; StartTime=$t0}) { $d=@{}; ([xml]$x.ToXml()).Event.EventData.Data | % { $d[$_.Name]=$_.'#text' }
  [pscustomobject]@{ t=$x.TimeCreated.ToString('o'); pid=[Convert]::ToInt32($d.NewProcessId,16); ppid=[Convert]::ToInt32($d.ProcessId,16); name=$d.NewProcessName; parent=$d.ParentProcessName; cl=$d.CommandLine } }
$rows | ConvertTo-Json | Set-Content "$PSScriptRoot\aud-start.json"
foreach($p in (Get-NetTCPConnection -LocalPort 4800 -State Listen).OwningProcess){ Stop-Process -Id $p -Force }
// gitconhost.cjs <aud-start.json>: server git processes, and which ones got a conhost child
const a=[].concat(JSON.parse(require("fs").readFileSync(process.argv[2],"utf8").replace(/^\uFEFF/,""))).sort((x,y)=>x.t.localeCompare(y.t));
const g=a.filter(e=>/\\bin\\git\.exe$/.test(e.name)&&/node\.exe$/.test(e.parent||""));const res={};let n=0;
for(const e of g){const c=a.some(x=>x.ppid===e.pid&&/conhost/.test(x.name)&&x.t>=e.t&&Date.parse(x.t)-Date.parse(e.t)<2000);if(c)n++;
  const k=(c?"CONHOST ":"none    ")+(e.cl||"").replace(/^"[^"]*"\s*/,"").replace(/C:\S+/g,"<path>").slice(0,110);res[k]=(res[k]||0)+1}
console.log("server git",g.length,"with conhost",n);for(const [k,v] of Object.entries(res).sort())console.log(v,k);

Where the time goes

  • packages/shared/src/shell.ts, runsGitWithoutConsole / CONSOLE_FREE_GIT_READS (from #19288). Only exact forms on the list spawn with detached: true, windowsHide: true, which starts no console host. The list has rev-parse --show-toplevel, remote, config --get * and a few more. It does not have config --get-all *, config --get-regexp *, remote -v, for-each-ref … or rev-parse --verify --quiet --symbolic-full-name *. It strips a leading --git-dir <dir> but not -C <dir>.
  • Only apps/server/src/vcs/GitVcsDriverCore.ts (the spawn in executeGit, forceKillAfter: "1 second" block) consults it. apps/server/src/project/RepositoryIdentityResolver.ts (resolveCacheKey, resolveFromCacheKey) runs git through apps/server/src/processRunner.ts run, which never sets detached. So its 3 reads per project always get a console, even rev-parse --show-toplevel, which is on the list.

Why it is avoidable

Every form in the table reads config or refs only. It starts no hook, helper, pager, editor or lazy fetch, which is the property the allowlist exists for. They get a console host only because the list is narrower than the read forms the server actually runs, and because the identity resolver bypasses it.

What a fix has to show

The same audited start, 3 times before and after, on the same seed:

  • Console hosts under server git processes per warm start drop from 38 to 0 for the forms in the table: identity reads 18 → 0 and driver reads 20 → 0. Total processes per start drop by 38.
  • What stays: the git processes themselves (their number is #40089's and #39984's to reduce; count them separately) and a console for git forms that can start a hook, helper, credential prompt or pager (fetch, push, commit, worktree add, status).
  • Results and error handling of the identity resolver and the driver reads do not change.

Found by the automated Windows performance sweep on b568fcbaa6.


Found by the automated Windows performance sweep on b568fcbaa6.

  1. tanstack-source added labelsbug

Sign in to join this conversation.