Repository navigation
feat(agents): supervisor stop policy and Codex tool pid namespace - #6280
Conversation
A bubblewrap provider for Gym's sandbox API: one unprivileged user+mount+pid namespace per sandbox on the host (no daemon, no image), an allow-listed environment with GPUs hidden, contained file transfer, bounded exec concurrency, and a stop that kills tracked processes and removes the sandbox directory. Adds the optional SupportsSandboxExecScopedProcesses protocol and AsyncSandbox.exec_processes_terminated, so a caller can confirm from the provider side that no exec process can still run. Tests live in tests/unit_tests/sandbox/ (unit tests with a fake bwrap; integration tests with the real binary when present). Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Stephen Ge <[email protected]>
Shared harness supervisor (nemo_gym/agents/utils): - process_supervisor.sh: TERM/INT/HUP without the controller's stop.request are counted as foreign signals and ignored (the controller only stops a run through stop.request); the receipt records foreign_signals. - sandbox_session / supervisor_client: a launch's return code and a missing cleanup receipt are recorded, and stop_and_confirm_cleanup can confirm cleanup from the provider side (exec_processes_terminated) when the supervisor died without writing its receipt. codex_agent: - tool_pid_namespace (default off): Codex tool commands run in a nested bwrap pid namespace on a tool host, so a tool command (pkill, kill -9 -1) cannot signal the harness; harness-kill evidence (128+N, receipts) is reported. - failure_artifacts_dir keeps a failed activation's supervisor/Codex logs. - tool_namespace_check runs the isolation check end to end against a real bwrap (optionally the real Codex CLI). Stacked on the bwrap provider PR. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Stephen Ge <[email protected]>
yaoyu-33
left a comment
There was a problem hiding this comment.
Thanks for splitting this out of #6279. The supervisor change is small and well tested, and the tool pid namespace answers a real problem: a model's pkill -f node or kill -9 -1 ending its own episode. This review covers only this PR's commit on top of #6279 (5659250d7e..312e456216).
Verdict: HOLD for one blocker. The end-to-end isolation check (tool_namespace_check) crashes with a TypeError on every run, so its test fails on any Linux host with bwrap user namespaces. It passes only where it skips, which is why it looked green on macOS. It is also the PR's only end-to-end evidence for the namespace, so it goes together with the ask for a real-model smoke at this head. Beyond that, the main code risk is that other harnesses on bwrap can't tell a provider-confirmed missing receipt apart from a clean stop. Everything else is a note. Each item is an inline comment.
What we checked, at this head, on a Linux host (bwrap 0.4.0, kernel 5.15):
tests/unit_tests/agents: 642 passed, including all 53 Linux-only supervisor tests.- codex_agent tests: one new failure (the blocker), 606 passed.
- The sandbox tests of 15 other sandboxed harnesses match #6279's head. No caller signals the supervisor: every controller stops it through
stop.request. - Reverting each piece of the fix (the supervisor script, the trap, the provider-proof branch, the
foreign_signalsparse) makes its new test fail, so these tests check real behaviour. - An independent probe with a real
BwrapProvider, the real supervisor andtool_namespace_args(): the harness survivedpkill -f node,pkill -9 -f nemo-gymandkill -9 -1with the namespace on, and died with it off. - The Codex 0.144.4 keys this relies on exist at
rust-v0.144.4:environments.toml,exec-server --listen stdioandorchestrator.skills.enabled.
Merge order: this PR's base is stepheng/bwrap-provider (#6279). Merge #6279 first, then retarget this PR to main. The missing-receipt path depends on #6279's exec_processes_terminated.
…s, setup-failure channel, CI) - Mount targets at, above or inside the sandbox's own /tmp, home or workdir are refused (bwrap would create the mount point in sandbox-writable space, following symlinks, or shadow that directory), and the workspace is bound at its host path only when that path lies outside them (the default base_dir is under /tmp). - An exec queued on exec_concurrency re-checks the closing marker after taking its slot; close() waits (bounded) for this instance's execs that are about to spawn; exec_processes_terminated() is False while any is queued or starting. - bwrap's own setup failure is detected from --info-fd (no child-pid reported), a channel the command cannot write; a command printing "bwrap: ..." now fails as itself. - uploads_independent_of_execs() is True (uploads never take the exec semaphore); the info pipe is closed on any spawn exception; SupportsSandboxExecScopedProcesses is exported with the other protocols and documented generically. - bwrap is listed under "Required provider migrations"; docs fixed (cancel re-raises, probe only with probe_on_create, exec_processes_terminated); the Codex runtime-mount section is dropped (mounts under /tmp are refused now). - CI installs bubblewrap and sets NEMO_GYM_REQUIRE_BWRAP=1 so the real-bwrap tests fail instead of skipping; new real-bwrap tests cover the process proof (creator and borrower), the info-fd child being pid 1, timeouts killing setsid children, a borrower's stop, and planted symlinks. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Stephen Ge <[email protected]>
…API; tighten its control verdict The check called the internal execute(command=, env=, prompt=) signature and failed with TypeError on every Linux run. It now stages the launch through SandboxSession.execute (stage_activation + collect_artifacts), with the environment in the runner's env array. The control run passes only when the check itself ran, kill -9 -1 ran and the unprotected harness died. The module moves beside its only consumer (codex_agent/tests) and creates its scratch directory per run instead of at import. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Stephen Ge <[email protected]>
Signed-off-by: Stephen Ge <[email protected]>
…pt, neutral kill labels, config checks) - A provider-confirmed missing receipt now carries receipt_missing: True in the receipt itself, so every SandboxSession consumer can tell it from a clean stop (the diagnostics out-parameter is gone). The provider path needs the supervisor's launch claim, re-reads the receipt once after the proof, and treats a failing proof as an unknown outcome. The launch's return code is recorded where execute holds the exec result. - Harness-kill evidence counts only signal statuses (129..192) and a missing receipt after a signalled or unknown launch; the label is harness_killed unless tools demonstrably signalled the supervisor (agent_killed_harness). - tool_pid_namespace: the agent-host bwrap must be an executable (422 at seed); a runtime without the platform Codex binary is a seed rejection, not a retry; probe output is capped; the runtime path is shell-quoted. - failure_artifacts_dir: decided before a graded failure clears the error, and bounded by the close budget. - process_supervisor.sh documents that it keeps the supervisor (not the harness) alive and that only stop signals are covered. README: config keys, Codex version pin, validated on the bwrap provider only. - Tests: the borrow test stub takes the provider's new keyword and imports from nemo_gym.sandbox. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Stephen Ge <[email protected]>
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
SHIP
No qualifying findings. I reviewed all 16 changed files and traced the affected cleanup, tool-host setup, and Codex response paths.
The earlier checker failure is fixed: it now uses the supported session API, and the control verdict requires executed kill commands plus evidence that the harness died. The missing-receipt fallback requires a returned launch, a launch claim, and positive provider proof. The current code also keeps the missing-receipt marker, neutral signal labels, and bounded artifact preservation.
This was a static review. I did not execute tests or independently reproduce the reported real-model smoke runs.
Note: formal approval is not available for this request, so this review is posted as a comment only.
Review generated by codex. This was a full review. Request a full review with /review reset=true.
… pending execs, visible-bind transfers) - /tmp, home_path and the workdir (SandboxSpec.workdir overrides included) must be pairwise disjoint: a workdir of /home with home /home/sandbox hid home from commands while uploads still landed there. - A pending exec (queued on exec_concurrency or about to spawn) is recorded in run/ (pending-*, owner pid and start time), so every provider instance sees it: exec_processes_terminated() is False while a live owner has one, and close() waits for them (bounded) before its final kill pass. A dead owner's record is removed. - The transfer table follows bind order: a later mount at or above an earlier one's destination hides it, so transfers resolve to the mount a command sees (and its writability). Regular-file mounts are addressable at their exact destination (download, exists; upload when read-write). - connect no longer compares the descriptor's workdir (the facade's default cwd, which set_default_workdir moves) with the workspace bind from the state file. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Stephen Ge <[email protected]>
Signed-off-by: Stephen Ge <[email protected]>
…ding them preserve_failure_artifacts now runs `tail -c <cap>` in the sandbox and downloads only that copy, so a huge session log never reaches the Agent Server whole (the 16 MiB cap used to apply after a full download). Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Stephen Ge <[email protected]>
|
/ok to test e1a3080 |
…ces are refused; retry an early forced stop - test_bwrap_tool_namespace probed only the outer bwrap namespace. The tool host is a bwrap inside the sandbox's bwrap, which a host can refuse while it allows the outer one (CI: both runs failed at the tool-host setup). The probe now creates a nested user + pid namespace, and the skip reason carries bwrap's error. NEMO_GYM_REQUIRE_BWRAP=1 still turns the skip into a failure. - A failed check prints its whole report; pytest's assertion repr truncated the setup output and the checks. - test_forced_stop_reaches_processes_that_leave_the_harness_during_the_stop: on a loaded runner the 1 s timeout could stop the worker before it set its TERM trap, so nothing was spawned to chase. The worker's `ready` file shows whether the trap was set; the run is repeated with 4 s and 10 s timeouts until it was. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Stephen Ge <[email protected]>
|
/ok to test b041afa |
yaoyu-33
left a comment
There was a problem hiding this comment.
Reviewed b041afa against the stacked #6279 base, including the earlier review fixes and an independent follow-up review.
Expected: controller-driven stops and tool isolation must preserve reliable cleanup and failure diagnostics. Actual: the checker uses the current session API, provider proof stays fail-closed, missing receipts remain explicit, and failure logs are now trimmed inside the sandbox before download under the existing capture deadline. No remaining blocking finding in this revision.
Validation: 534 focused tests passed on Linux/Python 3.13.14 with real bwrap and NEMO_GYM_REQUIRE_BWRAP=1, covering Codex sessions, namespace isolation/control, supervisor and shared session cleanup. One real-Codex-runtime test skipped because that runtime was not configured. The author's Codex/Pi model smoke at 2fdb5f9 covers the unchanged behavior; I did not rerun model smoke for the diagnostic/test-only follow-up. Required CI passed at this head; optional Environment Server compliance diagnostics failed.
This approves the code against its current base. Merge ordering with #6279 remains separate.
Signed-off-by: yaoyu-33 <[email protected]>
|
/ok to test 560f27d |
yaoyu-33
left a comment
There was a problem hiding this comment.
Re-approved at 560f27d after #6279 landed and this PR moved to main.
The main integration preserves the exact reviewed 16-file child delta and all current-main changes. An independent integration review found no new blocker. Earlier checker, cleanup-proof, signal classification and bounded diagnostic-log findings remain fixed.
Validation on Linux/Python 3.13.14: 542 focused Codex/session/supervisor tests passed with NEMO_GYM_REQUIRE_BWRAP=1, including real bwrap isolation and the control case; full pre-commit passed. One pinned real-Codex-runtime test skipped. The author's real Codex/Pi model smoke at 2fdb5f9 remains evidence for the unchanged behavior; no new model smoke was run for this merge-only update. Repository CI has been requested for this new head and must pass before merge.
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/44670979530 |
…ever park beside a launch that still writes Review of #5268. Supervisor (`process_supervisor.sh`): - `--max-pause SECONDS`: a pause nobody continues used to hold the harness for good, with the deadline not running and an expire waiting for the continue. Past the limit the supervisor ends the harness as at its time limit and the receipt records `pause_expired`. The limit counts the supervisor's polls, not the clock. `SandboxSession.execute` passes the pause allowance as the limit. - The wait for a continue also ends when the harness is gone. - The usage text lists the pause options. Pause and continue requests (`supervisor_client._request`): - bounded as a whole, so a request queued behind a full provider does not wait for a harness to end; - run from `control_cwd`, so they do not need a workdir the task moved or deleted. `SandboxSession.pause_harness` answers `unconfirmed` while the launch is still staging after its wait: a pause request would only hold the launch command, and staging would keep writing during the snapshot. `run_until_parked` is now `run_with_checkpoint_pauses` (it returns when the launch ends, parked or not), and `Finished`/`Stopped` are `LaunchFinished`/`LaunchStopped`. It also: - repeats a pause request that failed in transport (4 attempts, 1 s doubling) and waits the same way between continue attempts; a timeout or an answer of the supervisor is not repeated; - treats a `receipt_missing` receipt (main's #6280: the supervisor died and the provider proved the sandbox empty) after its own stop as a stopped launch, not a finished one; - raises, and does not park, when a launch cancelled while staging does not end within the stop timeout; - reads the exception of a park request or an abandoned launch, so asyncio does not log it as never retrieved. `SandboxSession.reattach` is now `rebind`, the word the checkpoint code uses; `ParkingActivation` and `SandboxSessionCheckpoint` are exported. `exec_idempotent` takes `cwd`, `env` and `timeout_s` explicitly. The conformance kit moves to `nemo_gym.agents.testing` as `check_harness_checkpointing`: it checks an agent adapter, and can now import `AGENT_ACTIVATION_HEADER`. Its local provider is private. The crash scenario ends the first agent (handles, processes, tasks) before the restore and cleans up in a `finally`, and an adapter can supply `crash_recovery_assertion` to prove the recovery continued the saved conversation. Tests: the deadline-extension test now fails without the extension, the hold test no longer asserts a tight real-time bound, and each change above has tests. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]>
…ever park beside a launch that still writes Review of #5268. Supervisor (`process_supervisor.sh`): - `--max-pause SECONDS`: a pause nobody continues used to hold the harness for good, with the deadline not running and an expire waiting for the continue. Past the limit the supervisor ends the harness as at its time limit and the receipt records `pause_expired`. The limit counts the supervisor's polls, not the clock. `SandboxSession.execute` passes the pause allowance as the limit. - The wait for a continue also ends when the harness is gone. - The usage text lists the pause options. Pause and continue requests (`supervisor_client._request`): - bounded as a whole, so a request queued behind a full provider does not wait for a harness to end; - run from `control_cwd`, so they do not need a workdir the task moved or deleted. `SandboxSession.pause_harness` answers `unconfirmed` while the launch is still staging after its wait: a pause request would only hold the launch command, and staging would keep writing during the snapshot. `run_until_parked` is now `run_with_checkpoint_pauses` (it returns when the launch ends, parked or not), and `Finished`/`Stopped` are `LaunchFinished`/`LaunchStopped`. It also: - repeats a pause request that failed in transport (4 attempts, 1 s doubling) and waits the same way between continue attempts; a timeout or an answer of the supervisor is not repeated; - treats a `receipt_missing` receipt (main's #6280: the supervisor died and the provider proved the sandbox empty) after its own stop as a stopped launch, not a finished one; - raises, and does not park, when a launch cancelled while staging does not end within the stop timeout; - reads the exception of a park request or an abandoned launch, so asyncio does not log it as never retrieved. `SandboxSession.reattach` is now `rebind`, the word the checkpoint code uses; `ParkingActivation` and `SandboxSessionCheckpoint` are exported. `exec_idempotent` takes `cwd`, `env` and `timeout_s` explicitly. The conformance kit moves to `nemo_gym.agents.testing` as `check_harness_checkpointing`: it checks an agent adapter, and can now import `AGENT_ACTIVATION_HEADER`. Its local provider is private. The crash scenario ends the first agent (handles, processes, tasks) before the restore and cleans up in a `finally`, and an adapter can supply `crash_recovery_assertion` to prove the recovery continued the saved conversation. Tests: the deadline-extension test now fails without the extension, the hold test no longer asserts a tight real-time bound, and each change above has tests. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]>
…ever park beside a launch that still writes Review of #5268. Supervisor (`process_supervisor.sh`): - `--max-pause SECONDS`: a pause nobody continues used to hold the harness for good, with the deadline not running and an expire waiting for the continue. Past the limit the supervisor ends the harness as at its time limit and the receipt records `pause_expired`. The limit counts the supervisor's polls, not the clock. `SandboxSession.execute` passes the pause allowance as the limit. - The wait for a continue also ends when the harness is gone. - The usage text lists the pause options. Pause and continue requests (`supervisor_client._request`): - bounded as a whole, so a request queued behind a full provider does not wait for a harness to end; - run from `control_cwd`, so they do not need a workdir the task moved or deleted. `SandboxSession.pause_harness` answers `unconfirmed` while the launch is still staging after its wait: a pause request would only hold the launch command, and staging would keep writing during the snapshot. `run_until_parked` is now `run_with_checkpoint_pauses` (it returns when the launch ends, parked or not), and `Finished`/`Stopped` are `LaunchFinished`/`LaunchStopped`. It also: - repeats a pause request that failed in transport (4 attempts, 1 s doubling) and waits the same way between continue attempts; a timeout or an answer of the supervisor is not repeated; - treats a `receipt_missing` receipt (main's #6280: the supervisor died and the provider proved the sandbox empty) after its own stop as a stopped launch, not a finished one; - raises, and does not park, when a launch cancelled while staging does not end within the stop timeout; - reads the exception of a park request or an abandoned launch, so asyncio does not log it as never retrieved. `SandboxSession.reattach` is now `rebind`, the word the checkpoint code uses; `ParkingActivation` and `SandboxSessionCheckpoint` are exported. `exec_idempotent` takes `cwd`, `env` and `timeout_s` explicitly. The conformance kit moves to `nemo_gym.agents.testing` as `check_harness_checkpointing`: it checks an agent adapter, and can now import `AGENT_ACTIVATION_HEADER`. Its local provider is private. The crash scenario ends the first agent (handles, processes, tasks) before the restore and cleans up in a `finally`, and an adapter can supply `crash_recovery_assertion` to prove the recovery continued the saved conversation. Tests: the deadline-extension test now fails without the extension, the hold test no longer asserts a tight real-time bound, and each change above has tests. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]>
…-NeMo#5268) * fix(checkpoint): leave the calls a checkpoint abandoned out of the capture ledger A harness interrupted at a checkpoint (OpenCode killed while its model call is held) gives up on the call. The ledger had recorded it, often as a failure row for a request that ended without staging coordinates, and the gate no longer counted it as undelivered once the request had finished, so the row went into the commit and the restored attempt's manifest reported a failure for a call no trajectory contains, which masks the sample. The policy gate now remembers calls whose client left while admission was closed (`GateSnapshot.abandoned`); the commit leaves their rows out like an undelivered call's, and the resume drops them from the live ledger (`FileLineageStore.discard_calls`), in the single-process and the multi-worker policy server alike. (cherry picked from commit 912ce78) Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]> (cherry picked from commit 7619754df96d015eb6bb98ec956aa5feb1c2c078) * feat(agent-utils): pause a supervised harness in place at a checkpoint and park its activation A checkpoint of an agent whose harness runs in a task sandbox had two choices: wait for the harness, which can take an hour, or stop it and relaunch after the commit. This adds a third, which is now the first choice. The bash supervisor pauses and continues the harness on request. Writing sequence number N to `pause.request` sends SIGSTOP to every process a stop would reach and to every process carrying the supervisor's environment marker, including services that left the harness, waits until each is stopped (longer while some are in uninterruptible sleep), and acknowledges in `paused.json`; `continue.request` with N sends SIGCONT and acknowledges in `continued.json`. Numbers only grow, so every checkpoint re-arms the protocol without removing files. Time spent paused does not count against the harness deadline, a pause requested before the launch holds the launch, and a stop while paused continues the processes first so the harness still sees TERM and can save its state. The cleanup receipt gains `stopped`: the stop file, not the harness's own exit or the deadline, ended the harness or fenced its launch. Receipts without it still parse. `SandboxSession` opts in with `pausable=True` and gains `pause_harness()` / `continue_harness()`, which read an existing receipt first, `execute(pause_allowance_s=...)` for the provider deadline, `session_root`, and `checkpoint_state()` / `reattach()` to rebind a session to the sandbox a restore forks from a snapshot. `run_until_parked()` races a launch against the activation's park request: it pauses the harness, parks the activation at the adapter's boundary, continues the harness after the resume, and keeps racing for the next checkpoint. A pause that is not confirmed, or a continue that fails three times, falls back to the stop the supervisor already had; the adapter then relaunches. A cancelled activation still stops its harness, shielded and bounded. Where the provider has them, a confirmed pause holds the launch's command polls in the sandbox's parked_exec_polling() scope until the continue, so a sandbox being snapshotted is not polled, and a stop for a checkpoint runs in checkpoint_exec_polling() so the provider notices the launch's end promptly. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]> * feat(opencode): pause at checkpoints and resume after a crash OpenCode episodes were restarted from scratch by every checkpoint restore, and a checkpoint had to wait for the harness. The agent now exports its sessions and uses the shared pause mechanism. - checkpoint_mode = "exported" and rebinds_tool_accesses = True. A session whose sandbox the agent owns (no sandbox_access) or a continuation session restarts instead. - A checkpointed session keeps OpenCode's conversation under the sandbox's session root, on the snapshotted disk, and the activation runs inside participant.activation(), so close and retire cancel the launch. - The launch loop runs run_until_parked: a confirmed pause parks the activation and continues the harness in place; a stopped harness is relaunched with the unspent budget (time paused does not count). A relaunch, or the first launch after a restore, resumes the saved conversation when it starts with the task and has a completed assistant message: resume_opencode.sh starts `opencode serve` in the sandbox and re-posts the last user message with empty parts, so no user turn is added. Otherwise the original prompt runs fresh, with the reason logged. - A re-sent activation index is answered from the saved reply; the reply metadata reports harness_launches. - Hooks: export_agent_sessions, restore_agent_sessions (unconnected), and _rebind_restored_agent_session_state, which connects to the forked sandbox, reattaches the SandboxSession and reinstalls missing files. A restored session that was never re-bound answers 409. - nemo_gym/testing/checkpoint_conformance.py: check_harness_adapter(), run here against OpenCode with a fake `opencode` that implements both `run` and `serve`. Provenance: NVIDIA-NeMo#4274's pause idea, resume decision and resume helper, and NVIDIA-NeMo#4553's agent half (legacy stack), rebuilt on main's SandboxSession and bash supervisor. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]> * fix(opencode): resume a saved conversation exported from OpenCode's database snapshot.py keeps each message's id beside its info, because OpenCode stores the id on the message row and not in its data; resume_payload read it from info and failed with KeyError 'id' on every real export, so every relaunch and restore started the task afresh (16-node job 8459954: 2 of 2 relaunches). Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]> * fix(opencode): retry a new sandbox's setup commands, and report a launch that saved nothing in one line A sandbox that was just created or restored can refuse a connection for a few seconds after it first answered (a gateway 502). OpenCode's seed failed on its first commands then, and the rollout started over (job 8539361: the workdir, preparation and runtime install failed for 3+ sandboxes each). - `exec_idempotent` (agent utilities) runs a command and retries it, twice, when the provider raises; a returned result, any exit code, is final. Only for commands that are safe to run twice. - OpenCode runs its workdir creation, sandbox preparation (it checks before it installs), runtime install (the installer serializes and skips a runtime in place) and the "set the conversation aside" move through it. - A restore that finds OpenCode had written no conversation yet (no root session) logs one INFO line and starts afresh, as before, instead of a WARNING with a traceback (`NoRootSessionError`). - A launch that ended without finishing and left no session database or no root session raises `NothingCapturedError`, which the session logs as one WARNING line with the runner's log, instead of a chained capture traceback on top of the launch's own error. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]> * fix(opencode): take the concurrency slot with Activation.slot, so a parked session's slot always comes back The slot was taken inside Activation.queued() but given back by a try/finally that began only after it. A retire or close of a session parked on the way out of queued(), after taking a slot while a checkpoint was open, raised before that finally, and the agent server ran with one slot fewer for good. Activation.slot() takes and releases the slot in one scope; without checkpointing, the same holds through a local helper. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]> * fix(opencode): relaunch, re-bind and stop paths found in a review of the checkpoint pause Found in a review of the harness pause and of OpenCode's relaunch. Relaunch and re-bind (OpenCode): - A relaunch that starts the task afresh no longer names the conversation it set aside. The launch command was built before the decision, so it kept `--session <id>` of the discarded conversation; it is now built after it, and the fresh start also drops the observations and trajectory of the discarded launch. - A saved conversation that cannot be read is no longer taken for a missing one. The relaunch reads the database itself, three times, and raises if it still cannot, instead of setting a resumable conversation aside after one failed download on a sandbox a restore just forked. - A restored session gets back what its seed had set and a checkpoint does not carry: `export_dir` and the environment of OpenCode's import and export. Without them a restored episode wrote no exports. - The re-bind's first command on the forked sandbox goes through `exec_idempotent`, and a re-bind that fails releases its sandbox connection instead of leaving one behind per retried seed. - A resumed launch that ends in a reported model error (API error, context overflow) is recognised: `resume_opencode.sh` exits 0 once the server answered, where `opencode run` exits 1. - A session that continues an imported conversation (`session_import_path`) restarts after a crash: a relaunch compared the imported conversation's first prompt with the task's and discarded it. - A reply given again from a saved one forwards its verification failure report, as the first reply does. - Text parts OpenCode marks synthetic are not part of the prompt a saved conversation is matched against. `resume_opencode.sh`: - The prompt request runs in the background and is waited for. Bash runs a trap only between foreground commands, so the supervisor's TERM was held until the turn ended: every stop of a resumed launch took the full grace period and the server was killed. - The server is ended with TERM: bash starts a background command with INT ignored. - The loopback request ignores proxy variables, and a path outside ASCII is encoded as its UTF-8 bytes. Pause and stop (agent utils): - A stop of a launch that is still staging cancels it. The stop had no harness to end, and the launch then ran its harness through the checkpoint, or waited until the provider deadline for the continue of a pause request that did reach the sandbox. - An error of a launch that left no receipt of a stop, for example because its sandbox died, propagates as the launch's own failure instead of parking a dead session. - A pause waits, bounded, for a launch that is staging, so a snapshot does not run beside the uploads and the launch command's polls are held like a running launch's. Process supervisor: - A hold before the launch is not added to the harness deadline again by the first pause after it. - An expire that arrives during a hold before the launch launches nothing. - A pause scans until a scan finds no new process, not twice. Other: - The launch number in the client session id is gone. Only a continuation session sets that id and only a checkpointed session relaunches, and a session is never both, so nothing could send it. - "discarded N abandoned call row(s)" is logged only when rows were dropped. - The OpenCode runtime's sandbox path prefix is a module constant, so a test whose sandbox is the test machine installs its fake CLI under its own directory instead of one /tmp path shared by every run on the node. Tests: the cases above; the receipt of a stop that fenced a launch, which has `stopped` since the pause in place; the kit's local provider; pause numbering, malformed requests and receipts; deterministic replacements for races and fixed sleeps (a harness that ticks until the test ends it, bounded waits, cleanup of a paused harness when a test fails half way); larger limits around the real supervisor. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]> * fix(checkpoint): require delete_calls of a capture ledger, and name the calls it deletes "disconnected" Review of NVIDIA-NeMo#5268. - `CheckpointableLedger` requires the method, and the model server refuses a ledger without it at startup, so the `getattr` fallback and its warning could not be reached. The method is called directly. - "abandoned" already means a rollout attempt the framework gave up on, and "discard" a fenced write. The calls are now `disconnected` (`GateSnapshot.disconnected`, `take_disconnected`), the ledger method is `delete_calls`, and the helper `delete_disconnected_calls`. Nothing of this is released, so there is no alias. - The comments describe the rule the code applies (a call that ended while admission was closed, before its response started) and the rows it leaves: an intent row and, sometimes, a failure row. - `FileLineageStore.delete_calls` removes the rollout from the cache through `_ledger_cache_pop`, which also drops the lineage caches. - `PolicyWorkerLink` uses its gate's ledger instead of a second copy. - New test: a worker deletes the rows of such a call when it reopens. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]> * fix(agent-utils): bound a checkpoint pause, retry its requests, and never park beside a launch that still writes Review of NVIDIA-NeMo#5268. Supervisor (`process_supervisor.sh`): - `--max-pause SECONDS`: a pause nobody continues used to hold the harness for good, with the deadline not running and an expire waiting for the continue. Past the limit the supervisor ends the harness as at its time limit and the receipt records `pause_expired`. The limit counts the supervisor's polls, not the clock. `SandboxSession.execute` passes the pause allowance as the limit. - The wait for a continue also ends when the harness is gone. - The usage text lists the pause options. Pause and continue requests (`supervisor_client._request`): - bounded as a whole, so a request queued behind a full provider does not wait for a harness to end; - run from `control_cwd`, so they do not need a workdir the task moved or deleted. `SandboxSession.pause_harness` answers `unconfirmed` while the launch is still staging after its wait: a pause request would only hold the launch command, and staging would keep writing during the snapshot. `run_until_parked` is now `run_with_checkpoint_pauses` (it returns when the launch ends, parked or not), and `Finished`/`Stopped` are `LaunchFinished`/`LaunchStopped`. It also: - repeats a pause request that failed in transport (4 attempts, 1 s doubling) and waits the same way between continue attempts; a timeout or an answer of the supervisor is not repeated; - treats a `receipt_missing` receipt (main's NVIDIA-NeMo#6280: the supervisor died and the provider proved the sandbox empty) after its own stop as a stopped launch, not a finished one; - raises, and does not park, when a launch cancelled while staging does not end within the stop timeout; - reads the exception of a park request or an abandoned launch, so asyncio does not log it as never retrieved. `SandboxSession.reattach` is now `rebind`, the word the checkpoint code uses; `ParkingActivation` and `SandboxSessionCheckpoint` are exported. `exec_idempotent` takes `cwd`, `env` and `timeout_s` explicitly. The conformance kit moves to `nemo_gym.agents.testing` as `check_harness_checkpointing`: it checks an agent adapter, and can now import `AGENT_ACTIVATION_HEADER`. Its local provider is private. The crash scenario ends the first agent (handles, processes, tasks) before the restore and cleans up in a `finally`, and an adapter can supply `crash_recovery_assertion` to prove the recovery continued the saved conversation. Tests: the deadline-extension test now fails without the extension, the hold test no longer asserts a tight real-time bound, and each change above has tests. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]> * fix(opencode): bind a saved reply to its request, keep the trajectory in a checkpoint, and reprompt like a first launch Review of NVIDIA-NeMo#5268. - A saved reply is given again only to the request that produced it: the session keeps the request's SHA-256 with the reply, also in the checkpoint, and a different request under the same activation index is a 409, as before this PR. - The checkpoint keeps a finished session's trajectory, restored under the replacement attempt's rollout ID, so a session that finished before the checkpoint still closes with it, also when closed before it is re-bound. - A re-bind that has to install the runtime again passes the seed's pinned ripgrep and plugin dependencies, and stages them through the sandbox connection it holds (`state.session` is not set yet). - "Resume" names the checkpoint step, so continuing a saved conversation is a reprompt: `reprompt.py`, `reprompt_opencode.sh`, `RepromptDecision`. `discard_conversation` is `set_conversation_aside` (`data.set-aside-N`). - The reprompt helper rejects permission requests, as `opencode run` does; under `opencode serve` nothing answered one and the turn waited until the harness deadline. It keeps the server's log and the request's status in the launch directory, and prints the log's end when the request fails. - A saved conversation that downloads but cannot be parsed starts the task afresh under its own reason; one that cannot be downloaded is still retried and then fails the activation. - Tool calls a relaunch finds unfinished are counted once each (`interrupted_tool_calls` in the launch record) and mark the observations with the gap `tool_call_interrupted_by_relaunch`. - The reply's metadata carries `harness_paused_seconds` next to `harness_launches`. - `_reported_model_error` keeps main's exit-0 context overflow (NVIDIA-NeMo#6471) for a launch that did not reprompt. - The preparation command's package install takes a lock, so a retry that overlaps its first run waits for it. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]> * docs(opencode): document partial-rollout checkpoints, their limits, and the supervisor's pause files Review of NVIDIA-NeMo#5268: the OpenCode README gets a section on checkpoints (settings, what a pause and a stop do, pause limits, clocks, recovery after a crash, the reprompt, interrupted tool calls, restart-only sessions); the agent integration page summarizes it; the harness guide lists the pause and continue files, `stopped` and `pause_expired` in the receipt, and `run_with_checkpoint_pauses`. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]> * test(hermes): expect `stopped` in the receipt of a stop that fenced the launch The supervisor now records that a stop request, not the harness's own exit or the deadline, ended or fenced the launch. Hermes's test compared the whole receipt. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]> * fix(opencode): do not repeat a refused continue, give retries one budget, and report a timeout after a stop Second review round of NVIDIA-NeMo#5268. - A continue the supervisor answered with a refusal is not sent again: the same sequence number would read the same answer from the acknowledgement file. `HarnessPauseResult.acknowledged` tells such an answer from a lost one, which is still retried. - `exec_idempotent`'s `timeout_s` is the budget of all attempts and the waits between them, not of each attempt. - When a launch was stopped at a checkpoint and the activation's budget is spent, nothing is relaunched: the reply is built from the stopped launch and reports a timeout. Preparing the relaunch used to discard that launch's output and then raise. - A re-bind installs the runtime again only when the check of its files ran and found some missing. A check the provider could not run is repeated and then fails the re-bind. - `prepare_launch` creates the launch directory through `exec_idempotent`. - The observation bundle of a restored session closed before its re-bind is schema 2.0, like every other close. - The saved conversation's export is read and decoded in the worker thread that makes it. - The test of the unread park-request exception now fails without its fix. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]> * test(agents): run the harness checkpoint conformance kit against a minimal adapter in the core suite The kit's main check only ran in OpenCode's server suite, which the core coverage gate does not measure, so the combined core coverage fell to 94.86%. A reference adapter whose harness is a shell loop now takes the kit through every scenario with the real process supervisor, and a second test shows the kit fails an adapter that cannot pause in place. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]> * fix(opencode): hold a checkpoint for staging that is still writing, bound retries by one deadline, and report a timeout when the relaunch budget runs out - run_with_checkpoint_pauses: a launch cancelled while staging is not reported stopped while its staging task still runs, and no error leaves the activation until the launch has ended and staging no longer runs. Until then the session is not ready, so the checkpoint waits for it up to its own deadline. SandboxSession gains staging and wait_staged. - exec_idempotent: every attempt runs under the one deadline, which now also bounds a provider's wait for capacity; no attempt starts once the budget is spent. - OpenCode: what a stopped launch produced is kept until its relaunch has started its harness. A budget that runs out before then, while the relaunch is prepared or staged, ends the activation as a timeout with the stopped launch's output. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]> * style(opencode): format a test line the linter rejects Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]> * fix(opencode): reprompt a saved conversation whose prompt was sent quoted as one argv word With argv_prompt_quoting (NVIDIA-NeMo#5458) a launch sends the prompt as `opencode run` builds it from one argv word, so the saved user turn holds the quoted text. A relaunch after a stop compared that turn with the unquoted prompt, found no match, and started the task afresh every time. It now compares with the prompt as the launch sent it. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]> --------- Signed-off-by: Pranav Thombre <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
What does this PR do?
Stacked on #6279; review that first.
Shared harness supervisor (
nemo_gym/agents/utils):stop.requestis counted as a foreign signal andignored; the controller only ever stops a run by writing
stop.request. Before this, a tool command such aspkill -f pythonorkillall bashcould end the harness and lose the episode. The receipt recordsforeign_signals.died without writing its receipt,
stop_and_confirm_cleanupcan confirm cleanup through the provider instead(
exec_processes_terminated, from feat(sandbox): bwrap sandbox provider #6279).codex_agent:
tool_pid_namespace(default off): Codex tool commands run in a nested bwrap pid namespace on a tool host, sopkillorkill -9 -1cannot reach the harness. Harness-kill evidence (exit code 128+N, receipts) is reported asobservation gaps.
failure_artifacts_dirkeeps a failed activation's supervisor and Codex logs.tool_namespace_checkruns the isolation check end to end against a real bwrap, and optionally the real Codex CLI.Validation
At e1a3080 (round 2, which merges #6279's round 2; 2fdb5f9 had 1295 passed):
NEMO_GYM_REQUIRE_BWRAP=1):pytest -m "sandbox or not sandbox" tests/unit_tests/agents responses_api_agents/codex_agent/testsplus thebwrap tests: 1301 passed.
tool_namespace_checkpasses in fake mode, both isolated and as the control run. The real-Codex mode needsNEMO_GYM_TEST_CODEX_RUNTIMEand was not run.Real-model smoke at 2fdb5f9 (round 2 changes only the failure-log tail, review fixes and #6279's round 2) (Ubuntu 24.04 host, Debian 12 container, bwrap 0.8.0, non-root; GLM 5.3 through
the NVIDIA inference API; DAPO-Math example tasks):
tool_pid_namespace: true, own bwrap sandbox: 2 of 2 episodes completed, reward 1.0. Toolcommands and an interactive
exec_command/write_stdinsession ran through the tool host, with noharness-kill, missing-receipt or ignored-signal gaps.
pi_agent), own bwrap sandbox: the episode was cancelled mid-turn by a 120 s episode timeout, andthe session closed with cleanup confirmed. Uncut, the same task completes in 56 s, reward 1.0.
(
kernel.apparmor_restrict_unprivileged_userns=0) for the nested namespace.Rollouts
Same production use as #6279: the tool namespace was on for every published episode.
Compatibility and benchmark impact
Behaviour changes for every sandboxed harness:
stop.requestis ignored and counted asforeign_signals. EveryGym controller stops through
stop.request, but a runtime teardown TERM alone no longer produces a receipt.This keeps the supervisor alive, not the harness: the runner still relays TERM to the harness CLI, so a tool's
killall bashcan still end a harness withouttool_pid_namespace. What changes is that the receipt now recordshow it ended. Only stop signals are covered; USR1, USR2, ALRM and PIPE still end the supervisor.
confirms cleanup through the provider (
exec_processes_terminated, bwrap only today) instead of failing with"outcome unknown". The receipt then carries
receipt_missing: True, so adapters can tell it from a clean stop.Everything in codex_agent is opt-in.
Checklist
git commit -s).🤖 Generated with Claude Code