Skip to content

Opensandboxed - OpenCode search environment - #4935

Merged
bxyu-nvidia merged 23 commits into
mainfrom
abhibha/search-browsecomp-opensandbox
Nov 4, 2026
Merged

bxyu-nvidia merged 23 commits into
mainfrom
abhibha/search-browsecomp-opensandbox

Conversation

@abhibha-nvidia

@abhibha-nvidia abhibha-nvidia commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

This is first of the multiharness envs for running search benchmarks like browsecomp, multimodal browsecomp, deepsearch qa, etc. This is using the openandboxed version of Opencode.

Rollouts

gym eval run
--config responses_api_models/vllm_model/configs/vllm_model.yaml
--config nemo_gym/sandbox/providers/opensandbox/configs/opensandbox.yaml
--config benchmarks/browsecomp/configs/browsecomp_opencode.yaml
--config /search_judge_nvinference.yaml
--config /search_exa_keys.yaml
++policy_base_url=http://<VLLM_HOST>:8000/v1
++policy_api_key=dummy_api_key
++policy_model_name=<SERVED_MODEL_NAME>
++split=benchmark
++use_absolute_ip=true
++num_samples_in_parallel=4
++output_jsonl_fpath=/tmp/trial_rollouts.jsonl

abhibha-nvidia and others added 3 commits October 20, 2026 11:11
…encode stack

Adds a search/BrowseComp-style environment that runs through the existing
opencode_sandboxed_agent and grades free-text answers with an LLM judge.

WHAT IS HERE
  benchmarks/search/                     the benchmark: config, dataset builder, README
  resources_servers/opencode_opensandbox_search_agent/
                                         per-row sandbox, judge grading, Exa response cache
  responses_api_agents/opencode_sandboxed_agent/
                                         five runtime plugins and the wiring they need
  nemo_gym/judge.py                      optional per-attempt timeout on call_judge

The grader is an LLM judge rather than string comparison, because a BrowseComp answer is free
text and equality marks correct answers wrong. There is no eval sandbox and no test execution.

PLUGINS, NOT PATCHES. Every behaviour change ships as a runtime .js plugin uploaded into the
sandbox, so opencode is never rebuilt or forked: a contamination and TDM-opt-out guard on
search/fetch, a turn budget that removes the tool surface at its cap so the model must answer, a
compaction continuation, a tool-surface repair, and a sentinel. The sentinel exists because
opencode swallows plugin load failures silently -- without it a run with every guardrail off
looks healthy and still scores, so the server refuses to grade a rollout whose log lacks its
marker.

ARMS ARE ENVIRONMENT VARIABLES, not one config file per feature. Hydra composes overrides by
path, so a file per feature is the only granularity files give you; ${oc.env:...} gives one
config with independent switches, which is already the idiom in benchmarks/deepsearchqa and
aalcr. All default to unset, and unset means the variable is dropped rather than exported, so a
plain run is byte-identical to one that never knew the knob existed.

DEFAULTS CHOSEN FROM MEASUREMENT, not convention. Generation is uncapped and the only deadline
is the job's wall clock. Both were bugs we previously shipped a file to work around: an output
cap does not truncate here, it kills the rollout, and a sandbox timeout below the job wall threw
away time already paid for while scoring its kills as reward 0 with no failure kind --
indistinguishable from a wrong answer. The Exa cache defaults to off and takes its root from the
environment, so no config points at a path only one site can read.

nemo_gym/judge.py is the only shared file touched: call_judge gains an optional timeout_seconds.
Gym's shared aiohttp client is built without a timeout, so one judge that accepts a connection
and never answers holds its rollout until the wall clock and the caller's retry loop never runs.

VALIDATION. `gym env resolve` over the full composed config with arms both off and on; search
resources server 12 passed; opencode agent suite 67 passed (one pre-existing import-timeout test
is flaky on a cold network filesystem and unrelated); ruff check and format clean across 13
files; all plugins parse.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: abhibhag <[email protected]>
…ename server to opencode_search

Two review comments, both addressed.

1. DEFAULT CONFIG LEFT ALONE (Brian). opencode_sandboxed_agent.yaml is now byte-identical to
main. It had grown 97 lines of ours -- an opencode_env block of ~20 placeholder keys, a plugin
list, stdin and compaction switches -- in a file every opencode benchmark loads, several of them
openly search-flavoured (EXA_API_KEYS, NEMO_GYM_EXA_MAX_CHARS). All of it moves to the new
configs/opencode_sandboxed_search_agent.yaml, which pulls the base in itself exactly as
responses_api_agents/nemo_fabric_agent/configs/nemo_fabric_claude.yaml does.

   Those placeholders turned out to be unnecessary rather than merely misplaced. A comment in
   that file claimed Hydra's struct lock forced every settable key to be declared in the base
   first. It does not: opencode_env, opencode_config, opencode_plugins, opencode_query_via_stdin
   and exclude_compaction_summaries are real fields on OpenCodeSandboxedAgentConfig with
   defaults. Verified by resolving a config that sets an opencode_env key present nowhere in the
   base -- once via CLI override, once via a config file -- both EXIT=0 with the key in the
   output. The false comment is gone with the placeholders.

2. SERVER RENAMED to resources_servers/opencode_search (was
opencode_opensandbox_search_agent). Directory, config filename, instance name
(opencode_search_resources_server) and implementation key, plus all eight cross-references.
Recorded as git renames, so history survives.

THE PART THAT WAS NOT FREE. Moving the knobs behind a second _inherit_from silently dropped the
base permission deny-list -- 74 bash rules covering destructive commands, git-history mining and
github fetches -- while the config still resolved cleanly and every other value looked right.
Gym resolves _inherit_from ONCE, against a frozen pre-resolution snapshot
(global_config.py _recursively_swap_keys; its own TODO notes the limitation), so inheriting from
an instance that itself inherits yields that instance's overrides WITHOUT the base underneath.
The benchmark therefore MERGES INTO opencode_sandboxed_search_agent instead of inheriting from
it, which keeps the chain one level deep. Confirmed by resolve: 74 bash rules before the
restructure, 0 after it, 74 again now.

VALIDATION. Full `gym env resolve`: permission/tools/agent/compaction all present, 5 plugins,
stdin on, sandbox_timeout 21600, model_call_timeout null, arms defaulting to "" (dropped, not
exported), dataset and resources_server bound. opencode_search 12 passed; opencode_sandboxed_agent
67 passed with the one pre-existing import-timeout test that is flaky on a cold network
filesystem. ruff check clean; all three YAMLs parse.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: abhibhag <[email protected]>
…marks/browsecomp

Four changes, three of them review requests.

STOCK SYSTEM PROMPT. The agent.build.prompt override is gone; the model now runs on opencode's
own prompt. That override carried the Explanation/Exact Answer/Confidence block, which is why
rows were sent as a bare question, so both halves move together: prepare now appends
simple-evals' QUERY_SUFFIX to the user turn, imported from benchmarks/browsecomp rather than
restated so the two cannot drift into asking for different formats. Changing one without the
other yields a run with no stated output format at all. Stock's prompt is written for software
engineering and asks for answers under four lines, which pulls against a task that must show its
reasoning; that is accepted deliberately in exchange for running unmodified opencode.

COMPACTION-CONTINUATION PLUGIN REMOVED. Stock appends "Continue if you have next steps, or stop
and ask for clarification if you are unsure how to proceed" after each compaction, and the plugin
reworded it. It was a reasoned fix with no A/B behind it, so it goes in favour of less deviation
from stock. Four plugins remain. The duplicate plugin list in the benchmark config is gone too --
it was restated in two files, and since OmegaConf replaces lists wholesale, a plugin added to one
would silently never load via the other.

MERGED INTO benchmarks/browsecomp. There is no second BrowseComp benchmark any more: the config
moved to benchmarks/browsecomp/configs/browsecomp_opencode.yaml and points at the upstream
dataset. This is possible only because of the prompt change above -- with QUERY_SUFFIX back in the
user turn our row is identical to upstream's, and this agent reads only the user message (it skips
system messages and never looks at `tools`), so the fields upstream carries for its own harness
are inert here. Our prepare.py, its data dir and the cross-benchmark import of the private
_select_samples are deleted. benchmarks/search/ is gitignored in full: what remains there is local
launch tooling, not part of the benchmark.

benchmarks/browsecomp/prepare.py IS NOT MODIFIED. An earlier attempt split it into
build_rows()/write_rows() so sharding could reuse the pieces; that is reverted and the file is
byte-identical to main. Sharding now happens in the launcher, which runs the upstream prepare once
and slices its jsonl -- prepare_script is Optional (config_types.py:475, dropped at :508), so a
shard dataset simply points at a file that already exists. That also removes the 34 generated
files a 15-way split used to need.

VALIDATION. Dry run end to end: upstream prepare wrote 400 rows, the launcher sliced them into 15
shards (27x10 + 26x5) and rendered per-shard configs. Output generation stays uncapped on all
three layers -- no OPENCODE_EXPERIMENTAL_OUTPUT_TOKEN_MAX, app.py's 1000000000 on the command
line, and null sampling caps on the model server.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: abhibhag <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Oct 22, 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.

abhibha-nvidia and others added 2 commits October 22, 2026 11:44
exa_cache_root and exa_cache_legacy_root are typed `str = ""` on the server config, and the code
treats "" as "cache disabled" (app.py: `if self.config.exa_cache_root:`). When these were made
env-driven so no private path would ship in the repo, the fallback was written as `null`, which
OmegaConf resolves to None and Pydantic rejects:

    ValidationError: 2 validation errors for SearchResourcesServerConfig
      exa_cache_root        Input should be a valid string [input_value=None]
      exa_cache_legacy_root Input should be a valid string [input_value=None]

The server then exits before serving a row, and the whole job fails about two minutes in.

It only fires when the cache is OFF, because any run that sets the env vars supplies real paths
and the default never resolves. Every run up to that point had it on, so the bug stayed invisible
until the first cache-free launch -- which then took out all 45 shards of three arms at once,
every one with the identical traceback.

"" restores the documented semantics: unset means no store, no /mcp proxy route, and the plugin
talks straight to mcp.exa.ai. Verified by resolving the config with both variables unset (both
fields resolve to '') and by a 10-row rollout that started cleanly and scored.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: abhibhag <[email protected]>
@svcnvidia-nemo-ci svcnvidia-nemo-ci added 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 labels Oct 22, 2026
@github-actions github-actions Bot added the sla:triage-overdue Review assignment is over the one-business-day SLA label Oct 23, 2026
@bxyu-nvidia

Copy link
Copy Markdown
Contributor

/ok to test 032410a

Comment thread .gitignore Resolved
@github-actions github-actions Bot removed the sla:triage-overdue Review assignment is over the one-business-day SLA label Oct 23, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the benchmark-onboarding Self-contained benchmark onboarding label Oct 24, 2026
@github-actions github-actions Bot added the sla:author-overdue Author response is over the one-business-day SLA label Oct 26, 2026
abhibha-nvidia and others added 5 commits October 27, 2026 17:59
… locally

Review feedback from @bxyu-nvidia: "can we revert this pls".

The PR had added 22 lines to the repo-root .gitignore to hide this clone's cluster launchers
and monitors. That file is shared by every contributor and every directory, and the patterns
carried no leading slash, so they matched at EVERY depth. `launch_*.sh` therefore already
matched a tracked, shipped file -- responses_api_models/local_vllm_model/scripts/
launch_vllm_server.sh -- which only kept working because git does not un-track a file that is
already in the index. Anything those globs caught could never be tracked, and the wheel ships
git-tracked files (pyproject.toml:546-549), so it could never ship either, silently.

The root ignore file is reverted to upstream. The same patterns now live in .git/info/exclude,
which is per-clone, never committed and affects nobody else, each anchored with a leading `/`
so it pins to the repo root where these files actually are. Verified: the 74 local files stay
ignored, nothing is newly exposed as untracked, and launch_vllm_server.sh is no longer matched.

Two comments pointed readers at benchmarks/search/opencode.yaml, a path that is not committed
and that nobody cloning the repo will have:
  - resources_servers/opencode_search/README.md also named configs/search.yaml, which does not
    exist either; both now point at the files this PR actually adds.
  - nemo_gym_turn_budget.js cited that file for a quote; the comment is now self-contained and
    states the permission-vs-tool-surface distinction directly.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: abhibhag <[email protected]>
Review feedback from @bxyu-nvidia: "can you double check the version of gym you're using?
there shouldnt be pty here".

He is right, and the version hint was literal. Upstream ba4d686 swapped this agent from
`sandbox.pty.exec` to `sandbox.exec`, and that commit is an ancestor of this branch. The string
"PTY command timed out" is produced in exactly one place -- `_pty_timeout_result`
(nemo_gym/sandbox/api.py:70) -- and its only callers live inside `SandboxPty.exec`. The agent's
path is `AsyncSandbox.exec`, which never reaches it. So both uses were permanently dead: the
rescue could never fire, and `_terminal_reason` could never return "agent_timed_out". The
evidence quoted in the original comment block was real but came from an older checkout that
still had `pty.exec`.

Removed, not replaced. The obvious substitute -- keying on `result.error_type == "timeout"` --
does not work either: on the OpenSandbox provider `_exec_background` only ever sets None or
"sandbox", and background_exec is the shipped default, so it would be a second branch that never
fires. Rather than guess, the signal to use is a question for the maintainer; nothing here
pretends to classify a timeout in the meantime.

  - `_terminal_reason` loses the dead `timed_out` leg. It still returns "context_window" and
    "max_iteration" from the plugin's stderr markers, so neither it nor the
    `opencode_terminal_reason` field becomes vestigial.
  - The "opencode runs under a PTY, which has a single stream" comment was false. The
    stdout+stderr concatenation it justified is still correct and is kept; the stated reason now
    describes the real one (the OpenSandbox background path returns one combined stream, the
    foreground path splits them).
  - Same root cause on the new resources server: `seed_session` created a PTY session per rollout
    that nothing ever read, and advertised `pty_session_id` as mandatory. The agent reads only
    `sandbox_handle`; the "raises if only one is present" comment described behaviour that
    ba4d686 deleted. Dropped the field, the create/close calls and the now-unused import.

Validation: ruff check and ruff format clean; resources_servers/opencode_search tests 12 passed;
no test in either suite references agent_timed_out, pty_session_id or terminal_reason; the only
"PTY" left in the agent is a pre-existing upstream TODO at app.py:651.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: abhibhag <[email protected]>
… of staging a file

Addresses the two remaining review comments from @bxyu-nvidia.

"how does this plugin flow differ from the existing one? e.g. for required-mcp.js"
It did not differ -- they were the same mechanism reached twice. Despite its name required-mcp.js
is not an MCP server: it exports a hook factory and reaches opencode through the same
config["plugin"] array as the files under plugins/. Both paths ended in an identical
setdefault("plugin", []).extend(...), and each had its own upload loop.

Unified behind `_plugin_uploads()`, which returns (local file, sandbox path) pairs in load order
and is the single source of truth for both consumers: `_create_opencode_config` registers the
sandbox paths, `responses` uploads the files. The registration site has no sandbox, which is fine
because a sandbox path is a deterministic function of the plugin name -- so a registered plugin
can no longer drift away from an uploaded one, which is the failure that matters here (opencode
silently ignores a `plugin` entry whose file is absent). Config-named plugins come first so
nemo_gym_sentinel.js still loads ahead of the guards it vouches for, and the two policy plugins
keep their existing /tmp/nemo-gym-<name> paths, so the emitted plugin list is unchanged for every
existing config. The read-back verification now covers all of them rather than only ours.

"what's the reason we need to use a file rather than just sending it in?"
The file was unnecessary; stdin is not. `opencode run` rewrites an argv message: v1.17.11
cli/cmd/run.ts wraps any argument containing a space in double quotes and backslash-escapes the
quotes inside it. Replayed over the BrowseComp 400, 400/400 reach the model wrapped and 30/400
have inner quotes mangled. Piped stdin takes the other branch and arrives verbatim. To be clear
about what it is not: this is not ARG_MAX (6.3 MB here against a 2,048-character longest question)
and not shell escaping (shlex.quote applies on both paths) -- the previous comment implied both.

So the temp file is gone and the query is piped straight in. `|` binds tighter than `&&`, so the
chain still reads as `... && (printf ... | opencode run ...) && echo ...` and the trailing `&&`
still gates on opencode's own exit status. Nothing is left behind in the sandbox's /tmp.

Also fixes two test download mocks that stripped the directory from the sandbox path but not the
`nemo-gym-` prefix, so a read-back looked for a file that never existed.

Validation: ruff check and ruff format clean; the agent suite goes from 67 passed to 68 passed
with the same single pre-existing failure (test_import_only_loads_shared_opencode_modules, which
also fails on the unmodified branch).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: abhibhag <[email protected]>
…-opensandbox

One conflict, in nemo_gym/judge.py, and both sides are kept.

Each side added a different keyword argument to the same `server_client.post(...)` call inside
`call_judge._call`, which is why git could not auto-merge a single line:

  * main adds the verifier-invocation header, so a judge call and its retries carry the identity
    of the verify execution that issued them.
  * this branch adds `timeout_seconds`, because Gym's shared aiohttp client is built with no
    timeout -- without it one unanswered judge call hangs its rollout until the job's wall clock
    and the caller's retry loop never runs.

They are independent concerns, so the resolution collects both into a `kwargs` dict and passes it
once. Both docstring additions are kept, and both imports (`ClientTimeout`;
`VERIFIER_INVOCATION_HEADER`/`current_verifier_invocation_id`) are retained.

Validation: ruff check and ruff format clean on judge.py; tests/unit_tests/test_judge.py 22
passed. The agent suite is unchanged by the merge at 68 passed / 1 pre-existing failure.

Signed-off-by: abhibhag <[email protected]>
…-opensandbox

main reorganised the package layout (nemo_gym/{core,config,client,trajectory,server_runtime,utils})
across 58 commits. The only conflict is in responses_api_agents/opencode_sandboxed_agent/app.py,
and all three blocks are import relocations rather than behaviour:

  * `import re` (ours) vs `import logging` (main) -- both kept.
  * ModelServerRef/ResourcesServerRef and get_global_config_dict moved to nemo_gym.config, and
    SESSION_ID_KEY/raise_for_status to nemo_gym.client. Took main's new paths and re-added
    get_first_server_config_dict, which our side uses and main's line does not carry; it now lives
    in nemo_gym.config too.
  * is_nemo_gym_fastapi_entrypoint moved to nemo_gym.utils (main also adds
    is_nemo_gym_fastapi_worker). Our nemo_gym.sandbox imports are unchanged because that package
    did not move. get_server_url moved to nemo_gym.client and is folded into that import; it is
    load-bearing for _resolve_opencode_env, which points the web-guard plugin at the search
    server's /mcp cache proxy -- without it the lookup raised NameError and the Exa cache silently
    never engaged.

Each relocated symbol was confirmed exported from its new package __init__ on main, and the import
block matches how responses_api_agents/opencode_agent/app.py imports the same modules there.

Validation: module imports cleanly; no references to the old nemo_gym.{config_types,global_config,
openai_utils,server_utils} paths remain in this agent or in resources_servers/opencode_search;
ruff check and ruff format clean; agent suite 76 passed with the same single pre-existing failure
(test_import_only_loads_shared_opencode_modules).

Signed-off-by: abhibhag <[email protected]>
@abhibha-nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test 37064e8

@abhibha-nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test acbe1c7

bxyu-nvidia
bxyu-nvidia previously approved these changes Nov 3, 2026
@bxyu-nvidia
bxyu-nvidia enabled auto-merge November 3, 2026 20:22
@github-actions github-actions Bot removed the sla:author-overdue Author response is over the one-business-day SLA label Nov 3, 2026
@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team November 3, 2026 22:04
@DanialTaheri

DanialTaheri commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Are we going to merge this?
Want to merge MM-browsecomp changes on the top of this.

@abhibha-nvidia

abhibha-nvidia commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Are we going to merge this? Want to merge MM-browsecomp changes on the top of this.

@DanialTaheri Yes, its in the merge queue - tests are taking a bit of time to run - blocked on the gym side for this. As soon as the tests pass it'll be automatically merged
.

abhibha-nvidia and others added 2 commits November 4, 2026 01:36
The main merge brought in three repo-wide gates that the opencode search
configs failed:

- test_repository_configs_declare_every_environment_server: move the
  example-dataset agent out of opencode_search.yaml into
  opencode_search_example.yaml, point it at the real resources-server
  instance (opencode_search_resources_server, not the directory name)
  and give it a legacy_agent environment server. Benchmarks build their
  server from opencode_search.yaml with _inherit_from, which moves the
  source instance, so an example agent in that file cannot resolve.
- test_every_repo_benchmark_appears_in_listing: give the
  browsecomp_opencode.yaml policy_model block an entrypoint so the
  benchmark listing can resolve the agent's model_server reference.
- test_every_resources_server_ships_a_schema: add
  resources_servers/opencode_search/task_data.py. It declares `id`
  because the committed example rows carry it.

The example config restates the benchmark's search_judge_model so the
collate command in its header resolves on its own, and the README
environment table is regenerated for the moved example agent.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: abhibhag <[email protected]>
@abhibha-nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test d8d1e22

@bxyu-nvidia
bxyu-nvidia disabled auto-merge November 4, 2026 19:25
@abhibha-nvidia abhibha-nvidia changed the title Abhibha/search browsecomp opensandbox Opensandboxed - OpenCode search environment Nov 4, 2026
@bxyu-nvidia
bxyu-nvidia merged commit 74b3070 into main Nov 4, 2026
63 of 66 checks passed
@bxyu-nvidia
bxyu-nvidia deleted the abhibha/search-browsecomp-opensandbox branch November 4, 2026 19:32
@AdamRajfer

Copy link
Copy Markdown
Contributor

The new server shipped without pyproject/uv.lock, so Check locks and the dependency tests fail on main; fix in #5629.

This branch was previously deployed

1 inactive deployment
public — d8d1e225 Deployed Nov 4, 2026 by copy-pr-bot[bot] via release / finalize / notify #10096
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 benchmark-onboarding Self-contained benchmark onboarding 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.

5 participants