Skip to content

feat(terminal-bench-science): run three more harnesses in the task sandbox - #5459

Open
gwarmstrong wants to merge 40 commits into
NVIDIA-NeMo:mainfrom
gwarmstrong:georgea/terminal-bench-science-more-harnesses-v2
Open

gwarmstrong wants to merge 40 commits into
NVIDIA-NeMo:mainfrom
gwarmstrong:georgea/terminal-bench-science-more-harnesses-v2

Conversation

@gwarmstrong

@gwarmstrong gwarmstrong commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

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/miniswe took in #5991:

  • Each preset names the committed entry environments/harbor/terminal_bench_science with harbor_target.
  • The Harbor environment server owns each task sandbox, its Compose group and the separate no-network verifier, and lends the sandbox to the CLI's agent session.
  • There is no second task path per harness and no resources server composition.

Client settings. Each preset starts its CLI as a plain launch in the task container would, with the client settings #5458 added:

  • DeepSeek V4.1 Flash at effort max, the CLI's own tools and prompt, the task's working directory (/ included) and /logs/agent.
  • For Pi and OpenCode, also verify_after_agent_error and raise_oom_score_adj.
  • Claude Code starts as Harbor 0.24's claude-code agent does.

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.

  • Pi and OpenCode run with --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).
  • Claude Code calls the model server's /v1/messages. Its preset sets model_server, because claude_code_agent.yaml sets 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):

  • TB4 resources server tests (resources_servers/terminal_bench_4/tests, in that server's own uv sync environment): 404 passed, 1 skipped. They include the new preset tests: each preset resolves through harbor_benchmark, carries the miniswe preset's server settings with the 1200 s setup, and carries its harness settings.
  • Environment tests: tests/unit_tests/environment and tests/unit_tests/test_public_api_facades.py, 1961 passed. test_environment_validation.py checks the three manifests.
  • Core unit tests: tests/unit_tests in a uv sync --extra dev --extra telemetry --extra mlflow --extra wandb environment, 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.
  • Settings check: every server block of the three presets validates against its config class (PiAgentConfig, OpenCodeAgentConfig, ClaudeCodeAgentConfig, HarborEnvironmentServerConfig). No key is unknown, and every default value validates.
  • pre-commit: passes on the changed files.
  • Prepare: 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 and animal-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>.

  • Model: self-hosted Kimi K3.1 Pro (one replica behind the multiplexer) at effort max. Pi and OpenCode went through openai_model. Claude Code went through vllm_model's /v1/messages, on this branch with fix(model): keep streaming /v1/messages calls open while they run #7157 merged in (483e1684e).
  • Run config: a 30-minute agent cap (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.
  • Grading: the separate no-network verifier graded every run. None was retried or recorded as a failure.
Harness Task End Model calls Reasoning Tests passed
Pi 0.80.10 eeg-erp-recovery finished before the cap 61 53 reasoning items, all with text; no <think> in its 20 messages 43/43 (reward 1)
OpenCode 1.17.11 mri-harmonization reached the cap, returned incomplete not counted (no call ids without capture) 95 reasoning items, all with text; no <think> in its 35 messages 1/8 (reward 0)
Claude Code 2.1.207 eeg-erp-recovery finished after 15 min 43, through /v1/messages thinking arrived as thinking blocks; Gym's record folds it into the message text as <think>, the eval default 43/43 (reward 1)
  • Claude Code compaction: Claude Code compacted once, automatically, at 167,381 tokens. The run config gave the CLI the model name without [1m], so the CLI assumed its 200,000-token default window. A run that wants the served window sets tbsci_claude_model to the name with [1m] and CLAUDE_CODE_AUTO_COMPACT_WINDOW to the window.
  • Long calls: this run has no per-call timing, because capture was off, so it doesn't show whether any call took more than 300 s. fix(model): keep streaming /v1/messages calls open while they run #7157's own rollouts cover that.

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:

  • Pi passed 43/43 on eeg-erp-recovery.
  • OpenCode passed 5/8 on mri-harmonization.
  • Claude Code, with no effort set, was still working, at 0/43.

A forced setup failure (OpenCode with an invalid permission value) exited at startup before any model step. It was not graded, and no verifier ran.

Compatibility and benchmark impact

  • Same names, new route: the three presets keep their names but now run on the Harbor route. As with the miniswe preset, they need gym dataset pull terminal_bench_science and recorded images.
  • Claude Code on slow backends: a /v1/messages call 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.

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]>
…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]>
@copy-pr-bot

copy-pr-bot Bot commented Nov 2, 2026

Copy link
Copy Markdown

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

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@gwarmstrong

Copy link
Copy Markdown
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]>
@gwarmstrong

Copy link
Copy Markdown
Contributor Author

/ok to test 830d6a6

@gwarmstrong

Copy link
Copy Markdown
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]>
@svcnvidia-nemo-ci svcnvidia-nemo-ci added feature New capabilities, enhancements, or enablement work area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers needs-review PR is ready for code review and waiting on a reviewer labels Nov 7, 2026
yaoyu-33 and others added 9 commits November 10, 2026 10:28
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]>

@armarkos armarkos left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Approved. Please make sure the CI is clean.

@github-actions github-actions Bot removed the sla:triage-overdue Review assignment is over the one-business-day SLA label Nov 25, 2026
…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]>
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the risk:high Autobot PR risk: high label Dec 2, 2026
@gwarmstrong

Copy link
Copy Markdown
Contributor Author

/ok to test 67c59ef

@gwarmstrong

Copy link
Copy Markdown
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.

@gwarmstrong
gwarmstrong requested a review from armarkos December 3, 2026 18:55

This branch was previously deployed

1 inactive (outdated) deployment
public — 815e56e8 Deployed Nov 4, 2026 by copy-pr-bot[bot] via release / finalize / notify #10003
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer risk:high Autobot PR risk: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants