Skip to content

refactor(agent_utils): run sandboxed harnesses with only bash in the task image - #5094

Closed
yaoyu-33 wants to merge 34 commits into
NVIDIA-NeMo:mainfrom
yaoyu-33:refactor/bash-sandbox-runtime
Closed

yaoyu-33 wants to merge 34 commits into
NVIDIA-NeMo:mainfrom
yaoyu-33:refactor/bash-sandbox-runtime

Conversation

@yaoyu-33

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

Copy link
Copy Markdown
Contributor

Stacked on this PR: #5137 (Hermes and Stirrup runtimes built on the agent server), then #5148 (Codex without the task image's Python). Their bases, refactor/bash-sandbox-runtime and fix/host-built-hermes-stirrup-runtime, are copies of the fork heads in this repo, so each diff shows only its own changes.

What

Sandboxed harnesses no longer need Python in the task image. The shared process supervisor (nemo_gym/agent_utils/process_supervisor.sh) and a shared harness runner (harness_runner.sh) are bash scripts, and the OpenCode/Kilo SQLite snapshot moves to the agent server. Claude Code, OpenCode, Kilo, OpenClaw and Pi run their CLIs through the bash runner; Hermes, NOOA and Stirrup keep their own Python workers under the bash supervisor.

This ports Hemil Desai's bash sandbox runtime change (his commits are kept with authorship) onto main, adapts it to code that only exists here, and adds fixes found in review.

Before / after

Colour key: amber = Python inside the task sandbox, green = moved from Python to bash, blue = moved out of the sandbox to the agent server, grey = Python worker kept as is.

Before: every sandboxed harness needs Python ≥ 3.8 in the task image.

flowchart LR
  subgraph host["Agent server"]
    S["SandboxSession<br/>supervisor_client"]
  end
  subgraph box["Task sandbox (task image)"]
    B["Bootstrap<br/>apt/apk python3 if missing<br/>workdir check with python3 -c"]:::py
    I["Runtime installers<br/>install_claude_runtime.py<br/>Python ≥ 3.8 assert, fcntl lock,<br/>hashlib digest, ctypes libstdc++"]:::py
    SUP["process_supervisor.py<br/>subreaper drain"]:::py
    R["sandbox_runner.py<br/>one per harness"]:::py
    CLI["Harness CLI<br/>Claude Code · OpenCode · Kilo · OpenClaw · Pi"]
    W["Codex worker + 429 proxy<br/>Hermes · NOOA · Stirrup workers"]:::keep
    DB[("opencode.db / kilo.db")]
    X["SQLite export<br/>sandbox_runner.py --snapshot"]:::py
  end
  S -->|"seed"| B --> I
  S -->|"launch: python3 -I"| SUP --> R --> CLI
  SUP --> W
  CLI --> DB --> X -->|"export.json<br/>observations.db"| S
  classDef py fill:#fde68a,stroke:#b45309,color:#111
  classDef keep fill:#e5e7eb,stroke:#6b7280,color:#111
Loading

After: the shared pieces need only bash; Codex, Hermes, NOOA and Stirrup still bring or use their own Python worker.

flowchart LR
  subgraph host["Agent server"]
    S["SandboxSession<br/>supervisor_client<br/>shell_assignments() → params.sh"]
    X["SQLite export<br/>snapshot.py"]:::host
  end
  subgraph box["Task sandbox (task image needs bash)"]
    B["Bootstrap<br/>apt/apk bash only if missing<br/>POSIX sh workdir check"]:::sh
    I["Runtime installers<br/>install_claude_runtime.sh<br/>flock or owner-symlink lock,<br/>sha256sum, path / apk checks"]:::sh
    SUP["process_supervisor.sh<br/>/proc rescans + env marker"]:::sh
    R["harness_runner.sh<br/>shared by 5 harnesses"]:::sh
    CLI["Harness CLI<br/>Claude Code · OpenCode · Kilo · OpenClaw · Pi"]
    W["Codex worker + 429 proxy<br/>Hermes · NOOA · Stirrup workers"]:::keep
    DB[("opencode.db / kilo.db<br/>+ WAL files")]
  end
  S -->|"seed"| B --> I
  S -->|"launch: bash"| SUP --> R --> CLI
  SUP --> W
  CLI --> DB -->|"download raw files"| X
  classDef sh fill:#bbf7d0,stroke:#15803d,color:#111
  classDef host fill:#bfdbfe,stroke:#1d4ed8,color:#111
  classDef keep fill:#e5e7eb,stroke:#6b7280,color:#111
Loading
Piece Before After Change
Process supervisor process_supervisor.py process_supervisor.sh Python → shell
Runner for Claude Code, OpenCode, Kilo, OpenClaw, Pi one sandbox_runner.py per harness shared harness_runner.sh Python → shell
Claude Code installer install_claude_runtime.py install_claude_runtime.sh Python → shell
OpenCode installer: lock and digest check inline Python (fcntl, hashlib) flock or owner symlink, sha256sum Python → shell
Kilo, OpenClaw, Pi installers: version and libstdc++ checks Python assert, ctypes probe path and apk info checks Python → shell
Bootstrap workdir overlap check (OpenCode, Kilo, OpenClaw, Pi) python3 -c POSIX sh Python → shell
Bootstrap packages python3 and bash if missing bash if missing; Codex still python3 and bash python3 no longer installed, except by Codex
OpenCode/Kilo SQLite export in the sandbox (--snapshot) on the agent server (snapshot.py) sandbox → host
Codex worker sandbox_runner.py + sandbox_transport.py unchanged, now under the bash supervisor stays Python
Hermes, NOOA, Stirrup workers own Python worker unchanged, now under the bash supervisor stays Python

Known exceptions (follow-ups, not in this PR)

These still put Python or the network into the task sandbox. No tracking issues are filed yet.

  • Codex still needs python3 ≥ 3.8 in the task image and apt/apk-installs it when missing. Python runs its workdir overlap check, the installer's version and libstdc++ probes, its worker, the 429 retry proxy (sandbox_transport.py) and the --snapshot export. Only the proxy has no bash equivalent; where it should live (for example the agent server's rate_limit_proxy) is still to be decided. Once Codex moves, stdlib_runner, RUNNER_INTERPRETER and bin/gym-runner can go.
  • Hermes uploads uv and runs uv venv --python 3.13 and uv pip install inside the sandbox, from the network, with cwd set to the task workdir, without --no-config, and without UV_CACHE_DIR or UV_PYTHON_INSTALL_DIR: a task's uv.toml or [tool.uv] can change the install, uv's cache and managed Python land in the task's home, and --python 3.13 can bind the image's own python3.13.
  • Stirrup does the same with uv pip install stirrup==...; it sets UV_CACHE_DIR and UV_PYTHON_INSTALL_DIR but not --no-config.
  • The fix for Hermes and Stirrup is a relocatable runtime prepared on the host, as hermes_sandboxed_agent/prepare_runtime.sh and NOOA do. The harness guide now presents these three paths as exceptions, not options.

Why

Before this change the supervisor and per-harness runners ran on whatever python3 the task image had:

  • python3 older than 3.8 failed the task (seen on SWE images with old Python);
  • a missing python3 was apt/apk-installed into the task image, changing what both the agent and the verifier see (for example Go/Rust/JS images in multilingual SWE sets).

No public issue; this mirrors internal work on the same change.

Port notes (differences from the original change)

  • Codex keeps its Python worker under the bash supervisor. On main the Codex worker runs a sandbox-local 429 retry proxy (sandbox_transport.py) that has no bash equivalent, so Codex still needs Python ≥ 3.8 in the task image. Where that proxy should live is an open question for a follow-up.
  • Cline's sandboxed mode and troxy are not on main; those parts are left out.
  • OpenCode drops sandbox_python_executable; sandbox_path_prefix now reaches the CLI through the runner setup. benchmarks/swe_together/opencode.yaml is updated.
  • NOOA drops the removed SandboxCommand.python field; its pinned Python still runs its worker.

Fixes on top of the port

  • Tools in their own session are stopped again. OpenCode/Kilo start shell tools detached, so after a timeout or close the group KILL missed them and they could write during verification after a confirmed receipt. On a forced stop the supervisor now scans /proc when the stop begins and on every polling round. It kills the harness group plus everything it reaches: descendants of the harness, of its group and of reached processes, and processes that inherited the harness's NEMO_GYM_SUPERVISOR environment marker (for example a tool that daemonizes, or a TERM handler that runs setsid ... & and exits). Marked processes that had already left the harness when the stop began are preserved as services, as the subreaper did on main. What is not reached is documented: a process that leaves between two scans after dropping the marker. The Codex runner passes the marker through its env allowlist.
  • Supervisor: a group is killed or awaited only while its ID still belongs to the recorded leader (same start time) or is free, so a reused group ID is not hit. Without a group of its own, the supervisor restarts itself as a job in a new process group, so a provider's group KILL cannot end it before the receipt; the remaining shell passes on TERM and the exit status.
  • Supervisor hardening: reads /proc/PID/stat whole and never evaluates its fields as arithmetic (a crafted process name could run code and hide a member); refuses to launch without a readable /proc; bounds the wait for a KILLed harness; rejects malformed arguments instead of looping; ignores an inherited errexit. Launches render fixed-point seconds, and a deadline under one centisecond expires before launch instead of leaving no receipt.
  • Supervisor stop cost: a forced stop parses every /proc/PID/stat several times, and on a busy host this made stops slow (1.65 s with about 1,100 processes, so Hermes's close test, which allows 2 s, failed there while CI passed). Parsing no longer uses bash's quadratic longest-prefix match or a regex per field, the drain takes liveness from its scan instead of a second pass, and no extra scan runs once the harness has exited. The same stop now takes about 0.55 s.
  • Runner: event timestamps on bash < 4.2; inherited variables named like runner PARAMS no longer configure the runner; the events-mode CLI gets no runner descriptors; CR stripping is linear in the line length (a quadratic ${1%$'\r'} took seconds per MB); an inherited set -e no longer stops the runner at a non-JSON line; a failed exec redirection no longer falls through into events mode. The runner exits 125 for its own failures (bad cwd, an exit in setup) and 126/127 when the CLI could not be started, and Kilo reports these apart from Kilo's own exit status. A cancelled Kilo run reports no exit code, as before.
  • Installers: the flock-less lock fallback is crash-safe (a ticket queue of owner symlinks with PID + start time); Claude installer works on bash < 4; Pi installer survives set -u on bash < 4.4 and checks all musl library directories; the OpenCode installer removes a partly staged binary on any failure and no longer reuses a cached binary whose --version fails.
  • Claude Code installs a missing bash during setup, like the other bash-runner adapters, and otherwise fails with a message that names bash.
  • Host-side SQLite connections are closed; shell_assignments() rejects NUL and non-string words.

Compatibility

  • nemo_gym.agent_utils.process_supervisor (Python) is removed; CleanupReceipt, exec_timeout and the constants live in nemo_gym.agent_utils.supervisor_client. SandboxCommand(python=...) and supervised_launch_command(python=...) are removed. Out-of-tree adapters need the migration in fern/versions/latest/pages/agent-server/add-or-update-a-harness.mdx.
  • Receipt return_code is now the shell status (128+N for a signal death) instead of −N; a missing CLI gives a confirmed receipt with 126/127, and a runner failure before the CLI starts gives 125. The harness guide's migration note lists these together with the removed python= parameters and the bash requirement.
  • Task images now need bash (adapters that installed python3 now install only a missing bash; Codex still installs python3).
  • Harness processes see a new NEMO_GYM_SUPERVISOR environment variable.
  • No benchmark-result impact expected; verification is unchanged.

Validation

Local (macOS, bash 3.2 and 5.2; Linux-only /proc tests are skipped here and run in CI):

  • pytest tests/unit_tests responses_api_agents/{opencode,kilocode,codex,pi,openclaw,claude_code,hermes_sandboxed}_agent/tests: 13766 passed, 480 skipped, 50 failed, 1 collection error. All 50 failures also fail on unmodified main in the same local venv (missing opensandbox/mlflow, macOS-specific telemetry/CI checks; one flaky Harbor test); the collection error is test_exporters.py needing mlflow.
  • Runner tests on both bash 3.2 and bash 5.2; the new regression tests fail on the unfixed scripts and pass after.
  • Manual run of the Claude installer's flock-less lock (stale and live owner) on bash 3.2 and 5.2.
  • pre-commit run --files <changed files>: passed.
  • Not run locally: Hermes/NOOA/Stirrup suites (packages not in the local venv), Linux-only supervisor tests.

Review round 2 (local, macOS):

  • Affected suites (tests/unit_tests/test_{harness_runner,process_supervisor,sandbox_supervisor_client,sandbox_supervisor_bootstrap,sandbox_session}.py, responses_api_agents/{kilocode,claude_code,opencode,codex,pi,openclaw}_agent/tests): 1910 passed, 228 skipped, 3 failed. The 3 failures are test_opensandbox_sdk_is_available_in_agent_environment, which needs opensandbox, missing from the local venv.
  • New runner tests on bash 3.2 and 5.2; the long-line and inherited-errexit tests fail on the previous runner.
  • The supervisor's scan, kill and group-identity logic, checked on bash 3.2 and 5.2 against a fake /proc: harness, tools, orphaned group member and daemons reached; earlier service and its children preserved; reused group not killed.
  • OpenCode installer staging failure and unhealthy cache, run by hand with a stub uname.
  • The new Linux supervisor tests (daemonized during the stop, reused IDs, provider group KILL) run only in CI.

Linux host (bash 5.0, about 1,100 processes), at 05bac05:

  • responses_api_agents/hermes_agent/tests: 349 passed. test_close_preserves_interrupted_observations_before_release failed in both cases at fb642f9 and passed 5 of 5 runs with the fix.
  • tests/unit_tests/test_{process_supervisor,sandbox_supervisor_client,harness_runner}.py, including the Linux-only supervisor tests: all passed. The new name-parsing test fails on a parser that splits at the first ") ".

Rollout evidence: pending — this stays a draft until smoke rollouts run on a Debian image, an old-Python SWE image and an Alpine image where bash gets auto-installed.

🤖 Generated with Claude Code

hemildesai and others added 20 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]>
@copy-pr-bot

copy-pr-bot Bot commented Oct 26, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test 01ac0f1

@svcnvidia-nemo-ci svcnvidia-nemo-ci added area:agent Agent harnesses and Responses API agent behavior feature New capabilities, enhancements, or enablement work labels Oct 26, 2026
@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

…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]>
@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test fb642f9

…hosts

A forced stop scans every process in /proc several times, and each
/proc/PID/stat parse used a longest-prefix match (quadratic in bash) and
three regex compilations. On a host with about 1,100 processes a stop
took 1.65 s, so Hermes's close test, which allows 2 s and polls for the
receipt once a second, failed there while CI passed.

Parse with a shortest-prefix loop and glob digit checks, let the forced
drain take liveness from its scan instead of a second /proc pass, and
skip the extra scan once the harness has exited (the drain scans next).
A stop on the same host now takes about 0.55 s.

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

Copy link
Copy Markdown
Contributor Author

/ok to test 05bac05

@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test b1c63b8

@yaoyu-33

Copy link
Copy Markdown
Contributor Author

Superseded by #5151, the same commits reopened from a branch in this repo so #5151, #5152 and #5153 can form a GitHub Stack (pull requests from forks cannot join one). This PR keeps the earlier review history; please continue on #5151.

leader=${group[pid]}
if [[ -n ${kept[pid]} || $pid == "$$" ]]; then
continue
elif [[ -n ${tracked[pid]} && ${tracked[pid]} == "${start[pid]}" ]]; then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No test fails when the start-time comparison on this branch is removed. test_reused_ids_are_neither_awaited_nor_killed covers reached_alive and kill_reached, but scan records the new start time at line 130, so a process that reused a tracked PID is pulled in and then killed before the guard in kill_reached can help. It needs the PID to wrap during a stop, so it is unlikely. A test that sets tracked[pid] to a stale start time and runs scan would pin it.


# Succeeds when process $1, started at $2, inherited this supervisor's marker. A process that started
# before the supervisor cannot have, so its environment is not read.
marked() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

marked reads the environment of every process that started after the supervisor and is not yet reached, on each scan. On bash 5.2 a scan took about 0.2 s with 900 processes visible, 0.7 s with 1,700 and 3 s with 3,700, mostly in these reads. That is fine inside a pod's own PID namespace. Does any provider run a sandbox in the host's PID namespace? There the poll interval and the receipt would stretch.

grace=$((NOW + cleanup))
while kill -0 "$harness" 2>/dev/null && ((NOW < grace)); do
sleep 0.05
scan

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this rescan passes every test. The rescans after the loop cover most of it, so only a process that leaves the harness during the grace period and drops the marker would differ. A test for that case would show whether the per-round rescan is needed.

# unset_env array of extglob patterns naming inherited variables to drop
# events file receiving each JSON object line of stdout as [seen_at, object]
# Writes runtime.json beside PARAMS. Exits with the command's status, 125 when the runner fails before
# starting it (including an exit from setup), or 126 or 127 when the command could not be started.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only Kilo tells these statuses apart from the CLI's own. Claude Code (claude_code_agent/app.py:793), OpenCode (opencode_agent/app.py:1275), OpenClaw and Pi still report 125, 126 and 127 as the CLI's exit code. Is that intended for this PR?

"XDG_CACHE_HOME",
"XDG_STATE_HOME",
# Lets the supervisor find Codex's tools after they leave its process tree.
"NEMO_GYM_SUPERVISOR",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex passes the marker explicitly because it builds its tools' environment from an allowlist. For the other CLIs the marker reaches tools only if the CLI hands them the parent's environment, and nothing shows that. A smoke rollout in which the model runs env | grep NEMO_GYM_SUPERVISOR would settle it for each harness.

f"{quote(self.config.runtime_python)} -I {quote(remote + '/process_supervisor.py')} "
f"--timeout {self.config.sandbox_timeout} --receipt {quote(remote + '/cleanup.json')} -- "
f"bash {quote(f'{remote}/{SUPERVISOR_FILE}')} "
f"--timeout {self.config.sandbox_timeout} --cleanup-timeout {DEFAULT_CLEANUP_TIMEOUT} "

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--timeout is still the raw float string. The supervisor accepts fixed-point values of at least 0.01, so a smaller value or exponent form such as 1e+16 exits 2 with no receipt. supervisor_client._seconds already formats it.

This branch was previously deployed

1 inactive deployment
public — b1c63b8d Deployed Oct 27, 2026 by copy-pr-bot[bot] via release / finalize / notify #7695
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 feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants