Repository navigation
feat(agents): Pi, OpenCode and Claude Code opt-ins for Harbor-style sandbox runs - #5458
Conversation
Benchmarks that grade a harness started inside the task container (Harbor's agents) need Pi to run with its own tools and prompt, call the benchmark's model endpoint, and leave logs where the verifier side collects them. Pi's sandbox sessions could only call a Gym model server with Gym's runtime guards, and they lost Pi's context-limit outcomes with Pi 0.80.10. All new settings are off or empty by default, so existing configs behave as before: - model_base_url and model_api_key: Pi calls an OpenAI-compatible endpoint directly from the sandbox instead of a Gym model server (set exactly one). Gym does not capture those calls. - thinking_level_map and provider_compat for the generated provider, so that `--thinking max` can send chat reasoning_effort "max"; settings merged recursively over Gym's settings.json (for example retry counts). - sandbox_env, and sandbox_runtime_guards: false to run Pi's own tools and system prompt without Gym's bash cap and prompt note. - session_prompt_cache_key: one prompt_cache_key per session on every call, so a gateway that routes on it keeps the session on one replica. - sandbox_logs_dir and log_requests: Pi's JSON events (pi.txt), its stderr and a per-request log without the conversation in a sandbox directory such as Harbor's /logs/agent. - raise_oom_score_adj: Pi and its tools become the memory-cgroup OOM killer's preferred victims, not the exec daemon or the supervisor. - verify_after_agent_error: a Pi run that failed while its sandbox still runs and answers is returned as a gradable failed response, as Harbor grades after any agent exit, unless its terminal error is a transient model-endpoint failure (after Pi's own retries) or cleanup is unconfirmed. The runner drops Pi's streaming message_update and tool_execution_update events, which repeat the whole partial message on every delta, so long turns no longer grow the event log quadratically. Pi 0.80.10 routes extension console output to stderr in JSON mode, so outcome.mjs writes its records to a session file that the runner appends to the event log; before, context-limit outcomes never reached the adapter in sandbox sessions. Local runs keep printing them. The task's HOME, the agent timeout from the task metadata and the runner's cleanup on capture errors are upstream behaviour and unchanged. Signed-off-by: gwarmstrong <[email protected]>
opencode_agent sandbox sessions could only call a Gym model server. A benchmark that grades a harness started in the task container, as Harbor runs OpenCode, has the harness call the model endpoint itself, and routing those calls through a Gym model server changes the requests the endpoint sees. model_base_url and model_api_key (both unset by default) point the session's OpenAI-compatible provider at an endpoint the sandbox reaches, sending `model` as the model ID; set exactly one of model_server and model_base_url. Gym does not capture those calls, so the model-call correlation plugin is not loaded for them. Sessions with a model server and local calls are unchanged. Signed-off-by: gwarmstrong <[email protected]>
A sandbox session's provider sent no reasoning effort, replayed reasoning only as reasoning_content, capped every call at max_output_tokens and told OpenCode the model's size, so it compacted before the endpoint's real limit. A harness started in a task container with its own model config does none of that, and some endpoints read the replayed reasoning from another field. Four settings, whose defaults keep today's requests: - reasoning_effort: the model's reasoningEffort option, sent as chat reasoning_effort on every request. - interleaved_reasoning_field: the assistant-message field that replays each turn's reasoning (default reasoning_content). - output_token_policy: remaining_context loads a plugin that drops max_tokens from the session provider's requests, so the endpoint picks the output budget, as opencode_sandboxed_agent's policy of that name does. - declare_model_limits: false leaves the model's size unknown to OpenCode, which then compacts only when the endpoint reports an overflow. Signed-off-by: gwarmstrong <[email protected]>
Two gaps kept a sandbox session from running OpenCode the way a harness started in the task container does: - Task images without a WORKDIR start in /, and sessions rejected that workdir because the adapter's runtime and session files under /tmp sit inside it. allow_root_workdir accepts exactly / (the files stay under /tmp, as a harness's own files do there); /tmp and the adapter's own directories are still rejected, and other workdirs keep the full overlap check. - A launcher that passes the instruction as one argument, as Harbor 0.24's opencode agent does, makes `opencode run` wrap it in double quotes (inner quotes escaped) before the model sees it. Sessions send the instruction on stdin, unquoted. argv_prompt_quoting sends the text OpenCode builds from that argument instead. Both are off by default. Signed-off-by: gwarmstrong <[email protected]>
Harbor runs the verifier after any agent exit that is not a timeout, so a trial whose agent died while its sandbox still answers is graded, not rerun. opencode_agent sessions raised an execution error for every failed OpenCode run (a nonzero exit, an error on an assistant turn, no terminal result), so the Environment Server skipped verification and retried the episode from scratch: an OpenCode the kernel's OOM kill hit, one whose own pkill hit it, or a request the endpoint rejected. verify_after_agent_error (off by default) returns such a run as a `failed` response (`incomplete` when it also hit its time limit), with the error in metadata.graded_agent_error, which Resources grades as a nonzero agent exit. It applies only when the supervisor confirmed cleanup, the run's session export was read, the last assistant turn's error is not a transient model-endpoint failure (OpenCode's retryable APIError: 429, 5xx, reset or lost connections, header and stream timeouts) and the sandbox still reports running and answers a probe command. Anything else stays an execution error and is retried. raise_oom_score_adj (off by default) makes OpenCode the OOM killer's preferred victim in its sandbox, as codex_agent's setting of that name does: the runner raises its own oom_score_adj, which OpenCode and its tools inherit, to 1000, or to 0 when the sandbox starts it below zero. The exec daemon and the supervisor keep the sandbox's own score. Signed-off-by: gwarmstrong <[email protected]>
Sandbox sessions pass the instruction to `claude -p` as an argument after `--`. Harbor 0.24's claude-code agent pipes it on stdin instead, and on a command line the task's own words are a target: an agent that runs `pkill -f <word from its task>` stops its own Claude Code. instruction_on_stdin (off by default) leaves the instruction out of argv and has the runner feed it to the CLI on stdin from a session file. Without it, the runner keeps stdin empty, as before. Signed-off-by: gwarmstrong <[email protected]>
Running Claude Code against a self-hosted model the way its provider's Claude Code guide configures it needs three client settings the agent could not express: the reasoning effort (`--effort`, which Harbor passes from its reasoning_effort), the per-call output cap (CLAUDE_CODE_MAX_OUTPUT_TOKENS) and further client environment such as API_TIMEOUT_MS or CLAUDE_CODE_AUTO_COMPACT_WINDOW. A settings file on the agent host could carry environment, but not from a run config, and not the CLI flag. reasoning_effort, max_output_tokens and extra_env (all unset by default) apply to local and sandbox launches alike. extra_env rejects the variables the agent sets itself (endpoint, credentials, model, CLAUDE_CONFIG_DIR, the output cap), and YAML integers become strings. Signed-off-by: gwarmstrong <[email protected]>
A task image without a WORKDIR lends "/" as its working directory, and sandbox sessions refuse it because the runtime and session files under /tmp sit inside it, so every such trial fails at session start while a harness started in the container runs there. allow_root_workdir (off by default) accepts exactly "/". The runtime and session files stay under /tmp; /tmp itself, the adapter's own directories and relative or `..` paths are still refused. Signed-off-by: gwarmstrong <[email protected]>
…essions Before Harbor 0.24 installs Claude Code in a task container, its claude-code agent runs ensure_system_dependencies for curl, bash, nodejs, npm and procps: each one whose commands are missing is installed as root with the first package manager found. Agents graded under Harbor therefore have node, npm, ps and pkill even where the task image lacks them, and a sandbox session that skips the step runs Claude Code in a different environment. harbor_system_dependencies (off by default) runs the same decisions as one POSIX sh script (system_dependencies.py: Harbor's checks, package names, manager order and install command lines, logged line by line) before the session installs Claude Code, bounded by system_dependencies_timeout_seconds (default 1800). Where Harbor errors the trial on a failed install, the session logs the failure and runs Claude Code anyway. The script's tests run it under real shells with stand-in package managers. Signed-off-by: gwarmstrong <[email protected]>
Signed-off-by: gwarmstrong <[email protected]>
… extension writes them Signed-off-by: gwarmstrong <[email protected]>
Signed-off-by: gwarmstrong <[email protected]>
Signed-off-by: gwarmstrong <[email protected]>
Signed-off-by: gwarmstrong <[email protected]>
…dbox-opt-ins Signed-off-by: gwarmstrong <[email protected]> # Conflicts: # nemo_gym/agent_utils/sandbox_session.py # responses_api_agents/opencode_agent/app.py # responses_api_agents/pi_agent/app.py # responses_api_agents/pi_agent/tests/test_sandbox.py
|
/ok to test 05da63a |
With verify_after_agent_error, Pi and OpenCode graded any failed run while the sandbox still ran. A run the harness runner could not start (exit 125, 126 or 127), a Pi run whose Gym MCP tools did not load (exit 78), or an OpenCode run whose required Gym MCP tools did not connect or were never confirmed is a setup failure: it now stays an execution error and is retried, never graded as the agent's result. Signed-off-by: gwarmstrong <[email protected]>
|
/ok to test a566b2d |
…dbox-opt-ins Signed-off-by: gwarmstrong <[email protected]> # Conflicts: # responses_api_agents/opencode_agent/app.py
reasoning_effort, interleaved_reasoning_field, output_token_policy, declare_model_limits and argv_prompt_quoting set OpenCode 1's provider configuration and launch. The OpenCode 2 session added on main builds its own and would ignore them, so its seed now refuses them, as it refuses plugin dependencies. raise_oom_score_adj is a harness runner setting and now reaches the OpenCode 2 runner too. Signed-off-by: gwarmstrong <[email protected]>
|
/ok to test dac94f7 |
|
@yaoyu-33 @lafrancef the 11-10 review is addressed in 34e10bc:
Since then I merged main (11-16), and dac94f7 refuses the OpenCode 1 launch settings on OpenCode 2 (#6001). Could you take another look? |
…dbox-opt-ins Keep both sides in the OpenCode agent: the branch's sandbox-session settings and main's compaction-buffer validator, and both sets of OpenCode 2 seed-refusal test cases. Signed-off-by: gwarmstrong <[email protected]> # Conflicts: # responses_api_agents/opencode_agent/app.py # responses_api_agents/opencode_agent/tests/test_opencode2_session.py
|
/ok to test c19798e |
yaoyu-33
left a comment
There was a problem hiding this comment.
Thanks for removing the direct endpoint and fixing the startup cases from the first review. I rechecked c19798e through the Pi and OpenCode HTTP handlers with a simulated sandbox. Two grading decisions still need fixes before approval. The inline comments give the inputs and observed responses. The Claude Code dependency comment is a separate, non-blocking Harbor compatibility note.
| and output_captured | ||
| and self.config.verify_after_agent_error | ||
| ): | ||
| last_error = native_result.get("error") |
There was a problem hiding this comment.
On a timed-out continuation, classify_opencode_run can see an APIError with status 503 in stdout even when the exported assistant message has no error. With that input I got HTTP 502 with verify_after_agent_error off. Turning it on returned HTTP 200 with status="incomplete" and graded_agent_error containing the 503. Please carry the structured stdout error into this check so the endpoint failure stays retryable. The existing test_opencode_error_during_timeout_fails_http_activation is a good place to cover the opt-in with a stdout-only 503.
There was a problem hiding this comment.
Fixed in 377d76d. The endpoint check now reads the first stdout error event as well as the last assistant message's error, so a stdout-only APIError 503 keeps the run an execution error. test_opencode_error_during_timeout_fails_http_activation now covers the opt-in: a stdout-only 503 stays HTTP 502 with no graded_agent_error. A stdout-only 400 is still graded (incomplete at the deadline), so the test also shows the opt-in is active.
| ): | ||
| LOG.warning("Pi failed in setup; not grading it: %s", detail) | ||
| return None | ||
| if _MODEL_ENDPOINT_ERROR.search(error): |
There was a problem hiding this comment.
This regex gets a single string chosen from the process and provider errors. I reproduced both directions with verify_after_agent_error enabled and a live sandbox:
- After a
toolUseturn and exit 0 with no final answer, the adapter generatesPi ended without a terminal assistant result. The regex matchesended without, so activation returns HTTP 500 and skips grading the partial work. - After a provider 503 with
willRetry=true, exit 1 before the retry replaces the provider message withPi exited with code 1. Activation returns HTTP 200 withgraded_agent_error, making the outage gradable.
Please retain the provider diagnostic separately from the process exit and apply the endpoint check to the provider evidence. Both cases would make useful opt-in regressions.
There was a problem hiding this comment.
Fixed in eaee2f1. The adapter now keeps Pi's error for its last model call (the terminal assistant's errorMessage, or the failed compaction's) apart from the process-exit text, and the endpoint regex reads only that provider evidence. Both of your cases are now regressions in test_failed_run_is_graded_only_while_its_sandbox_runs:
tool_use_exit_0: graded, withgraded_agent_error=exit 0: Pi ended without a terminal assistant result.endpoint_then_exit: a 503 withwillRetry=true, then exit 1, returns HTTP 500 and is not graded.
rejected_then_exit (a 400, then exit 1) is still graded, as a provider rejection is.
| system_dependencies_command(), timeout_s=self.config.system_dependencies_timeout_seconds | ||
| ) | ||
| log = (result.stdout or "") + (result.stderr or "") | ||
| if result.return_code != 0 or result.error_type: |
There was a problem hiding this comment.
Non-blocking Harbor parity note. With harbor_system_dependencies enabled, a failed package install is logged and the task starts. If procps was missing and the package mirror failed, the verifier can then score work done without the expected tools. The README documents this choice. For runs intended to match Harbor, could a nonzero package-manager exit fail session setup? Harbor 0.24 runs the install as root and propagates that failure. Harbor install path.
There was a problem hiding this comment.
Done in 3e73920. A nonzero package-manager exit, or the step's time limit, now fails session setup, so the episode is retried rather than graded without the tools. With no supported package manager, the step still only warns, as Harbor does. The README and the config comment say so.
With verify_after_agent_error on, a timed-out continuation whose exported assistant message has no error but whose stdout carries an APIError 503 event was graded as a failed answer. The endpoint check now reads the first stdout error event as well as the last assistant message's error, so the run stays an execution error and the episode is retried. Signed-off-by: gwarmstrong <[email protected]>
The endpoint regex read one error string that could be either Pi's provider message or the adapter's own process text. Two cases went wrong with verify_after_agent_error on: - a tool-use turn then exit 0 produced "Pi ended without a terminal assistant result", which matched "ended without", so partial work was not graded; - a provider 503 with willRetry=true then exit 1 replaced the provider message with "Pi exited with code 1", so the outage was graded. Keep Pi's error for its last model call apart from the process exit and run the endpoint check on that provider evidence only. Signed-off-by: gwarmstrong <[email protected]>
… fails harbor_system_dependencies exists for Harbor parity, and Harbor 0.24 errors the trial when its system-dependency install fails. Gym logged the failure and started the task, so the verifier could score work done without procps or node. A nonzero package-manager exit (or the step's time limit) now fails session setup and the episode is retried. With no supported package manager, the step still only warns, as Harbor does. Signed-off-by: gwarmstrong <[email protected]>
|
/ok to test 3e73920 |
…dbox-opt-ins Signed-off-by: gwarmstrong <[email protected]>
Main (NVIDIA-NeMo#6020) records the sandbox's id at the end of Claude Code's seed, so a stub sandbox without sandbox_id fails setup. The stubs in test_sandbox.py gained one in that change; these two did not exist yet. Signed-off-by: gwarmstrong <[email protected]>
|
/ok to test e5453a6 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/44935156869 |
…oted as one argv word With argv_prompt_quoting (#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]>
…-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]>
…e-v1-v2 Resolve conflicts with main's checkpoint/resume (#5268) and task-container (#5458) work: - app.py: keep main's _reported_model_error signature (reprompted) with the _CLASSIFIED_OPENCODE_VERSIONS docstring; take main's _install_session_files call and pass the release digests for every pinned version there, as the PR did inline. - README.md: OpenCode 2 prints v2.3.2, plus main's task-container sentence. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
…route terminal_bench_science/pi, /opencode and /claude_code now name the Harbor entry with harbor_target, as terminal_bench_science/miniswe does (NVIDIA-NeMo#5991), instead of composing the TB4 resources server and single_agent_turn_legacy. Each carries the miniswe preset's server settings with 1200 s of harness setup, and its CLI's Harbor-style client settings. Model calls go through the Gym model server: Pi and OpenCode no longer have a direct endpoint (NVIDIA-NeMo#5458), and the README says to run them with openai_model, which passes chat requests through and keeps reasoning separate; vllm_model's chat route returns it inside the message text. Claude Code calls the model server's /v1/messages route; the preset sets model_server because the shipped config sets no route and the CLI would otherwise call Anthropic's API. OpenCode moves to 1.17.11, the adapter's tested version. Signed-off-by: gwarmstrong <[email protected]>
What does this PR do?
Benchmarks that grade a harness started inside the task container, as Harbor does, need Pi, OpenCode and Claude Code in sandbox sessions to take the client settings that benchmark's guide prescribes, and to be graded the way Harbor grades them. These are opt-ins on each agent, all off by default, one commit per agent and feature. Every model call still goes through the Gym model server, so Gym captures and correlates it.
pi_agent:thinking_level_mapandprovider_compat, so--thinking maxcan sendreasoning_effort: "max"(Pi accepts--thinking maxfrom 0.80.6; the default pin is 0.80.2);settingsmerged over Gym'ssettings.json;sandbox_envandsandbox_runtime_guards: falseto run Pi's own tools and prompt; a per-sessionprompt_cache_key; request and event logs insandbox_logs_dir(Pi's stderr goes there directly, and its event lines are copied there when the run is collected);raise_oom_score_adj;verify_after_agent_error. Pi's per-token update events, which made the event log grow quadratically, are left out of it. MCP tool grants (feat(pi): use MCP tool grants in sandbox sessions #4587) work with every setting.opencode_agent:reasoning_effortandinterleaved_reasoning_field;output_token_policy: remaining_context(nomax_tokens) anddeclare_model_limits: false, so OpenCode compacts only on an overflow error;allow_root_workdir(the POSIXshworkdir check accepts/);argv_prompt_quoting, the prompt as Harbor 0.24 passes it;verify_after_agent_errorandraise_oom_score_adj. Built on the multiple-activation sessions of feat(opencode): support multiple activations per session #4747. These are OpenCode 1 settings: an OpenCode 2 session (feat(opencode): support OpenCode v2 alongside v1 #6001) builds its own provider configuration and launch, so its seed refusesreasoning_effort,interleaved_reasoning_field,output_token_policy,declare_model_limitsandargv_prompt_quoting;raise_oom_score_adjandverify_after_agent_errorapply to both.claude_code_agent(on feat(claude-code): support owned and borrowed sandbox sessions #4745's sandbox sessions):instruction_on_stdin(the instruction is staged asprompt.txtand becomes the runner'sstdin);reasoning_effort(--effort),max_output_tokensandextra_env, which rejects the variables the agent sets itself,CLAUDE_CODE_DISABLE_BACKGROUND_TASKS(fix(claude-code): keep Bash commands in the foreground in headless runs #5549) included;allow_root_workdir;harbor_system_dependencies, Harbor's dependency step (curl, bash, nodejs, npm, procps when missing); as in Harbor, a failed install fails session setup.The three CLIs run through #5151's shared
harness_runner.sh, which gains one optional parameter,events_exclude(extglob patterns for stdout lines to leave out of the event log; stdout itself keeps every line).raise_oom_score_adjis a runnersetupsnippet,prefer_oom_kill_setup()insandbox_session.py: it raises the runner'soom_score_adj(to 1000, or to 0 when it starts below zero) before the CLI starts, so the CLI and its tools inherit it while the supervisor and the exec daemon keep the sandbox's own; the change is recorded in the supervisor's log. That only steers the kernel's choice of a single victim: where the container's memory cgroup setsmemory.oom.group=1, an OOM kill still ends every process in it.verify_after_agent_erroris the settingcodex_agentalready has (#5156), with the same metadata (graded_agent_error). A failed run stays an execution error, and is retried, when it is a setup failure, the sandbox is lost, cleanup is unconfirmed or the failure is a transient model-endpoint error. The endpoint check reads the model call's own error, not the adapter's process-exit text: for Pi, its error for its last model call, even when Pi then exited nonzero; for OpenCode, the last assistant message's error or an error event on stdout. Setup failures are the harness runner's own exits (125 when it failed before starting the CLI, 126 or 127 when the CLI could not be started), Pi's Gym MCP tools failing to load (exit 78), OpenCode's required Gym MCP tools not connecting or never being confirmed (also when OpenCode then exits nonzero for another reason), and a CLI that exits before its first model turn: Pi before it ends an assistant turn, OpenCode before a model step runs, unless the time limit stopped it. A model error the agent reported itself is not graded by this setting: it keeps its classified cause (#4834) for the Environment Server's outcome policy. OpenCode's sandbox observation for a graded run records outcomefailedwith error typeagent_error, the root invocation's category.These combine with main's Pi controls (#5144): with
enable_tools: false, Pi loads no runtime guards whateversandbox_runtime_guardssays and gets--no-builtin-tools, andsystem_prompt_mode: replacepasses the system prompt with--system-prompt. A sandbox run whose provider stops waiting after Pi's own deadline is still a timeout when the supervisor confirmed it, as on main.No issue: opt-in settings on the existing sandbox sessions; no default changes.
Through the Gym model server
An earlier version also let Pi and OpenCode call an endpoint directly from the sandbox (
model_base_url), because the chat route refusedreasoning_effort: "max"with a 422. Main's OpenAI 2.45 schemas (#5464) accept it, so this PR no longer has a direct mode: the calls go through the Gym model server, which captures them and keeps Gym's request metadata. What changes on the way, measured with Pi 0.80.10 and OpenCode 1.17.11 against a recording endpoint on main a5ba9d6 (one tool-call turn, then a final turn; the same CLI settings in every arm, only the base URL differs):openai_model, the endpoint receives what a direct call sends, except thatstreamandstream_optionsare dropped (the model server calls the endpoint without streaming and replays the reply as SSE) and the JSON key order.reasoning_effort: "max",max_tokens(Pi),prompt_cache_key(Pi), the tools,tool_choiceand every message arrive unchanged, the replayed assistant reasoning (reasoning_content) on the second turn included. When the endpoint answers withreasoninginstead ofreasoning_content, the replay sends it asreasoning_content, and Pi then sends it back under that key. Both CLIs keep real thinking parts, and the final answer is plain text.vllm_model, the requests match as well, but withuses_reasoning_parserits chat route returns the reasoning insidecontentas<think>…</think>. The CLIs keep it as answer text (their final message carries the tags), and the model server parses it back out on the next request. A benchmark that grades the CLI as Harbor runs it should therefore putopenai_modelin front of its endpoint.X-Request-Idwith the rollout prefix, not the CLIs' session headers (x-session-id, OpenCode'sx-session-affinity). No request was refused.Validation
pi_agent412 passed (32 skipped);opencode_agent1,071 passed (26 skipped);claude_code_agent298 passed;tests/unit_tests/agents723 passed (2 skipped).pre-commitclean on the changed files. Pi's OpenSandbox-SDK presence check fails here as before (nosandboxextra). New regressions, each failing at c19798e: with the setting on, OpenCode's stdout-only 503 on a timed-out continuation stays HTTP 502 (a stdout-only 400 is still graded); Pi's tool-use turn then exit 0 is graded, and Pi's 503 withwillRetrythen exit 1 is not (a 400 then exit 1 still is); Claude Code's failed dependency install fails session setup before Claude Code is installed. These changes are unit-tested only; the smokes below ran at dac94f7.pi_agent418 passed (22 skipped);opencode_agent1,035 passed (1 skipped);claude_code_agent251 passed;tests/unit_tests/agents634 passed (2 skipped), including the harness runner'sevents_excludeand OOM setup; the public-API, facade, import-linter and moved-path checks 1,171 passed.pre-commitclean. Deselected, failing the same way on main in this environment: Pi'stest_gym_mcp.mjsnode test (a 30 s timeout here), the OpenSandbox-SDK presence checks (nosandboxextra),test_upload_evidence_roundtrips_in_reports_and_process_projection(nocloudpickle) and OpenCode 2's plugin test (this host's Node 19 does not loadopencode2/plugin/index.jsas an ES module;opencode2/is unchanged from main).raise_oom_score_adjreaches the OpenCode 2 runner's setup. Six of the nine new cases fail without the change.events_excludefilters nothing when the runner's parameters leave it unset; that test fails without the runner'sunset.environments/harbor/terminal_bench_science, feat(terminal_bench_science): run mini-SWE through Harbor and keep the /run relay preset as miniswe_legacy_agent #5991), the model behindopenai_model(results under Rollouts). A forced setup failure, OpenCode with an invalidpermissionvalue, exited at startup ("Configuration is invalid") before any model step: it was returned as an agent error, not graded, and no verifier ran.Rollouts
N/A for the settings themselves. Smokes at dac94f7 on OpenSandbox, self-hosted DeepSeek V4.1 Flash (one replica behind the multiplexer) behind
openai_model, through main's Harbor route, the official instruction and a 30-minute agent cap. Every run reached the cap, was returnedincompleteand was graded by the separate verifier; none was retried or recorded as a failure.--thinking maxwith{max: max},provider_compat, no runtime guards,verify_after_agent_error,raise_oom_score_adj<think>in the outputreasoning_effort: max,interleaved_reasoning_field: reasoning,remaining_context, no model limits,argv_prompt_quoting,allow_root_workdir<think>in its 2 messagesinstruction_on_stdin,harbor_system_dependencies,allow_root_workdir, no turn limit,model_server: policy_model/v1/messagesCompatibility and benchmark impact
All new settings are off by default; existing configs are unchanged.