Repository navigation
feat(deepswe): run OpenCode through agent sessions - #4560
Conversation
A sandbox session installs the pinned OpenCode release from GitHub unless the runtime is already cached in the sandbox. Task sandboxes without internet access, such as DeepSWE's agent sandbox, therefore cannot start a session. Add `sandbox_runtime_binaries`: prebuilt executables of the pinned version that are already inside the sandbox (for example on a read-only mount), keyed by the sandbox libc. Setup copies the one matching the sandbox into the runtime cache, makes it executable and checks its version before use, so a wrong binary fails setup instead of running. A libc without a configured binary keeps the download, and paths must be absolute. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Giulio Lovisotto <[email protected]>
Sandbox sessions ran OpenCode with HOME and every XDG directory moved into the session directory. OpenCode's shell commands and formatters inherit that environment, so in a task image they lost the state the image prepared under its HOME. In DeepSWE images, `git commit` found no identity (the pod hostname has no domain, so git cannot guess one), Go saw an empty module cache and tried to download modules without network access, and the rustup `cargo` shim found no toolchain. The previous sandboxed OpenCode agent kept HOME. Move only XDG_DATA_HOME, which holds the session database the adapter snapshots, and leave HOME and the XDG config, cache and state directories as the sandbox has them. Because OpenCode now keeps its config, cache and state under that HOME, setup also rejects a workdir that would contain them, as it already does for the runtime and session directories. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Giulio Lovisotto <[email protected]>
The DeepSWE resources server accepted only the flat seed an agent's `/run` sends and returned a bare sandbox handle, so an EnvironmentServer could not lend its agent sandbox to a session-capable agent, and nothing stopped that sandbox when an episode ended without verify. A typed `ResourcesSeedSessionRequest` now starts the same agent sandbox (task image, no-network policy plus the model host, git identity) and returns it as `sandbox_access` with `/app` as the workdir, scoped so the agent may operate but not destroy it. The seed binds the caller's session ID to the session cookie verify reads, checks the task ID against the row, and is idempotent for the same episode and task. `/close_session` stops the agent sandbox unless verify already did and fences later seeds; a failed stop raises and keeps the sandbox for the retry. A repeated verify of an Environment Server session fails instead of grading an empty patch. Sessions are process-local and require one worker. The flat seed, golden-patch verification and grading are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Giulio Lovisotto <[email protected]>
Migrate the DeepSWE v1.1 OpenCode benchmark from `opencode_sandboxed_agent` to `opencode_agent` behind the `single_agent_turn_legacy` EnvironmentServer. Each episode seeds DeepSWE, which lends its no-network agent sandbox; opens an OpenCode session in it; runs the prepared prompt; closes the agent; verifies the committed patch in a fresh verifier sandbox; and closes the resources session. The recipe keeps the three-hour agent budget (`timeout: 10800`), the 262,144 token context, an output budget equal to the context window, the shared command restrictions and the 10 repeats. Concurrency is raised so the single session worker does not queue rollouts. The DeepSWE allowlist and manifest now name `opencode_agent`. The Nemotron 3.5 Super overlays bind the renamed `deepswe_opencode_agent` instance and point it at the mounted OpenCode binary. The DeepSWE README maps the previous agent settings to the new ones, lists the previous controls the session path does not support, and records what changes the model's inputs. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Giulio Lovisotto <[email protected]>
…gent Two settings let a benchmark keep what `opencode_sandboxed_agent` did when it moves to sandbox sessions. Both default to off, so existing session users are unchanged. `session_return_failed_runs`: a run that ends on a model or runtime error (for example a context overflow returned as an error, a nonzero exit, or a lost sandbox exec) returns a response with status `failed`, its error and the partial output, instead of an HTTP 502. An EnvironmentServer then closes the agent and verifies the task as usual, rather than recording a failed rollout that collection retries. Cancellation still propagates, and close still has to confirm that OpenCode's processes stopped before verification can run. `session_project_config`: stop setting OPENCODE_DISABLE_PROJECT_CONFIG, so OpenCode reads the task repository's AGENTS.md or CLAUDE.md and project config as it does when run in that repository. Settings Gym passes in OPENCODE_CONFIG_CONTENT are merged last and still take precedence. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Giulio Lovisotto <[email protected]>
…efore The previous DeepSWE recipe left `execution_failure_reward_zero` at false: a run that ended on an OpenCode error was still verified and graded normally, and OpenCode read the task repository's top-level AGENTS.md or CLAUDE.md (20 of the 113 task repositories have one). Enable `session_return_failed_runs` and `session_project_config` so the session recipe keeps both. The README maps both settings, drops them from the unsupported controls, and corrects the note on reasoning: earlier reasoning reached the model before as well, because Gym's vLLM model server returns it in `<think>` tags, OpenCode sends it back, and the model server moves it into the reasoning field. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Giulio Lovisotto <[email protected]>
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
Stage the portable NOOA runtime for borrowed task sandboxes. This layer now builds on the standard single-agent-turn session integration. This is part of the existing NOOA integration stack, based on NVIDIA-NeMo#3848; no separate issue is needed for this requested architecture revision. Shared/base environment servers, shared agent contracts, generic sandbox code, and other harnesses remain fixed. Patterns adopted from merged NVIDIA-NeMo#3717 (single-agent-turn lifecycle), NVIDIA-NeMo#3554/NVIDIA-NeMo#3961 (Hermes sessions and sandbox cleanup), NVIDIA-NeMo#3640 (Codex), NVIDIA-NeMo#3626 (Pi), and open NVIDIA-NeMo#4560 (borrowed DeepSWE/OpenCode sandbox): seed Resources, seed agent, activate, close agent and collect evidence/cookies, verify, close Resources. Compatibility: in sandboxed NOOA, agent-owned background services stop before verification; the Resources-owned sandbox and persisted artifacts remain available. Tasks requiring a NOOA-started service during grading are unsupported by this lifecycle. The standard contract has an episode-wide deadline and no separate NOOA agent deadline; Terminal-Bench recipes retain verifier timeouts but do not reproduce canonical per-agent deadlines. Current revision: `0efed19193e1bb3e906318a6c6486f64078188ee`. Validation evidence: Implementation pushed before writing or running new behavior tests or local checks, as requested. Existing tests received only mechanical naming/import updates before this push. Checks, exact-layer tests, live-model smoke rollouts, and current-head CI are pending for this revision. Earlier test and CI evidence applies only to earlier revisions and does not validate this change. No new benchmark scores are claimed. ## Tests and validation Current revision: `a55f1eddbf13448c30728dafd17ef0af8ac26dbc`. Rebased the existing ten-PR stack onto main `9ef5ed0f80a9f81c5d82af6588cd4cc956c4f5d1`; assembled tip is `196bd5e333abd6e8ee7a93f4c8805ae33f67a66a` (NVIDIA-NeMo#4357). Main compatibility adds only two test updates: NVIDIA-NeMo#3846 gives the fake HTTP response its headers mapping for checkpoint-aware Environment seeding; NVIDIA-NeMo#4088 checks serialized tool-output snapshots while retaining history, round-trip, and interpreter-object coverage. Both changes were independently reviewed. The rebase preserves upstream NOOA serialization and runtime configuration changes. Validation on the exact rebased revisions: - NVIDIA-NeMo#3843: **170 passed** (one expected skip-verification aggregate-metrics warning). - NVIDIA-NeMo#3846: **195 passed**. - NVIDIA-NeMo#3844: **218 passed, 8 Linux-only installer skips** on macOS. - Assembled NVIDIA-NeMo#4357 tip: **373 passed, 16 platform skips** (10 installer and 6 Linux supervisor tests). - `pre-commit run --all-files` passed. DCO sign-offs, sequential layer ancestry, and the focused final diff were checked. Command from each revision's `responses_api_agents/nooa_agent`: `python -m pytest tests --import-mode=importlib -q -o addopts= -o log_cli=false --tb=short -rs`. Exact early-layer tests use installed NOOA `051472343211914222e24ce36d8752f4e86bbe43`; the assembled tip uses coherent core/CLI/BenchAgent `19caab169b018476ac433d040f6ae3f06aeff101`. Commands and logs: `/tmp/nooa-merge-main-candidate-20261016/final-tests-{3843,3846,3844,4357}/`. Prior real-model evidence for the unchanged reviewer-fix behavior remains at `/tmp/nooa-review-fixes-20261016/live-final/`, run on pre-rebase tip `8185eb1f405ba476aab42b00a222f92dbec4364f`: real Qwen output-token and iteration exhaustion each verified once; an actual iteration limit followed by injected cleanup failure remained fatal, skipped verification, and closed both sessions. This main sync adds test compatibility rather than new agent behavior, so that smoke was not rerun and is not presented as a smoke of the rebased tree. It used the integration-test Resources fixture and was not a new SWE-bench/OpenSandbox canary. GitHub CI is requested for the new heads. Optional cross-harness conformance failures also reproduce on main and are separate from the required `Nemo_CICD_Test` gate. Existing branch names, bases, draft states, native groups, and description text outside this validation section are preserved. Required [branch CI](https://github.com/NVIDIA-NeMo/Gym/actions/runs/38964312169) passed on this revision: 8,793 core tests, 921 sandbox tests, 95.07% coverage, and 226 NOOA tests (including Linux installer tests for NVIDIA-NeMo#3844). Signed-off-by: Nikhil Deshmudre <[email protected]>
yaoyu-33
left a comment
There was a problem hiding this comment.
Thanks for this. I tried to stack deepswe_external1 on it and ran into a few things worth fixing here first. I opened that part separately as #5815, which does not touch resources_servers/deepswe.
1. The branch needs main merged. It is about 600 commits behind. A test merge of origin/main (0cc28ac) conflicts in nine files: benchmarks/deepswe/opencode.yaml, resources_servers/deepswe/{app.py,tests/test_app.py}, and six files under responses_api_agents/opencode_agent/ (app.py has seven hunks). Two of the six commits overlap what main now does:
- install sandbox runtimes from in-sandbox binaries:
mainaddedsandbox_executable_path/sandbox_executable_sha256(a pinned binary already in the sandbox) plus the pinned ripgrep / plugin-dependency bundle. - keep the sandbox's HOME:
mainkeeps OpenCode's private HOME/XDG but gives tool shells the task's environment back through a plugin hook (_private_directories).
Please check whether sandbox_runtime_binaries and the HOME change are still needed on top of those, or whether the recipe can just set the new fields. The remaining imports from flat paths (nemo_gym.base_resources_server, nemo_gym.server_utils, nemo_gym.episode_types, ...) also need to move to the package public APIs.
2. Consider SandboxSessionResourcesServer instead of the hand-written session code. #4302 (merged 2026-11-05) added it in resources_servers/swebench/sandbox_sessions.py; swe_gym, r2e_gym, swebench and now #5815 use it. Moving deepswe onto it would fix these gaps in the current version:
_closed_sessionsand_session_locksnever shrink. The base fences forsession_close_retry_window_secondsand drops idle locks.- A verify after close or a repeated verify raises
ValueError, which is an HTTP 500. The resources-session contract expects a maskedsession_lostsample, whichcheck_resources_session_contract(..., verify_body=...)checks. The base returns that, and replays the saved verdict for an identical retry. - An episode session that is never closed keeps its sandbox until it is stopped by hand:
deepswehas no shutdown hook onmaineither. The base expires sessions with the sandbox'sttl_sand stops what is left at shutdown. num_workersmust be 1 here, but the server runtime now routes a session's requests to the worker that owns it (routes_sessions_to_owner), so the restriction is not needed.
The pattern is seed_session → seed_task_sandbox_session(request, body, DeepSWEInstanceRequest) for typed seeds, a _start_task_sandbox hook that registers the sandbox in _session_id_to_sandbox, and verify → verify_task_sandbox_session(...) with capture_task_sandbox_patch / stop_task_sandbox_after_capture around the patch collection. resources_servers/swe_gym/app.py is the shortest example. #5815 does the same for deepswe_external1, a subclass of DeepSWEResourcesServer, and pins its close_resources_session to the base so it keeps working whichever way this PR goes.
|
|
||
| Existing flat-row benchmarks keep the `opencode_sandboxed_agent` entrypoint | ||
| and configuration for their Resources-owned lifecycle. | ||
| DeepSWE (`benchmarks/deepswe/opencode.yaml`) runs this agent through EnvironmentServer |
There was a problem hiding this comment.
no need to mention deepswe here, too specific.
There was a problem hiding this comment.
Done in a109fae: the OpenCode README no longer mentions DeepSWE. The only addition there is a general "Repository project config" section for session_project_config.
Resolve the conflicts with main and rebuild the branch on what main now provides: - DeepSWE episode sessions now use SandboxSessionResourcesServer, the base that swe_gym, r2e_gym and swebench use. A seed registers the agent sandbox with the base. Verify saves the captured patch, replays the saved verdict for an identical retry, and masks a verify after close or expiry as a lost session (no HTTP 500). Sessions that are never closed expire after the sandbox's ttl_s, and shutdown stops any that remain. The num_workers=1 restriction is gone because the runtime routes each session to its owner. Agent-run (/run) seeds work as before. deepswe_external1 now initializes the base's session state. - OpenCode: drop sandbox_runtime_binaries (main's sandbox_executable_path/sha256 pins the binary) and the HOME/XDG change (main's task_environment plugin gives tool shells the task's HOME back). Also drop session_return_failed_runs: main already returns a failed response, which the Environment Server verifies, when OpenCode reports a model error. Keep session_project_config on main's code, with its README section. - Recipe: keep main's report_agent_sandbox_oom and cap the episode at the sandbox's ttl_s (18000 s). The Nemotron overlay pins the mounted binary with the npm [email protected] digest. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
|
/ok to test a109fae |
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
|
/ok to test 27d5eb6 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/42908977940 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/42910742592 |
feat(deepswe): run OpenCode through agent sessions
What changed and why
The DeepSWE v1.1 OpenCode benchmark ran
opencode_sandboxed_agentbehind alegacy_agentrelay: the agent's/runseeded DeepSWE, connected to the agent sandbox by handle, ran OpenCode, called verify and then stopped the sandbox
itself. This PR moves the official recipe (
benchmarks/deepswe/opencode.yaml) toopencode_agentthrough thesingle_agent_turn_legacyEnvironmentServer and the agent-session interfaces, keeping sandbox execution:ResourcesSeedSessionRequest. DeepSWE starts the agent sandbox(task image, no-network policy plus the model host, git identity) and lends it as
sandbox_access(/app).opencode_agentsession in that sandbox, which installs the pinned OpenCode runtimeinside it, and activates it once with the prepared prompt (three-hour budget).
is disconnected, not stopped), calls verify (the committed patch is collected from the agent sandbox, which is
then stopped, and graded in a fresh verifier sandbox), and closes the DeepSWE session (stops the agent sandbox if
verify has not, fences late seeds).
Six commits:
GitHub, which DeepSWE's no-network agent sandbox cannot reach. New
sandbox_runtime_binaries(keyed byglibc/
musl) points at prebuilt executables of the pinned version already in the sandbox, for example on aread-only mount. Setup copies the matching one into the runtime cache, makes it executable and checks its
version; other libcs keep the download.
directory into the session directory. OpenCode's shell and formatter processes inherit that, so in DeepSWE images
git commithad no identity (the pod hostname has no domain), Go saw an empty module cache and tried to downloadmodules offline, and the rustup
cargoshim found no toolchain (all three reproduced in DeepSWE task images).Only XDG_DATA_HOME (OpenCode's session database) moves now, as in the previous sandboxed agent. Setup rejects a
workdir that would contain OpenCode's config, cache or state directories.
sandbox_access, idempotentfor the same episode and task;
/close_sessionthat stops the agent sandbox unless verify did, keeps it for aretry when the stop fails, and fences later seeds; a repeated verify of a session fails instead of grading an
empty patch; one worker required. Flat seeds, golden-patch verification and grading are unchanged.
opencode_agent), manifest(
0.2.0), Nemotron 3.5 Super overlays, README.session_return_failed_runs: a run that ends on a model or runtime error returns statusfailedwith its errorand partial output instead of an HTTP 502, so the EnvironmentServer still verifies it; cancellation still raises
and close must still confirm cleanup before verify.
session_project_config: stop settingOPENCODE_DISABLE_PROJECT_CONFIG, so OpenCode reads the task repository's AGENTS.md or CLAUDE.md and projectconfig; Gym's inline config is merged last and still wins.
execution_failure_reward_zeroat false, so a run that ended on an OpenCode error was verified and gradednormally, and OpenCode read the repository's top-level AGENTS.md or CLAUDE.md. The recipe enables both settings.
Compatibility and migration
Config keys downstream configs must follow:
deepswe_opencode_sandboxed_agent.responses_api_agents.opencode_sandboxed_agent.datasetsdeepswe_opencode_agent.responses_api_agents.opencode_agent.datasets...opencode_sandboxed_agent.sandbox_timeout...opencode_agent.timeout...opencode_sandboxed_agent.opencode_max_context_window...opencode_agent.context_window(the output budget follows it)...remote_opencode_install_script_path+remote_opencode_binary_path...opencode_agent.sandbox_runtime_binaries.glibcdeepswe_environment_server.environment_servers.legacy_agentdeepswe_environment_server.environment_servers.single_agent_turn_legacyThe old instance key is not rejected: an override of
deepswe_opencode_sandboxed_agent.responses_api_agents.opencode_sandboxed_agent.datasetsnow creates a separate,incomplete agent block next to the new one, so update such overrides rather than adding to them.
benchmarks/nemotron_3.5_super/sandbox_utils.yamlandpolicy_model_override.yamlkeep their file names; thesandbox overlay now sets
sandbox_runtime_binaries.glibcondeepswe_opencode_agent.Benchmark-result impact
The recipe keeps the previous task semantics: same OpenCode version (1.17.11), correlation plugin, command
restrictions, subagents, context window and output budget; runs that end on an error are graded, not retried; the
repository's AGENTS.md or CLAUDE.md is read (20 of the 113 task repositories have one at their base commit).
Earlier reasoning reaches the model as before: Gym's vLLM model server returns it inside
<think>tags in theassistant content, OpenCode sends that content back, and the model server moves it into the reasoning field.
Remaining differences that could affect scores:
webfetch,websearchandskillare removed as tools instead of denied by permission.The DeepSWE README lists the previous controls the session path does not support.
Issue
No public issue. This migrates one benchmark recipe to the EnvironmentServer session path that
opencode_agentalready supports.
Validation
responses_api_agents/opencode_agent/tests,resources_servers/deepswe/tests,resources_servers/deepswe_external1/tests,tests/unit_tests/test_session_contract_repo.py: 460 passed;environment_servers/single_agent_turn{,_legacy}/tests: 45 passed. The runtime installer tests (Linux-only)ran in a Linux container: 28 passed. New tests cover the in-sandbox runtime binaries, the HOME/workdir check,
DeepSWE's typed seed/verify/close (including
check_resources_session_contract), failed runs returned forverification (model error, nonzero exit, no assistant result, sandbox exec error; cancellation still raises; an
EnvironmentServer episode with a model error reaches verify and close without a failure), the project-config
setting, and the recipe and overlays.
tests/unit_tests: 7918 passed; 13 failures are local-environment only (DNS for configs withuse_absolute_ip, missing optional wandb/HF/GitLab dependencies, macOS process memory) in modules this PR doesnot touch.
gym env resolveandgym env validateforbenchmarks/deepswe/opencode.yaml, alone and with the Nemotronoverlays;
gym env validate --manifest benchmarks/deepswe/opencode/manifest.yamlpasses (113 rows).pre-commit runon the changed files.scripts/run_harness_conformance.py --harness opencode): 7/7 scenariosfulfilled. This qualifies the local path only.
Rollouts
textual-kitty-key-phasesand
aiomonitor-task-snapshots-diff: the golden patch committed in the lent sandbox scored 1.0 (f2p 23/23 and53/53), the empty patch 0.0 (f2p 0/23 and 0/53, p2p all passing). After verify the agent sandbox was gone, a
repeated verify and a late seed were rejected, and close succeeded.
textual-kitty-key-phases) end to end throughgym eval runon OpenSandbox with the migratedrecipe and the Nemotron sandbox overlay. The runtime was installed from the mounted binary and OpenCode ran in
the task pod. No model endpoint was reachable from the remote sandbox in this setup, so OpenCode reached its
shortened 300 s budget without a reply; the run was graded as an empty patch (0.0, evaluation completed), the
agent sandbox was deleted, and the failures file was empty.
small Python repository, held-out grader): Nemotron 3 Nano 30B-A3B worked in the lent sandbox, created a branch
and committed, and the committed patch scored 1.0 (f2p 4/4). Model-call capture joined 9 calls; rollout health
healthy; the P0 artifact checks (scripts/inspect_harness_conformance.py --require-sandbox) fulfilled TE-1 toTE-9. A second rollout stopped after four turns without editing and scored 0.0, also healthy.
AGENTS.mdat the repository root: the first captured request's system promptcontains
Instructions from: /app/AGENTS.mdand its text; the agent followed it (ran the tests beforecommitting) and scored 1.0.
status
failedwith that error, and the episode was verified once (0.0, evaluation completed); the failures filewas empty and nothing was retried. Rollout health reports
rollout_ended_on_failed_model_call.Not yet done: a real-model DeepSWE task on OpenSandbox. It needs a model server reachable from the remote
sandbox (
use_absolute_ip=trueon a cluster node).Remaining observation gap on the session path (not introduced here): every captured call reports
assistant_message_call_unmatched, because the session path returns no agent-built trajectory for theassistant-message join; turns are reconstructed from the captured calls instead.
🤖 Generated with Claude Code