Skip to content

Every server start on Windows re-runs codex --version and codex app-server --help (8 processes, ~275 ms) although the Codex binary did not change #40142

Closed

Description

@juliusmarminge

What is slow

On every server start (and so every desktop app start), Codex's status waits for codex --version and then codex app-server --help before the app-server probe starts. On Windows with Codex installed through npm, each launch goes through the npm shim: cmd.exe, conhost.exe, node.exe codex.js, then codex.exe. That is 8 processes and ~275 ms per start, with the same answer every time. Refresh never repeats them, because the result is cached, but only in memory, so each restart pays again.

Measured

  • Windows Server 2025, 4 vCPU, Defender on. Commit b568fcbaa6, server from source. @openai/codex 0.17x installed with npm i -g. 6 projects / 18 threads seeded.
  • Spawn log over 8 server starts (6 warm starts of the production server, plus 2 dev starts): codex --version and codex app-server --help ran once each in 8 of 8 starts and in 0 of 6 Refresh clicks:
start --version app-server --help app-server probe started after --version started
2 140 ms 138 ms 816 ms
3 132 ms 140 ms 798 ms
4 135 ms 134 ms 779 ms
5 133 ms 140 ms 811 ms
6 137 ms 135 ms 816 ms

The first start after a Defender change took 630 ms for --version.

  • Event 4688 audit of 3 more starts: each start created cmd.exe /d /s /c "codex.CMD --version" → conhost.exe, node.exe …codex.js --version → codex.exe --version, and the same 4 processes for app-server --help.

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();

Start the server 6 times (stop it by its port between starts) and run the script below on the spawn log. Optionally confirm the process tree with an event 4688 audit (auditpol /set /subcategory:"Process Creation" /success:enable, then Get-WinEvent -FilterHashtable @{LogName='Security'; Id=4688; StartTime=<start>}).

// codexstart.cjs <spawn.ndjson>: per codex --version, the --help after it and when the app-server probe started
const L=require("fs").readFileSync(process.argv[2],"utf8").split("\n").flatMap(l=>{try{return[JSON.parse(l)]}catch{return[]}}).sort((a,b)=>a.at-b.at);
const s=o=>o.cmd+" "+o.args.join(" ");const v=L.filter(o=>/codex/i.test(s(o))&&/--version/.test(s(o))),h=L.filter(o=>/codex/i.test(s(o))&&/app-server\S* \S*--help/.test(s(o))),a=L.filter(o=>/codex/i.test(s(o))&&/thread_unload/.test(s(o)));
for(const x of v){const hh=h.find(o=>o.at>=x.at&&o.at<x.at+3000),aa=a.find(o=>o.at>=x.at&&o.at<x.at+5000);console.log(new Date(x.at).toISOString(),"version",x.ms,"help",hh&&hh.ms,"probe +"+(aa?aa.at-x.at:"?"))}
console.log("app-server probes",a.length,"version runs",v.length,"help runs",h.length);

Where the time goes

apps/server/src/provider/CodexInstallation.ts, resolveLocal. It computes a fingerprint of the resolved executable (realPath:size:mtime:ino) and looks it up in localCache, a Map created inside the layer. On a miss it runs runCommand(executablePath, ["--version"]) and then runCommand(executablePath, ["app-server", "--help"]), one after the other. The map starts empty in every server process, so the first resolve after each start always misses.

Why it is avoidable

The answer depends only on the executable, and the fingerprint already says whether it changed. Kept across restarts (next to the provider status cache), a warm start with an unchanged Codex has nothing to run.

What a fix has to show

The same 6 warm starts, before and after, with an unchanged Codex:

  • codex --version and codex app-server --help launches per warm start go from 1 + 1 (8 processes on an npm install) to 0. The app-server probe starts at least 250 ms sooner after the server starts.
  • What stays: both checks on the first start, and after Codex is installed, updated or replaced (any fingerprint change), with today's results for unsupported versions and a missing app-server. The managed-install path (resolveManaged) and Refresh behaviour do not change.

Found by the automated Windows performance sweep on b568fcb.


Found by the automated Windows performance sweep on b568fcb.

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