Skip to content

perf(sandbox): run the Codex binary without its Node launcher - #4118

Merged
yannickmonney merged 2 commits into
mainfrom
perf/sandbox-codex-direct
Oct 3, 2026
Merged

yannickmonney merged 2 commits into
mainfrom
perf/sandbox-codex-direct

Conversation

@yannickmonney

Copy link
Copy Markdown
Contributor

Why

Codex installs from npm with a JavaScript launcher (bin/codex.js). It finds the native binary, spawns it, and then waits as its parent for the whole run, relaying signals and the exit status. That is a Node process — about 40 MB idle, ~60 ms to start — held for every Codex turn, doing nothing else.

What changes

  • /opt/agents/bin/codex is now a three-line shell launcher (services/sandbox-runtime/codex-launcher.in) that execs the native binary directly, with the environment the npm launcher sets: CODEX_MANAGED_BY_NPM=1 and CODEX_MANAGED_PACKAGE_ROOT (the package root's realpath). Signals now reach the binary itself, and its exit status is the launcher's.
  • The image build resolves the binary exactly the way codex.js does (the platform package @openai/codex-linux-{x64,arm64} beside the launcher, else the package's own vendor/), fails the build if it is not executable, and runs codex --version through the new launcher.

Gemini CLI and Qwen Code were checked too: Gemini relaunches itself only when its autoConfigureMemory setting is on (the staged settings leave it off), and Qwen's entry does more than relay (update pins, home resolution), so both stay as they are.

Verification

  • The launcher template was filled locally with stand-ins: arguments pass through unchanged, and the two variables are exported.
  • The image conformance test checks that codex on PATH is the direct launcher and still runs codex --version; CI's image build runs the resolution step itself. (Docker on the authoring machine is down, so CI is where the image step runs first.)

Follows #4116 and #4117.

Codex installs from npm with a JavaScript launcher (bin/codex.js) that
finds the native binary, spawns it, and then waits as its parent for the
whole run, relaying signals and the exit status: a Node process of about
40 MB and some 60 ms of start-up on every Codex turn, doing nothing else.

The image now puts a three-line shell launcher at /opt/agents/bin/codex
that execs the native binary directly, with the environment the npm
launcher sets (CODEX_MANAGED_BY_NPM, CODEX_MANAGED_PACKAGE_ROOT). The image
build resolves the binary the way that launcher does and fails if it is
missing; the conformance test checks the launcher and runs it.
The harness ledger row now says codex on PATH is the direct launcher, and that the image conformance test checks it and runs it.
@yannickmonney
yannickmonney force-pushed the perf/sandbox-codex-direct branch from 18439a5 to d04393b Compare October 3, 2026 08:44
@yannickmonney

Copy link
Copy Markdown
Contributor Author

Independent review of PR #4118 at d04393b96b3fa146126dd2f747d82fa46b43775d: accepted (LOW findings only). I reviewed the launcher change at 18439a517. Since then the PR was rebased onto df5be3397 (#4117), and its launcher, Dockerfile and conformance-test patches are byte-identical in content. The only new change is the manual-register row.

  • Reviewer: Tale agent update dashboard ui (#508) #2 3f9fdcee-79e7-430b-a430-ba179d5b5132, TALE-359 run 6b60fb49-b479-4eeb-850a-951812ec31f3.
  • Implementation: root's team on the shared principal; not a cycle agent, so this run is distinct.
  • Method: a source review by one read-only review agent, cross-checked by me. It compared against the pinned @openai/codex 0.142.5's bin/codex.js.

Verified correct

  • Binary resolution matches codex.js: the createRequire platform-package lookup with a vendor fallback, and the …-unknown-linux-musl/bin/codex path (Dockerfile:371-381).
  • Environment matches: the launcher sets the same managed-by variables, including the package root's realpath (codex-launcher.in:7-9).
  • No PATH change is lost: 0.142.5 sets no PATH, and the binary finds its bundled rg/bwrap relative to itself.
  • Arguments and signals: "$@" passes arguments verbatim, and exec replaces dash in the same pid, so Codex leads the exec's process group. Signal state is clean through runnerd (Node) and the exec shim.
  • Reaping doesn't depend on process names, and nothing matches a codex or node process.
  • The build fails loudly: test -x, codex --version through the new launcher, and the arm64 release runner.
  • The exit status after a signal is now 128+N rather than Node's 0, an improvement.

LOW

  1. The conformance assertion checks only the shebang. container-sandbox-runtime-test.ts:235-239 greps for #!/bin/sh, so a launcher that went back to exec node …/codex.js would still pass, as would one missing its environment.
    • Suggested check: the running Codex's /proc/<pid>/comm is codex, its environ carries CODEX_MANAGED_PACKAGE_ROOT, and the exec target starts with \177ELF.
    • The register row's ✅ rests on this check.
  2. The PR body's Gemini statement is wrong for the pinned 0.59.0. Gemini relaunches itself whenever GEMINI_CLI_NO_RELAUNCH and SANDBOX are both unset, which is every Tale turn, so its idle Node parent remains (bundle/gemini.js:65,76).
    • autoConfigureMemory only adds a heap flag.
    • Possible follow-up: GEMINI_CLI_NO_RELAUNCH=true in the wrapper, after checking what the relaunch parent's settings IPC is for.
  3. Drift on a Codex bump (a hypothesis). The build re-implements codex.js as it is today. A sha256sum -c of bin/codex.js in the same RUN, with a comment to re-check the launcher when it changes, would catch a new variable or PATH entry.

INFO

  • codex.js sets CODEX_MANAGED_BY_BUN under a bun user agent; the launcher always says NPM. It's used only for install and update diagnostics.
  • dash drops environment entries whose names aren't valid identifiers. Every platform producer uses valid names.

It merges once the exact-head checks are all green.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant