Repository navigation
feat(terminal-bench-science): run three more harnesses in the task sandbox - #5459
Open
gwarmstrong wants to merge 40 commits into
Open
gwarmstrong wants to merge 40 commits into
gwarmstrong wants to merge 40 commits into
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
…ndbox Claude Code, OpenCode and Pi profiles for Terminal-Bench-Science v0.1, composed like the Codex profile: the TB4 resources server lends the task sandbox, each harness runs in it with the PR 8 opt-ins that match Harbor 0.24's agents, and single_agent_turn_legacy grades the episode. Signed-off-by: gwarmstrong <[email protected]>
Contributor
Author
|
/ok to test 84ac5a7 |
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]>
…bench-science-more-harnesses-v2 Signed-off-by: gwarmstrong <[email protected]>
Contributor
Author
|
/ok to test 830d6a6 |
Contributor
Author
|
/ok to test 815e56e |
OpenCode: _sandbox_prepare_command takes both this branch's allow_root and main's export_dir, the seed keeps main's sandbox_id check, and the remaining-context plugin loads with Gym's plugins, before main's owner-staged ones. With allow_root and a workdir of /, main's export_dir check still refuses any export_dir, since every path is inside /. The OpenCode and Claude Code READMEs keep main's benchmark-profile paragraphs, then this branch's task-container settings. Signed-off-by: gwarmstrong <[email protected]>
Main's egress change (NVIDIA-NeMo#5554, NVIDIA-NeMo#5555) builds an owned sandbox's network policy from the Gym model server's URL. With model_base_url set and no model_server, that read failed on None, so Pi and OpenCode could not seed a sandbox they create, whatever network_access was. The policy now takes the direct endpoint in that case, so model_only opens the endpoint's host. Each adapter's tests seed an owned sandbox with a direct endpoint under inherit and model_only; they fail without this change. Signed-off-by: gwarmstrong <[email protected]>
Preserve sandbox opt-ins alongside prompt images, protected activation staging, MCP grants, and step-limit reporting. Keep the corrected judge-only benchmark guidance. Signed-off-by: yaoyu-33 <[email protected]>
…dbox-opt-ins Signed-off-by: gwarmstrong <[email protected]> # Conflicts: # nemo_gym/agents/__init__.py # responses_api_agents/pi_agent/app.py # responses_api_agents/pi_agent/tests/test_sandbox_runner.py
…d the model Pi and OpenCode sandbox sessions drop the direct model endpoint (model_base_url, model_api_key). Their calls go through the Gym model server again, so Gym captures and correlates every call. That route now takes the settings the direct endpoint was added for: main's OpenAI 2.45 schemas (NVIDIA-NeMo#5464) accept chat reasoning_effort "max". The direct-endpoint egress fix goes with it; owned sandboxes open the model server's host as on main. verify_after_agent_error now treats more failed runs as setup failures, which stay execution errors and are retried, never graded, as Codex does on main for a run that never started a turn: - Pi: a nonzero exit before Pi ended its first assistant turn, unless the time limit stopped it. - OpenCode: a nonzero exit before any model step ran, unless the time limit stopped it; and a run whose required Gym MCP tools were never confirmed, also when OpenCode then exited nonzero for another reason. The READMEs no longer link to Terminal-Bench-Science sections that are not on main, and Pi's notes that `thinking: max` needs pi_version 0.80.6 or later (the default pin is 0.80.2). Signed-off-by: gwarmstrong <[email protected]>
prefer_oom_kill_setup's docstring implied that the supervisor and the exec daemon survive an OOM kill. Where the container's memory cgroup sets memory.oom.group=1 (cgroup v2, as some kubelets configure it), the kernel kills every process in it. The harness-runner tests now also check that an inherited events_exclude filters nothing when the params leave it unset; the test fails without the runner's unset. Signed-off-by: gwarmstrong <[email protected]>
…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]>
…bench-science-more-harnesses-v2 Signed-off-by: gwarmstrong <[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]>
…e Harbor entry Signed-off-by: gwarmstrong <[email protected]>
armarkos
approved these changes
Nov 25, 2026
armarkos
left a comment
There was a problem hiding this comment.
Approved. Please make sure the CI is clean.
…nch-science-more-harnesses-v2 Signed-off-by: gwarmstrong <[email protected]> # Conflicts: # nemo_gym/agents/__init__.py # nemo_gym/agents/utils/harness_runner.sh # nemo_gym/agents/utils/sandbox_session.py # responses_api_agents/claude_code_agent/README.md # responses_api_agents/claude_code_agent/app.py # responses_api_agents/claude_code_agent/tests/test_task_container_sessions.py # responses_api_agents/opencode_agent/README.md # responses_api_agents/opencode_agent/app.py # responses_api_agents/opencode_agent/sandbox.py # responses_api_agents/opencode_agent/tests/test_opencode2_session.py # responses_api_agents/opencode_agent/tests/test_sandbox_runner.py # responses_api_agents/opencode_agent/tests/test_task_container_sessions.py # responses_api_agents/pi_agent/README.md # responses_api_agents/pi_agent/app.py # responses_api_agents/pi_agent/tests/test_sandbox.py # tests/unit_tests/agents/test_harness_runner.py
…ion fields Main's check-manifest-selection-fields hook requires maintainers, capabilities, domains, requirements and primary_metric. The Pi, OpenCode and Claude Code manifests take the miniswe manifest's values, which runs the same Harbor entry, and its list modality and full canonical split. Signed-off-by: gwarmstrong <[email protected]>
…_gym.config Code outside nemo_gym imports from a package's public API (test_public_api_facades). Signed-off-by: gwarmstrong <[email protected]>
Contributor
Author
|
/ok to test 67c59ef |
Contributor
Author
|
@armarkos this PR changed after your approval, could you take another look? The three presets now run on the Harbor route that the miniswe preset took in #5991, instead of composing the TB4 resources server, and the branch carries main's copy of every #5458 file, so the diff is this PR's 10 files only. The description is updated, with new smokes at 67c59ef on Kimi K3.1 Pro: Pi and Claude Code passed 43/43 on eeg-erp-recovery, and OpenCode reached the 30-minute cap on mri-harmonization at 1/8. |
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Adds Terminal-Bench-Science presets for Pi (0.80.10), OpenCode (1.17.11) and Claude Code (2.1.207). They run on the Harbor route that
terminal_bench_science/miniswetook in #5991:environments/harbor/terminal_bench_sciencewithharbor_target.Client settings. Each preset starts its CLI as a plain launch in the task container would, with the client settings #5458 added:
max, the CLI's own tools and prompt, the task's working directory (/included) and/logs/agent.verify_after_agent_errorandraise_oom_score_adj.The README lists every setting.
Server settings. They are the miniswe preset's: the episode bound, sandbox labels, 100 GiB disk and
resource_requests: limits. The presets add 1200 s of harness setup for the CLI installs, so the episode bound is 47100 s.Model calls. Every model call goes through the Gym model server.
--model-type openai_model, which passes their chat requests through and keeps the reasoning separate.vllm_model's chat route returns the reasoning inside the message text (measurements in feat(agents): Pi, OpenCode and Claude Code opt-ins for Harbor-style sandbox runs #5458)./v1/messages. Its preset setsmodel_server, becauseclaude_code_agent.yamlsets no route and the CLI would otherwise call Anthropic's own API.An earlier version of this PR composed the TB4 resources server with
single_agent_turn_legacy, and each CLI called its endpoint directly. #5991 and the review of #5458 moved both away from that. Since #5458 merged, this branch merges main with main's copy of every #5458 file, so the diff is this PR's 10 files only.No issue: these are presets for the benchmark added in #4879.
Validation
At 67c59ef (main 64d738e):
resources_servers/terminal_bench_4/tests, in that server's ownuv syncenvironment): 404 passed, 1 skipped. They include the new preset tests: each preset resolves throughharbor_benchmark, carries the miniswe preset's server settings with the 1200 s setup, and carries its harness settings.tests/unit_tests/environmentandtests/unit_tests/test_public_api_facades.py, 1961 passed.test_environment_validation.pychecks the three manifests.tests/unit_testsin auv sync --extra dev --extra telemetry --extra mlflow --extra wandbenvironment, Python 3.13.14. The only failures are 100 tests that fail the same way on main 64d738e here: sandbox, Docker Compose, request-gzip hook and CI-environment tests, none in a file this PR touches.PiAgentConfig,OpenCodeAgentConfig,ClaudeCodeAgentConfig,HarborEnvironmentServerConfig). No key is unknown, and every default value validates.gym eval prepare --benchmark terminal_bench_science/{pi,opencode,claude_code}on the pulled entry with recorded images prepares 66 tasks each. The 3 unsupported Compose tasks andanimal-reid, whose image was not recorded, are skipped.Rollouts
At 67c59ef, each preset ran as shipped:
gym eval run --benchmark terminal_bench_science/{pi,opencode,claude_code} --sandbox opensandbox --only-tasks <task>.max. Pi and OpenCode went throughopenai_model. Claude Code went throughvllm_model's/v1/messages, on this branch with fix(model): keep streaming /v1/messages calls open while they run #7157 merged in (483e1684e).tbsci_agent_max_timeout_sec: 1800) and one task per harness. For Claude Code, the config also set API and stream-idle timeouts of 3,000,000 ms.<think>in its 20 messagesincomplete<think>in its 35 messages/v1/messages<think>, the eval default[1m], so the CLI assumed its 200,000-token default window. A run that wants the served window setstbsci_claude_modelto the name with[1m]andCLAUDE_CODE_AUTO_COMPACT_WINDOWto the window.Earlier smokes. Before #5458 merged, the same harness and server settings ran at its commit dac94f7 against self-hosted DeepSeek V4.1 Flash (
gym eval run terminal_bench_science --agent ...). All three runs reached the 30-minute cap:A forced setup failure (OpenCode with an invalid
permissionvalue) exited at startup before any model step. It was not graded, and no verifier ran.Compatibility and benchmark impact
gym dataset pull terminal_bench_scienceand recorded images./v1/messagescall whose generation takes more than 300 s also needs fix(model): keep streaming /v1/messages calls open while they run #7157. Without it, the model server sends nothing until the generation ends, and the CLI abandons the call.