Skip to content

feat(harness): add offline scientific evaluation with OpenCode and Pi - #3570

Closed
Kipok wants to merge 15 commits into
mainfrom
codex/opencode-benchmark-workflow
Closed

Kipok wants to merge 15 commits into
mainfrom
codex/opencode-benchmark-workflow

Conversation

@Kipok

@Kipok Kipok commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Run APEX Shortlist and HLE through the shared sandbox harness with OpenCode or Pi, using offline scientific tools and optional Gym-hosted Tavily search. Benchmark preparation, answer-format requirements, repeat counts, and verifiers are preserved; HLE's format instructions move into the user message for native harnesses.

  • Add composable benchmark presets and reproducible images with scientific Python, SageMath, Lean/Mathlib, OpenCode, and Pi. Dependencies are locked; Gym uploads the selected adapter's source at rollout startup.
  • Restrict sandbox egress to the Gym model host and configured tool hosts. Model and Tavily API credentials remain in host services; agents receive per-session MCP authentication.
  • Use the inference server's remaining context budget, disable automatic compaction, disable OpenCode background titles, and cap Pi benchmark Bash calls at 120 seconds. Enclosing rollout budgets are four hours.
  • Preserve already-resolved model URLs, rollout identity, native observations and OpenCode trajectories. Save generation receipts before judging, handle Unicode separators in native exports, and keep long buffered chat streams alive.
  • Extend Tavily with bounded retries, key-pool rotation, URL exclusions, and a bounded page cache. Commit only the public HLE exclusions; deployment-specific policies stay external.
  • Allow benchmark discovery to inspect required values and absent environment settings without weakening normal run validation.

No separate issue: this extends the existing shared harness and Tavily resource. The PR remains a draft for design and implementation review.

Compatibility and limits

Existing no-tools benchmark configurations retain their behavior. These changes also affect users outside the new presets:

  • Tavily: aggregate Search Answer output is removed because its source provenance cannot be filtered. Search returns source results only. Requested and returned URLs, including reported extraction redirects, are filtered; finite exclusions cannot guarantee no answer exposure. Invalid policy domains prevent startup with file/domain diagnostics.
  • Retry/cache budgets: max_http_attempts defaults to 3 total attempts, replacing indefinite 429 retries; delays begin at 1 second and keys rotate. Exhaustion raises a tool-service error. http_timeout_s defaults to 60 seconds per attempt, and max_cached_pages to 128. Zero disables caching and its optional character cap; max_scroll_words remains independent. Concurrent cache misses are not coalesced.
  • OpenCode configuration: the standalone interleaved reasoning default from feat(agents): add ModelServerRef support to CLI agents #2047 is retained. Explicit native interleaved values now take precedence over the old forced overwrite. The benchmark preset omits the generated setting with interleaved_reasoning: false. Simultaneous legacy tools and permission are rejected; migrate rules to permission.
  • Failure handling: execution_failure_reward_zero=true requires invocation observations (Hermes, OpenClaw, OpenCode, Pi); unsupported adapters reject it at startup. Completed empty answers still go to the verifier. Explicit harness failures get zero without verifier-specific fields; setup, runner, export and judge exceptions still propagate.
  • MCP: with tool_servers, call /run; direct /v1/responses returns HTTP 400 before provisioning. OpenCode and Pi are supported. Pi's extension supports Gym's stateless JSON MCP endpoint, not arbitrary transports. The runner rejects non-model URL lookups instead of silently routing them to the model proxy.
  • Streaming: buffered SSE sets anti-buffering headers. Chat keepalives start after 15 seconds; fast backend failures retain normal HTTP handling, and late backend failures end with an SSE error. Capture/serialization failures propagate. Responses-API streams still wait silently for their backend response.

Model/tool hosts must be reachable from the assigned sandbox cell; loopback rewriting does not create routing. The inference server must support the intended context window and must not impose a smaller output cap. Tool timeouts do not prevent OOMs. Prompt placement, tool access, exclusions and token/timeout policies affect benchmark comparability.

See the harness guide, Tavily guide, and image build instructions.

Validation

  • Combined local regression suite: 838 Python tests passed, with imports pinned to the checkout and pytest -q --tb=short --import-mode=importlib. Covers discovery/benchmark composition, model dispatch and capture, rollout collection/trajectory export, shared harness, Claude Code URL routing, OpenCode/Pi, and Tavily. Seven recent regression cases also fail against their pre-fix snapshot.
  • 10 Pi JavaScript tests passed, covering Gym MCP, Bash timeout and remaining-context extensions. All four APEX/HLE × OpenCode/Pi preset compositions preserve preparation/repeats and resolve their intended budgets. Runtime package manifests match their locks.
  • Repository-wide pre-commit run --all-files and git diff --check: passed. Fern validation: zero errors; remote redirect checking skipped because the local CLI is unauthenticated.
  • The broader config suite has a separately reproduced Python 3.14/Hydra LazyCompletionHelp incompatibility; it is not included in the passing suite above. Full repository core/server coverage remains pending. All commits have DCO sign-offs.

Rollout evidence

  • Final consistency smoke: hosted-model OpenCode through the local Docker runner executed Python, earned reward 1, and preserved three native turns with matching task/rollout IDs. Its sandbox was removed. Prior OpenCode/Pi smokes also verified tool execution, verifier results and single-prefix model routing; Claude Code routing has adapter tests, not a live rollout.
  • Earlier Kubernetes validation exercised offline scientific tools, model-proxy access, and Gym MCP search with URL exclusions. Native Pi testing verified process-tree termination and recovery after a Bash timeout. This cleanup did not rebuild images or repeat Kubernetes/network-policy validation.
  • Full APEX and HLE Python, with and without search where applicable, were evaluated with both harnesses. Initial results are accepted by the author; checkpoint-specific comparisons and deployment receipts remain private. Failed and unfinished attempts counted as zero using the full planned denominator, without generation retries.

@Kipok Kipok added feature New capabilities, enhancements, or enablement work area:agent Agent harnesses and Responses API agent behavior labels Sep 21, 2026
@copy-pr-bot

copy-pr-bot Bot commented Sep 21, 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.

@github-actions

Copy link
Copy Markdown
Contributor

@Kipok
Kipok marked this pull request as ready for review September 21, 2026 18:58
@Kipok Kipok added the needs-review PR is ready for code review and waiting on a reviewer label Sep 21, 2026
@yaoyu-33 yaoyu-33 added the complexity:high Cross-component or shared-contract change with a large review surface label Sep 21, 2026
@Kipok

Kipok commented Sep 22, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #3575, which carries the OpenCode/Pi evaluation workflow and fixes into the dedicated sandboxed adapters. Closing this shared-harness implementation in favor of that PR; please continue review there.

@Kipok Kipok closed this Sep 22, 2026
gwarmstrong pushed a commit to gwarmstrong/Gym that referenced this pull request Oct 2, 2026
…IA-NeMo#3575)

## What does this PR do?

Run APEX Shortlist and HLE with native OpenCode or Pi inside
provider-managed sandboxes, using preinstalled scientific tools and
optional Gym-hosted Tavily search. Extends `opencode_sandboxed_agent`
and adds `pi_sandboxed_agent`; the existing `harness_agent` is
unchanged.

This carries the OpenCode/Pi benchmark features and later fixes from
NVIDIA-NeMo#3570 into dedicated adapters. No separate issue: this is the
architectural alternative discussed during review of that PR, which this
PR supersedes.

## Design

- Gym provisions, parses, exports, and grades on the host. Native CLIs
execute inside the sandbox; no Gym installation, uploaded Gym source, or
runtime method replacement is needed there. Pi reuses its existing host
adapter's model configuration, response parsing, and observations.
- Python-only permits model-host egress; search additionally permits the
Gym tool host. Restricted policies require OpenSandbox and fail closed
for other providers or resource-owned sandboxes. API credentials stay on
the host; MCP uses per-session authentication. These are whole-host
allowlists: every port/path on an allowed host is reachable, including
colocated Gym APIs. A separately deployed isolated gateway is outside
this PR.
- Six benchmark presets preserve standard preparation, grading, and
answer-format instructions. Native prompt additions describe network
availability and preinstalled tools. Defaults: four-hour execution
budgets, 262,144-token context, remaining-context output requests, no
compaction, OpenCode 400 steps with titles disabled, Pi 120s Bash cap.
- Adds reproducible `offline_science_image/` build contexts. Python/Sage
Python 3.13.14, Sage 10.8, Lean/Mathlib 4.34.0, and OpenCode 1.17.11 are
pinned; a small separate layer adds Node 22.23.2/Pi 0.85.1. OpenCode's
plugin dependency is preinstalled. Locks, provenance, and build
instructions are included.
- Preserves OpenCode native trajectory export, Pi native/timestamped
events, generation receipts, failure accounting, and cancellation
cleanup. Ports the model streaming and benchmark discovery fixes needed
by the workflow.

## Compatibility and behavior changes

- Terminal token-limit stops score zero in both benchmark presets,
retain the partial answer, and set response status `incomplete` with
reason `max_output_tokens`. OpenCode previously graded these partial
answers; Pi now enforces this even with observations disabled. General
configurations still control zero scoring through
`execution_failure_reward_zero`. Sandbox timeouts are recorded as
`timeout`, including exit code 124 when no provider error type is
present.

- Existing OpenCode configuration defaults to inherited networking and
runtime installation. Benchmark-only restrictions and zero-reward
execution-failure handling are opt-in presets. Native OpenCode overrides
are now deep merged. Existing `tools`/`permission` configurations remain
accepted; presets use only `permission` to avoid native precedence
surprises.
- OpenCode transcript export/download failures now propagate instead of
yielding an empty or stale result. Setup/export/judge failures stay
request failures, including required MCP initialization failures.
Explicit completed execution failures may score zero through
empty-output verification, retaining native score fields and the
original generation. The verifier must score empty output as unmasked
zero. This fixes failed attempts disappearing from native APEX symbolic
metrics. Use failure sidecars and report missing-row coverage.
- Remote benchmark presets now set `use_absolute_ip: true` so Gym
actually binds to the advertised host IP. Restricted modes reject
loopback/wildcard endpoints instead of rewriting URLs; inherited
host-network deployments preserve loopback. Explicit hosts must remain
reachable from the sandbox.
- Pi sandbox execution uses `/run`; an unseeded `/v1/responses` call is
rejected. OpenCode also requires a seeded run when tool servers are
configured. Pi's JSONL parser preserves Unicode paragraph separators
inside event content.
- Pi logs sandbox cleanup exceptions without overwriting a completed
grade or masking the original execution/verification error.
- OpenCode retains main’s configurable model-call timeout and seeded
sandbox working directory; benchmark presets retain their four-hour
execution budget.
- Tavily now supports key pools, bounded HTTP/connection/timeout retries
and page caching, filters requested and returned URLs, and returns
source excerpts without aggregate direct answers. Only public HLE
exclusions are committed. Invalid keys (401) and exhausted quotas
(432/433) fall back to another key within the same HTTP attempt budget;
keys rejected in the current call are skipped until the next call. These
shared changes need Tavily maintainer review.
- Buffered chat streaming preserves early HTTP errors and sends
keepalives during long generation; late backend failures become terminal
SSE errors with status-bearing messages recognizable by native retry
handling. Responses-API streaming behavior is unchanged.

## Validation

- Latest scoring/CI follow-up: 342 targeted tests passed, including
Vibench, OpenCode/Pi, Tavily, shared verification, and observability.
Full pre-commit and diff checks passed. Two hosted-model Docker runs hit
a real 32-token output cap; both retained the partial answer, marked it
incomplete, and scored zero. Two additional native-agent runs exercised
provider timeout handling. All four containers were removed. These fixes
did not require rebuilding images; Kubernetes and full benchmarks were
not rerun.

- After merging main `fd2a1484b`: 172 focused
OpenCode/Pi/Tavily/sandbox-tool tests and 440 shared
agent/model/sandbox/HTTP/correlation tests passed (14 shared tests
skipped), using Python 3.13.14, Tavily 0.7.21, and imports pinned to
this checkout. Full `pre-commit run --all-files` and `git diff --check
origin/main` passed.
- Two fresh hosted-model Docker search rollouts passed verification on
the merged code. A synthetic public NASA query exercised actual Tavily
HTTP 401 → alternate-key HTTP 200, and an excluded example.com URL was
blocked. Pi preserved its grade after an injected cleanup exception
following actual container deletion. All test containers were confirmed
removed. No new image build, Kubernetes run, or full benchmark rerun was
needed for these host-side fixes.

- Earlier validation: 415 targeted Python tests and 16 JavaScript tests
passed, covering adapters, Tavily policy, streaming/capture, discovery,
Bash deadlines, remaining-context requests, and MCP. Python imports were
explicitly pinned to this checkout.
- All six benchmark configurations resolved and were checked for
preparation, prompts, repeats, agent selection, and limits. A fresh
isolated Pi installation also verified its sandbox dependencies.
- Both images built and were pushed to the deployment registry. Offline
scientific computations and interpreter/CLI versions were verified. Real
Kubernetes canaries exercised Python, Tavily MCP, URL exclusions,
network isolation, transcript export, grading, and sandbox cleanup.
- Full APEX and HLE Python/search runs completed for both dedicated
adapters. Failed judges were regraded without regenerating policy
answers; remaining infrastructure failures and unwritten answers counted
as zero. These runs validate the workflow, but do not establish score
equivalence for every configuration. Some export failures, sandbox OOMs,
and allocation timeouts remain.
- Full `pre-commit run --all-files` and `git diff --check` passed. Fern
check: zero errors, one redirect-validation warning. Broader
global-config testing exposed one unrelated Hydra `LazyCompletionHelp`
incompatibility with local Python 3.14; its test and Gym implementation
are unchanged from main. The focused host-IP binding test passes.

- After the review fixes, four hosted-model Docker rollouts (OpenCode/Pi
× Python/search) scored 1.0, with real Tavily calls, HLE URL blocking,
native exports, and verified container deletion. Native CLI fault
injection showed old OpenCode continuing after MCP failure, the fixed
version stopping before inference, and Pi exiting with the setup-failure
code. Kubernetes and full benchmarks were not rerun for these fixes.
Runtime extensions are uploaded; existing images were reused.
- Regression coverage also checks failed APEX attempts in the symbolic
denominator, empty-output verifier compatibility, partial Pi capture
tails, connection/body retries, and plugins uploaded into resource-owned
sandboxes.

---------

Signed-off-by: Igor Gitman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:agent Agent harnesses and Responses API agent behavior complexity:high Cross-component or shared-contract change with a large review surface feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants