Skip to content

refactor(codex): run sandboxed Codex without the task image's Python - #5153

Merged
yaoyu-33 merged 72 commits into
mainfrom
refactor/codex-bash-runner
Nov 6, 2026
Merged

yaoyu-33 merged 72 commits into
mainfrom
refactor/codex-bash-runner

Conversation

@yaoyu-33

@yaoyu-33 yaoyu-33 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Stack: this PR → #5327. #5151 and #5152 are merged. This PR replaces #5148 and moves Codex to Bash/Node; #5327 separately removes the now-unused shared stdlib_runner compatibility API.

What

Codex was the last CLI harness whose sandbox worker ran on the task image's python3. This moves it onto the shared bash runner, so no sandboxed CLI harness needs Python in the task image any more.

  • Codex now starts through harness_runner.sh, like Claude Code, OpenCode, Kilo, OpenClaw and Pi. The runner supplies the prompt on stdin, stamps stdout as events, keeps stderr and writes runtime.json.
  • The sandbox-local HTTP 429 retry proxy moves from Python to sandbox_launcher.mjs, which runs on the Node 22.19.0 that the Codex runtime already installs. It starts the forwarder on a loopback port, then starts Codex with -c model_providers.gym.base_url=<forwarder>.
  • The native-session snapshot (native_session.jsonl) moves to the same launcher (--snapshot).
  • The bootstrap no longer installs python3, and the workdir overlap check is POSIX sh. The installer drops its Python version assertion and its ctypes libstdc++ probe, replaced by a private Node execution probe that honors musl's configured library search paths.
  • The shared stdlib_runner compatibility path and its tests remain available in this PR. Codex no longer uses it; the API removal is isolated in refactor(sandbox): remove unused stdlib runner compatibility #5327.
Piece Before After
Codex worker sandbox_runner.py on the task image's python3 (≥ 3.8), run as bin/gym-runner shared harness_runner.sh
429 retry proxy sandbox_transport.py (stdlib http.server + urllib) sandbox_launcher.mjs on the runtime's Node
Native-session snapshot python3 sandbox_runner --snapshot node sandbox_launcher.mjs --snapshot
Bootstrap installs missing python3 and bash; overlap check with python3 -c installs a missing bash; POSIX sh overlap check
Installer asserts Python ≥ 3.8; ctypes libstdc++ probe on musl no Python; probe the private Node runtime using musl's loader, bootstrap missing libraries, and privately repair incompatible ones

Why

@hemildesai asked to move the remaining harnesses off the task image's Python as a follow-up to #5151. Codex was the only CLI harness left. The Python harnesses are covered separately:

No separate issue: this follows the review discussion on #5094.

Behaviour kept from the Python worker

The launcher keeps the Python worker's behaviour in all of these:

  • Retries. A 429 is retried twice. A numeric Retry-After is honoured, clamped to [0, 30] s. A non-numeric or non-finite value backs off 1 s, then 2 s.
  • Attempt records. Every upstream attempt is written to model_attempts.jsonl:
    • the status;
    • status: null plus the error when the connection fails; the forwarder then answers 502;
    • transport_error when the upstream body is cut short or times out.
  • Header rewrite. x-session-id is replaced with the invocation ID.
  • Environment. Codex gets the same allowlist (PATH, LANG, LC_ALL, HOME, XDG_*, NEMO_GYM_SUPERVISOR) plus the adapter's variables. The runner drops a task NODE_OPTIONS before the launcher starts, the way python3 -I ignored PYTHON* variables.
  • Stops. TERM is passed on to Codex, so a stopped Codex can still flush its last events.
  • Exit status. The launcher exits with Codex's status as a shell would: 128+N when signal N killed it, 127 when Codex cannot be started.

Two differences, both deliberate:

  • One connection per attempt. The forwarder opens a fresh upstream connection per attempt (agent: false), like urlopen did. Node, unlike urllib, ignores http_proxy, which Codex itself never saw either.
  • Line splitting in the snapshot. The snapshot splits lines only at \n, \r\n and \r. Python's splitlines() also split at U+2028 and similar characters, which JSON may contain unescaped inside a string, and so could break a native-session record in two.

Compatibility

  • Task images for Codex need bash and no longer need Python. Images without bash get it from apt-get or apk when running as root, as before.
  • SandboxCommand(stdlib_runner=...), supervised_launch_command(stdlib_runner=...), RUNNER_FILE, and RUNNER_INTERPRETER remain compatible here. Their removal and the migration guidance are in refactor(sandbox): remove unused stdlib runner compatibility #5327. New adapters should use the shared Bash runner or an explicit adapter-managed Python interpreter.
  • HarnessProcessInfo.python (Codex) is removed; runtime.json now comes from the runner and carries hostname and pid.
  • No benchmark-result impact expected: Codex's model calls, retries and outputs are unchanged.

Tests

  • Ported. test_sandbox_runner.py now runs a staged activation through the real supervisor, runner and launcher. It covers:
    • stdin and events;
    • the environment allowlist and the dropped NODE_OPTIONS;
    • services that outlive a natural exit, a timeout or a stop;
    • TERM reaching Codex;
    • the receipt status for exit 7, a TERM death (143) and a missing binary (127);
    • the stop fence.
  • New. test_sandbox_launcher.py tests the forwarder against real HTTP servers:
    • which statuses are retried, and that every attempt is recorded;
    • Retry-After parsing;
    • a refused connection;
    • a cut-short body: timeout, truncated chunked body, truncated Content-Length body;
    • the end-to-end launcher;
    • snapshot path order and line splitting.
  • CI coverage. CI's test container has no Node, which would make all of these skip. So codex_agent/tests/conftest.py installs Node at collection on Linux through a new setup_codex.ensure_node(), which reuses the existing local-mode Node installer, and the install directory is gitignored.
  • Compatibility tests. The existing shared stdlib_runner tests remain until refactor(sandbox): remove unused stdlib runner compatibility #5327. Codex's mocked cleanup receipts now use the Bash supervisor's signal exit statuses, 137/143, instead of old Python subprocess statuses.

Validation

Review fixes at 5e6211de9, on top of the merge of main with #5152 squash-merged (f444027ad):

  • Records split on the host. The snapshot already keeps a native-session record that contains U+2028, U+2029 or U+0085 intact. But parse_codex_observations and parse_codex_usage still used str.splitlines(), so the host split the record again and lost the tool output. They now split only at \n, \r\n and \r, as the snapshot does.
  • Deeply nested event line. The bash runner copies every stdout line that starts with {. A line nested too deeply to parse now gets skipped on the host, as the Python worker did in the sandbox. Before this fix, its RecursionError failed the response.
  • Abandoned model stream. If Codex hung up while the forwarder waited for upstream headers, the forwarder never cancelled the upstream stream and never recorded the attempt. It now cancels the stream and records it.
  • Symlinked launcher path. The main-module check compared Node's real path with the path given on the command line. Under a symlinked session directory (for example a task image whose /tmp is a symlink), the launcher skipped Codex and the snapshot and exited 0. It now compares real paths.
  • Long rollout files. The snapshot no longer spreads each file into Array.push, which overflowed the call stack at about 150k lines.

Each fix has a regression test that fails on f444027ad.

  • macOS: Codex suite plus the shared runner and supervisor tests, 562 passed and 66 skipped (Linux-only). The one failure is the OpenSandbox SDK check, which fails the same way on f444027ad because the local venv lacks opensandbox.
  • Linux (Node 22.15): Codex suite plus the runner, process-supervisor and sandbox-session tests, 674 passed. The 6 skips are the streaming tests that need CODEX_TEST_BIN.
  • pre-commit run --all-files: passed.

No new model rollouts: these fixes change host parsing and launcher edge cases. Model calls, retries and outputs are unchanged.

Earlier fix at 9bc9afd8e: a nonroot musl image can provide libstdc++ through a custom loader search path. Fixed-directory detection previously rejected it. The installer now probes Node and distinguishes a missing library from an older library that can use the existing private repair.

  • Linux: pytest responses_api_agents/codex_agent/tests/test_install_runtime.py responses_api_agents/codex_agent/tests/test_bootstrap.py with the existing venv, verified checkout imports, explicit async plugin and no cache/coverage addopts: 31 passed.
  • The runnable-Node regression failed for both root and nonroot cases on the unchanged installer before the fix.
  • Real Docker reproduction on Alpine 3.20 and Alpine 3.16, UID 1000, with libstdc++ moved to /opt/task-libs and configured through /etc/ld-musl-x86_64.path: the old installer fails requesting root; the fixed installer completes with Node 22.19.0 and Codex CLI 0.144.4. Alpine 3.16 exercises the checksum-verified private-library repair. Default library locations remain untouched.
  • Missing libstdc++/libgcc and old-library checksum behavior are covered for root/nonroot execution. Independent review of the fix found no remaining issue.
  • pre-commit run --all-files and bash -n responses_api_agents/codex_agent/install_codex_runtime.sh: passed.
  • These are real runtime installation checks, not new model rollouts; model interaction and verifier behavior are unchanged by this installer fix. Prior real-model evidence remains below.

Prior split validation:

At 988a8ed5b, with the current #5152 head 87ff060b3 included:

  • Targeted Codex and shared sandbox regression tests: 418 passed, 49 skipped. All skips are Linux-only process/sandbox contracts on this macOS host. The HTTP proxy tests ran against real localhost servers.
  • pre-commit run --all-files: passed.
  • cd fern && npm run check: passed, zero errors and one warning.
  • Independent review confirmed that the shared compatibility API and its tests remain intact. The two split PRs together have exactly the same tree as the cleaned-up implementation plus the updated parent.

Test selection (existing development venv, plugin autoload disabled, async plugin loaded explicitly, source imports verified against this checkout):

pytest -p pytest_asyncio.plugin -p no:cacheprovider -o addopts='' -o log_cli=false -q \
  responses_api_agents/codex_agent/tests/test_sandbox_launcher.py \
  responses_api_agents/codex_agent/tests/test_bootstrap.py \
  responses_api_agents/codex_agent/tests/test_install_runtime.py \
  responses_api_agents/codex_agent/tests/test_exec_transport.py \
  responses_api_agents/codex_agent/tests/test_sandbox_sessions.py \
  responses_api_agents/codex_agent/tests/test_sandbox_runner.py \
  tests/unit_tests/test_sandbox_supervisor_bootstrap.py \
  tests/unit_tests/test_sandbox_supervisor_client.py \
  tests/unit_tests/test_sandbox_session.py \
  tests/unit_tests/test_harness_runner.py

Earlier validation, before the split:

  • At bedf8f76d, regression tests cover Unicode line separators in events and retrying a 429 whose body breaks; both fail on the previous implementation. Codex suite: 324 passed on macOS and 363 on Linux.
  • Linux workstation at the merge with refactor(agent_utils): run sandboxed harnesses with only bash in the task image #5151's 05bac0530: Codex/shared suites plus test_process_supervisor.py had 508 passed, 6 skipped.
  • Real Codex CLI with a scripted model endpoint passed on Debian and Alpine without installing Python: attempts [429, 200], confirmed exit 0, and native transcript collected.

Real-model rollout evidence: Codex 0.144.4 smoke rollouts at bedf8f76d with nvidia/nemotron-3.5-lightning-30b-a3b passed on debian:bookworm-slim, a SWE-bench image with Python 3.6 first on PATH, and alpine:3.20. Each run created a tool-made deliverable verified after a confirmed close; task HOME/XDG files survived and no Python was installed. These are prior rollout results, not fresh runs at 988a8ed5b. The split adds no new Codex runtime behavior.

🤖 Generated with Claude Code; split and follow-up validation with Codex.

hemildesai and others added 30 commits October 26, 2026 15:04
The supervisor uploaded into task sandboxes now needs only bash, /proc, sleep and mv, so
sandboxed harnesses no longer require Python 3.8+ in the task image. It keeps the CLI and
receipt contract: run the harness in its own process group, stop it at the deadline or
when the stop file appears (TERM, then KILL the group), and confirm no group member runs.

Stops now reach the supervisor through stop.request instead of SIGTERM, so the launch
shell no longer ignores TERM and the harness keeps the default disposition. Shared
receipt types and timeouts move to supervisor_client; SandboxCommand drops its python
field. shell_assignments() renders runner inputs as bash source.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Hemil Desai <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
harness_runner.sh replaces per-harness Python runners: it sources the PARAMS written by
shell_assignments(), records runtime.json, applies the harness environment and runs the
CLI with file-backed stdio. With events set, it stamps each JSON stdout line with the time
it was seen, reading a file so a detached tool holding stdout cannot stall it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Hemil Desai <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
…rmes tests

Point the harness guide, package docs and SandboxSession docstring at process_supervisor.sh
and harness_runner.sh, drop the Python-in-sandbox requirement and the subreaper drain the
bash supervisor no longer performs. Hermes tests use the bash supervisor. The runner stamps
a final unterminated event line with the same fallback time as the others on bash < 5.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Hemil Desai <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Hemil Desai <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
Kilo sessions now run through the shared bash harness runner with PARAMS
written by shell_assignments(); sandbox_runner.py is gone. A short setup
string removes a stale plugin receipt and records the task's HOME/XDG for
the task-environment plugin, unset_env drops inherited KILO_*/OPENCODE_*/
OpenAI variables, and the exit code comes from the cleanup receipt.
Path checks are POSIX shell, the bootstrap installs only bash, and the
installer drops its Python checks. The SQLite snapshot moves host-side:
kilo.db and its WAL files are downloaded and backed up locally.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Hemil Desai <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
…ndbox

Claude sessions now launch through the shared bash harness_runner.sh with params.sh instead of
sandbox_runner.py and input.json. The offline runtime installer is a bash script with the same
SHA-256, version and lock semantics, so task images need bash and coreutils but no Python.

Signed-off-by: Hemil Desai <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
Launch OpenClaw through the shared bash harness_runner.sh with PARAMS from shell_assignments()
and a staged prompt file, replacing sandbox_runner.py. The workdir overlap check is POSIX sh,
session setup installs only a missing bash, and the runtime installer drops its Python checks
(apk now reports whether musl images have libstdc++; the prepare step already guards the
runtime path against the task workdir).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Hemil Desai <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
Task images now need only bash. The shared harness_runner.sh replaces
sandbox_runner.py: PARAMS carry the CLI argv, environment and stdio files, and a
short setup records the task HOME/XDG directories for the shell.env hook, removes
a stale initialization receipt and creates the private CLI directories.

The SQLite snapshot moves to the agent server: after confirmed cleanup the adapter
downloads opencode.db (and its -wal/-shm files when present) and runs the same
export there, producing the same export.json and observations.db. The bootstrap
no longer installs python3 and checks workdir overlap with POSIX shell, and the
runtime installer serializes with flock, or a reclaimable lock directory without it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Hemil Desai <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
Pi now runs under the shared bash harness runner: the adapter stages params.sh
and prompt.txt, and the runner records [seen_at, event] lines. Session setup no
longer installs python3, the runtime installer checks for the musl C++ library
by path instead of with ctypes, and the host parser skips recorded lines that
are not [number, object] records.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Hemil Desai <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
…available

A missing or undownloadable session database again leaves no export, so
collection reports "OpenCode sandbox runner returned no valid result" with the
output log, as when export.json was missing before. The export no longer depends
on copying the observation store: a failed copy, like the failed observations.db
download before, only adds observation gaps.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Hemil Desai <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Hemil Desai <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
The bash supervisor no longer takes an interpreter, so NOOA drops the removed
SandboxCommand.python field (its own pinned Python still runs its worker), and
the Codex worker keeps its Python runner under the bash supervisor: its
sandbox-local 429 retry proxy still needs Python. OpenCode drops
sandbox_python_executable; sandbox_path_prefix now reaches the CLI through the
runner setup. Tests and READMEs name process_supervisor.sh.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
… runner names

On bash < 4.2 printf has no strftime, so every event was stamped with an empty
time and the host parsers dropped them all; fall back to date. Strip a trailing
CR before recording a JSON line. Inherited variables named like runner PARAMS
(setup, events, stdout, ...) no longer configure the runner or leak into the CLI.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
…he bash supervisor

A stopped CLI's tools that run in their own session (OpenCode and Codex start every
shell tool that way) kept writing to the task after a confirmed receipt. Before
stopping the harness, the supervisor now records its descendants outside its
process group from /proc and kills them, and the groups they lead, with the
harness; confirmation waits for them too. Services orphaned before the stop are
still left for the sandbox owner.

The supervisor also:
- reads each /proc/PID/stat whole and never evaluates its fields as arithmetic, so
  a process name holding a newline cannot run code or hide a group member;
- refuses to launch without a readable /proc, and counts unreadable process
  state as running;
- bounds the wait for a KILLed harness and writes a negative receipt instead;
- exits on a missing option value or separator instead of looping or running part
  of the command, and ignores an inherited errexit.

Launches render fixed-point seconds, and a deadline shorter than the supervisor's
centisecond resolution expires before launch instead of leaving no receipt.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
…runner descriptors

Without job control bash starts an async command with INT and QUIT ignored, and
the CLI's tools inherited that. The CLI also inherited the runner's read and
events descriptors, so a tool could write raw lines into events.jsonl. Reset the
two signals (bash 5 honours the reset) and close both descriptors for the CLI.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
…e to older bash

Without flock, the Claude installer never reclaimed the lock of a killed
installer, and OpenCode's reclaim could delete a lock another installer had just
taken (or skip an owner killed before it wrote its PID). Both now take a symlink
that names the owner by PID and start time, and remove a dead owner's lock only
under a second lock after re-reading it.

The Claude installer lowercases the trusted digest without bash 4 expansions.
The Pi installer no longer fails under set -u on bash < 4.4 when it needs no
packages, and checks every default musl library directory for libstdc++.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
sqlite3's context manager commits but does not close, so a failed export kept the
copied databases open while the snapshot directory was removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
…wn sessions

The receipt docstring, the harness guide and the Codex, Pi, OpenCode, OpenClaw,
Hermes and Terminal-Bench READMEs now describe what the bash supervisor does:
it kills the harness group and, after a forced stop, the descendants that ran in
other process groups when the stop began; processes that left the harness
earlier stay with the sandbox owner. The receipt documents shell exit statuses.
The Kilo and local-provider tests cover a tool in its own session again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
… stop test

shell_assignments() now raises for NUL and non-string words, which bash would
silently drop or which raised an opaque TypeError. The Hermes close test stops
the supervisor through the stop file alone, as production does, and the
sandboxed Hermes README states that the supervisor needs the task image's bash.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
…completed tools

The bash port's tests asserted that a tool still running in its own session
survives a close, and modelled a completed tool's service as a direct child of
the CLI. With the supervisor's stop-time cleanup, an in-flight detached tool is
stopped again, as before the port; a service left by a tool that already exited
still survives.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
The harness guide said Codex starts its CLI through harness_runner.sh. On main
Codex keeps its Python sandbox_runner.py for its sandbox-local retry proxy, so it
still needs the task image's Python; Hermes, Stirrup and NOOA run their Python
shims on interpreters they install privately.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
…sandbox-runtime

# Conflicts:
#	responses_api_agents/hermes_agent/tests/test_sandbox.py
Resolve the conflicts with #4805, which hid the Python supervisor and opted-in
Python runners from `pkill python` by running them through interpreter links.
The supervisor here is bash, so its link is dropped. Its runner link survives as
SandboxCommand.stdlib_runner on the bash launch: Codex, the one harness that
keeps a standard-library Python runner, runs it as bin/gym-runner from
`sandbox_runner`. OpenCode, OpenClaw, Pi and Kilo keep the bash runner, whose
name never mentions python. The pkill and delayed-launch tests follow the bash
supervisor; the READMEs and the harness guide describe the result.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
…afe task dirs

Address review findings on the bash runtime:
- Without flock, the OpenCode and Claude installers now queue on numbered
  owner links that are never removed or reused, and skip a number whose
  owner is done or gone. There is no second reclaim lock left to strand, and
  an installer killed at any point cannot block or release another.
- A preinstalled OpenCode binary must exit successfully from --version, not
  only print the version, before it replaces the cached runtime.
- OpenCode's and Kilo's task-env.json writers escape every JSON control
  character, so task HOME/XDG paths with tabs or newlines stay valid JSON.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
…l-name tests

The pkill tests merged from main called payload() with a timeout, which only
the Python runner's input carried; the bash runner takes its timeout from
execute().

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
The pkill test from main assumed the supervisor's only child is the runner. The
bash supervisor also forks its polling sleeps, so take the runner as the parent
of the tool it started and check that it is a supervisor child.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
Review found that one descendant snapshot before TERM let a confirmed receipt
leave processes running: a TERM handler that runs `setsid ... &` and exits, or
a tool that keeps forking new sessions during the grace period.

- The supervisor gives the harness a NEMO_GYM_SUPERVISOR environment marker
  unique to this run. On a forced stop it scans /proc when the stop begins, on
  every grace and drain round, and before the final KILL. It reaches the
  harness group, descendants of the harness, of its group and of reached
  processes, and processes carrying the marker. Marked processes that had
  already left the harness when the stop began are preserved as services, as
  the subreaper on main did. The Codex runner passes the marker through its
  env allowlist.
- A recorded group is killed or awaited only while its ID is free or still
  held by the recorded leader (same start time), so a reused group ID is not
  hit.
- Without a process group of its own, the supervisor restarts itself as a job
  in a new group, so a provider's group KILL cannot end it before the receipt.
  The shell left behind passes on TERM and the exit status.
- Docstrings and READMEs state what a forced stop reaches and what it does not.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
…statuses

- emit() strips a trailing CR without `${1%$'\r'}`, which tried the suffix at
  every position and took seconds per MB, long enough for Pi's agent_end event
  to outlast the deadline.
- The runner resets errexit, nounset, pipefail and IFS, so a BASH_ENV with
  `set -e` no longer stops it at the first non-JSON line.
- A failed exec redirection no longer falls through into events mode or
  launches the CLI. The runner exits 125 for its own failures (bad cwd, an
  exit in setup) and 126 or 127 when the CLI could not be started.
- Drop `trap - INT QUIT`: it did not change what the CLI inherits, and its test
  passed without it.
- Kilo tells runner failures apart from Kilo's own exit status, reports no exit
  code for a Kilo the runner never started, and none for a cancelled run.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
…e Code

- The OpenCode installer removes a partly staged binary from its single EXIT
  trap, however it exits, and a cached binary must exit successfully from
  --version to be reused.
- Claude Code setup installs a missing bash on root images with apk or
  apt-get, as the other bash-runner adapters do, and otherwise fails with a
  message that names bash instead of a bare 127.
- Reword "native" in the Claude installer docs, docstring and a test name.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
yaoyu-33 and others added 2 commits November 1, 2026 21:35
…ntime

main now checks import layering and moved paths. sandbox_python.py read
CACHE_DIR_KEY_NAME, maybe_get_global_config_dict and request through old
paths, and it and its test imported AsyncSandbox and SandboxSpec through
the nemo_gym.sandbox package. Import them from their current, defining
modules. uv_bootstrap is deleted on purpose, so drop it from the recorded
import surface.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
…ntime' into refactor/codex-bash-runner

Signed-off-by: yaoyu-33 <[email protected]>
@yaoyu-33

yaoyu-33 commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 2bfb748

giuliolovisotto
giuliolovisotto previously approved these changes Nov 2, 2026
yaoyu-33 and others added 2 commits November 2, 2026 20:36
…-bash-runner

main moved agent_utils and the agent base into nemo_gym.agents. The six
conflicts were import blocks and the add-harness checklist:
- Codex code and tests import through the nemo_gym.agents facade, as
  main does, with the runner names (HARNESS_RUNNER_FILE,
  HARNESS_RUNNER_SCRIPT, shell_assignments) in place of the Python
  worker's RUNNER_FILE, which this branch removes.
- The checklist keeps this branch's note that no built-in adapter uses
  stdlib_runner any more, naming its new module.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@yaoyu-33

yaoyu-33 commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test ce7c373

#5152 landed on main as a6cd35c with commits this branch had not seen.
Five conflicted files belong to #5152 (nemo_gym/agents/__init__.py,
sandbox_python.py, nemo_gym/sandbox/api.py, Stirrup's session tests and
test_sandbox_python.py); this branch does not change them, so main's
version stands. The harness guide is main's text with this branch's four
Codex edits: Codex starts through the runner and Node launcher, no
adapter depends on the task image's Python, stdlib_runner remains only
for existing shims, and the Codex launcher keeps the supervisor marker.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@yaoyu-33

yaoyu-33 commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test f444027

yaoyu-33 and others added 2 commits November 3, 2026 20:08
…eams

- Host parsing of native session records now splits lines only at \n, \r\n
  and \r, as the launcher's snapshot does. str.splitlines() also split at
  U+0085, U+2028 and U+2029, which Codex leaves unescaped inside JSON
  strings, so a tool output holding one lost its record and left tool
  timing unknown.
- The host now skips an event record nested too deeply to parse. The Python
  worker dropped such lines in the sandbox; the bash runner copies them
  verbatim, so the RecursionError failed the response.
- The forwarder now cancels the upstream request when Codex hung up while it
  waited for the response headers. The close listener was registered only
  after the headers arrived, so the abandoned stream ran to its end.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
…rollouts

- The launcher compared import.meta.url, which Node resolves to the real
  path, with the path it was started by. Under a symlinked session directory
  (a task image whose /tmp is a symlink) it skipped both Codex and the
  snapshot and exited 0, so every rollout failed without an explanation.
- The snapshot spread each rollout file into Array.push, which overflows the
  call stack on a file of a few hundred thousand lines and loses the
  native transcript.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@yaoyu-33

yaoyu-33 commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 5e6211d

main's #5309 taught the Python 429 forwarder (sandbox_transport.py) to
record compaction helper responses. This branch replaces that forwarder
with sandbox_launcher.mjs, so the merge drops the Python file and ports
the change to the launcher: a request whose x-codex-turn-metadata says
request_kind=compaction has its 200 SSE body buffered (up to 8 MiB,
forwarding unchanged), and one completed response's id and assistant
text are recorded as compaction_response in model_attempts.jsonl. The
tests move to test_sandbox_launcher.py, and observability.py's format
note points at the launcher.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@yaoyu-33

yaoyu-33 commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test e1f885f

The harness guide's adapter list conflicted: main now says framework
adapters list the framework in pyproject.toml (#4837), and this branch
says Codex starts through harness_runner.sh and sandbox_launcher.mjs.
Keep both.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@yaoyu-33

yaoyu-33 commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 9411714

Preserve the network policy and preinstalled runtime checks from main while keeping the Bash/Node launcher and removing task-image Python requirements. Keep the obsolete Python transport deleted and reconcile session test imports and runtime documentation.

Validation: 370 focused tests passed, 6 skipped; pre-commit run --all-files passed. No new model rollout: this merge preserves the existing harness and network-policy contracts.
Signed-off-by: yaoyu-33 <[email protected]>
@weijiac0619

Copy link
Copy Markdown
Contributor

FYI, not blocking. Running responses_api_agents/codex_agent/tests/test_sandbox_sessions.py with -n 8 on our OCI CPU nodes (srun, 16 cores on a shared node, checkout and TMPDIR on Lustre), every run had a few failures, and a different set each time, mostly TimeoutError or KeyError: '.../native_session.jsonl'. Three runs on this head failed 1, 2 and 10 tests. the merge base on the same node, interleaved with them, failed 1, 3 and 1. So this predates the PR, and CI passed all 73 tests in this file at 9411714. I suspect timing-sensitive tests on a loaded node with slow shared storage, but I haven't confirmed it.

weijiac0619
weijiac0619 previously approved these changes Nov 6, 2026
@weijiac0619

Copy link
Copy Markdown
Contributor

LGTM. Left two non blocking comments

The test conftest only warned when ensure_node() failed, so a failed Node
download in CI would skip the launcher and runner tests and still pass.
Let the error fail the run, as the other servers' install hooks do.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@yaoyu-33

yaoyu-33 commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test cfaa83a

@weijiac0619

Copy link
Copy Markdown
Contributor

FYI, not blocking. Running responses_api_agents/codex_agent/tests/test_sandbox_sessions.py with -n 8 on our OCI CPU nodes (srun, 16 cores on a shared node, checkout and TMPDIR on Lustre), every run had a few failures, and a different set each time, mostly TimeoutError or KeyError: '.../native_session.jsonl'. Three runs on this head failed 1, 2 and 10 tests. the merge base on the same node, interleaved with them, failed 1, 3 and 1. So this predates the PR, and CI passed all 73 tests in this file at 9411714. I suspect timing-sensitive tests on a loaded node with slow shared storage, but I haven't confirmed it.

Confirmed it was our setup, not the PR. I had TMPDIR pointed at Lustre on that node instead of /tmp

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/42292912639

This branch was previously deployed

1 inactive deployment
public — cfaa83af Deployed Nov 6, 2026 by yaoyu-33 via release / finalize / notify #10728
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:agent Agent harnesses and Responses API agent behavior blocked Work cannot move forward until an external dependency is cleared feature New capabilities, enhancements, or enablement work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants