Repository navigation
feat(deepswe_external1): serve episode sessions and run OpenCode through single_agent_turn - #5815
Conversation
…ode through single_agent_turn deepswe_external1 now serves the resources session contract on the shared SandboxSessionResourcesServer base: a typed seed starts the agent sandbox and lends it as sandbox_access, verify grades it once and replays the verdict on an identical retry, close stops the sandbox if verify did not and fences later seeds, and abandoned sessions expire with the sandbox's ttl_s. The agent-run seed keeps returning the sandbox handle for the legacy_agent relay; both kinds of seed register their sandbox with the base, so close, expiry and shutdown stop it. Golden/null validation is unchanged and refuses episode seeds with 422. deepswe_external1_opencode.yaml now runs opencode_agent through single_agent_turn; the relay config is kept as deepswe_external1_opencode_legacy_agent.yaml with a deprecation note. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
|
/ok to test 0dc538e |
…eview fixes - Admit OpenCode episodes at the agent's rate (max_concurrent_episodes 8, a queue timeout) and keep the episode deadline within the sandbox ttl_s, so queued rows no longer each hold a seeded sandbox while waiting for an OpenCode slot. - Refuse a seed body that names a resources_session_id but is not a valid episode seed (422) instead of starting an agent-run sandbox, with reject_partial_typed_seed on the agent-run arm. - Drop the unused _stop_sandbox override. - Say that only episode sessions expire, and that a failed agent-sandbox stop is masked and replayed. - List the whole opencode_agent offline bundle (binary, ripgrep, plugin dependencies) in the README. - Test verifier ownership: a failed verifier stop retried by the verify wrapper and by close, and a cancelled verify that stops both sandboxes and regrades the saved patch. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
|
/ok to test ac349ed |
Signed-off-by: yaoyu-33 <[email protected]>
…d cancellation - Save the agent sandbox's ID with an episode's captured patch, so a verify retried after a cancellation reports it and still refuses a verifier that reuses it. - Try a session verifier's stop twice before building the verdict, so cleanup_errors names the verifier only when it is still running. - Shield and bound the stop of golden- and null-validation sandboxes, so a cancelled request does not leave them to the provider's ttl_s. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
|
/ok to test 5323648 |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
SHIP WITH CARE
I found two RISK issues: session ownership becomes visible too late during sandbox setup, and the documented cached-runtime alternative is incomplete for offline execution. One NOTE covers stale cleanup diagnostics.
I inspected all seven changed files and traced the affected session, sandbox, environment and agent contracts. This was a read-only source review; I didn't execute tests or rollouts.
Review generated by codex. This was a full review. Request a full review with /review reset=true.
| """Start and set up the agent sandbox for a task row, and return the repository the agent works in.""" | ||
| data = TaskData.model_validate(task) | ||
| self._forget_task_sandbox_state(session_id) | ||
| sandbox = await self._create_sandbox(InlineTask(data), phase="agent") |
There was a problem hiding this comment.
RISK — Register session-owned sandboxes before startup/setup awaits.
If an episode seed disconnects during image setup, _create_sandbox() hasn't returned, so the assignment below this line never runs. After provider creation, start_with_setup attempts an unshielded stop when setup is cancelled; that stop can itself be cancelled. The outer failed-seed cleanup then finds no registered sandbox and drops the record. Close and shutdown cannot recover it. A setup exception followed by a failed stop has the same result. The new session-verifier registration has the same ordering problem during verifier setup. The helper weakness predates this PR, but the newly added session-owned paths don't satisfy their cleanup contract.
Could you make ownership visible before start_with_setup? A focused correction, following SWE Gym's allocation pattern, is to add keyword-only session_id: str | None = None and verifier_session_id: str | None = None parameters to _create_sandbox, then insert immediately after constructing AsyncSandbox:
if session_id is not None:
self._session_id_to_sandbox[session_id] = sandbox
if verifier_session_id is not None:
self._verifier_sandboxes[verifier_session_id] = sandboxPass session_id=session_id from _start_task_sandbox. Pass verifier_session_id=session_id if mode == "agent" else None from _verify_task's verifier allocation. Remove the redundant post-return registrations and update the allocation fakes to accept and honor these keywords. Keep failed stops registered for the existing shielded cleanup and later close. Please verify this suggested change before adopting it.
Acceptance — proposed, not executed: use a real AsyncSandbox with a fake provider whose create succeeds, suspend agent setup, then cancel the request's AnyIO scope. Cleanup must stop the sandbox. Repeat during verifier setup. For setup errors whose cleanup keeps failing, assert that the appropriate registry retains the handle and a later close stops it. Preserve successful seed replay without another allocation, the operate-scoped handoff, flat-seed descriptor preservation, failed-close retry, and golden/null grading without session registration.
| (`sandbox_ripgrep_path`, `sandbox_ripgrep_sha256`) and the plugin dependencies | ||
| (`sandbox_plugin_dependencies_path`, `sandbox_plugin_dependencies_sha256`), each a | ||
| file already inside the sandbox, for example on a mounted cache. Alternatively, use | ||
| task images that hold the runtime at `/tmp/nemo-gym-opencode-runtime-<opencode_version>` |
There was a problem hiding this comment.
RISK — Cached OpenCode and rg don't replace the plugin-dependency bundle.
On a provider enforcing the model-only network policy, the advertised alternative—cache OpenCode under /tmp/nemo-gym-opencode-runtime-<opencode_version> and put rg on PATH—still cannot run offline without sandbox_plugin_dependencies_*. The agent creates a fresh private config directory, stages dependencies only when those fields are set, and always configures the task-environment plugin. The agent's documented contract states that each fresh config downloads plugin dependencies without the bundle; offline, installation fails.
Could you replace the alternative with: “Alternatively, cache the OpenCode binary at /tmp/nemo-gym-opencode-runtime-<opencode_version> and put rg on PATH; still set sandbox_plugin_dependencies_path and sandbox_plugin_dependencies_sha256 to populate each session's private config directory.” Apply the same correction to the config comments. This preserves both binary-install choices while keeping plugin dependencies mandatory offline; no shared-agent change is needed.
Acceptance — proposed, not executed: on a network-enforcing provider, use the matching cached binary and rg plus the pinned plugin-dependency archive. A minimal model turn should initialize the task-environment plugin without GitHub/npm downloads and reach verification. Preserve the fully pinned bundle option. Statically check that neither document describes cached binary plus rg alone as sufficient.
| if verifier_sandbox is not None: | ||
| if not await self._release_sandbox(verifier_sandbox, task_id=task_id, phase="verifier"): | ||
| if mode == "agent": | ||
| if not await self._stop_session_verifier(session_id, task_id=task_id): |
There was a problem hiding this comment.
NOTE — Suggestion: reconcile diagnostics after the wrapper's final cleanup.
With verifier stop outcomes [RuntimeError("down"), RuntimeError("down"), None], _stop_session_verifier() exhausts its two attempts and records "verifier" in cleanup_errors. The shared verify wrapper then attempts another stop, which succeeds before the HTTP response returns. Nevertheless, the response, saved replay and result.json still report cleanup_errors: ["verifier"]. This conflicts with the helper's stated meaning that the entry identifies a verifier still running after cleanup. The impact is misleading diagnostics, not an incorrect reward.
Could you reconcile the returned and persisted diagnostics after the wrapper's final stop, or arrange for cleanup to finish before building the verdict? The exact implementation needs to account for both the shared wrapper and the result-file write; increasing the helper's retry count alone leaves the same ordering problem. Preserve completed grades regardless of cleanup failures, ownership when every stop fails, and identical verdict replay.
Acceptance — proposed, not executed: add the two-failures-then-success case to the verifier-stop tests. Expect reward 1.0, mask_sample: false, no owned verifier, and cleanup_errors: [] in the response, identical retry and persisted result. Retain the first-failure-then-success case and the three-failures case, which must retain cleanup_errors: ["verifier"] and ownership until close succeeds.
…diagnostics Signed-off-by: yaoyu-33 <[email protected]>
|
/ok to test 94c1c0e |
Clean session-owned verifiers even when setup fails before allocation returns. Preserve cleanup diagnostics in the masked response, replay, and saved result while retaining ownership for a later close. Validation on ws: 252 focused DeepSWE and session-contract tests passed; pre-commit run --all-files passed. The setup-failure regression fails against the parent revision. No new model rollout: this follow-up covers failed setup and teardown diagnostics, with grading and model interaction unchanged. Signed-off-by: yaoyu-33 <[email protected]>
|
/ok to test 0af9f82 |
|
/review |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
SHIP
The two prior RISK findings and the NOTE are fixed in the current source:
- Sandbox ownership is registered before startup awaits, so session cleanup can reach agent and verifier sandboxes after setup fails or is cancelled.
- Verification reconciles cleanup diagnostics after the wrapper's final stop. The response, saved replay and persisted result now agree for the reported two-failures-then-success case.
- The README and config comments require the pinned plugin-dependency bundle even when OpenCode and
rgare cached.
I compared the follow-up changes with the previously reviewed head and traced the affected sandbox, session, replay and OpenCode contracts, including the relevant regression tests. No unresolved prior findings or eligible introduced regressions remain. This was a scoped, read-only follow-up, not a fresh whole-PR review; I didn't execute tests or rollouts.
Review generated by codex. This was a findings-only review. Request a full review with /review reset=true.
init-nikhil
left a comment
There was a problem hiding this comment.
this mostly looks good to me. One small change you can have your agent make:
If shutting down the agent sandbox fails, we can retry the shutdown and then proceed with verification, like some of the other SWE resource servers do.
Signed-off-by: yaoyu-33 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
init-nikhil
left a comment
There was a problem hiding this comment.
Thanks, the shutdown retry addresses my request. Looks good to me.
|
/ok to test 81a97ac |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/43172459281 |
What changed and why
deepswe_external1(self-contained DeepSWE rows) only served the agent-run seed: its sandbox lived in a cookie-keyed map that onlyverify, a re-seed or shutdown released, so it could not run under an Environment Server, and an episode that never reachedverifyheld its sandbox until shutdown. This PR moves it onto the sharedSandboxSessionResourcesServerbase (resources_servers/swebench/sandbox_sessions.py, the oneswe_gymandr2e_gymuse) and switches its OpenCode config toopencode_agentsessions undersingle_agent_turn.Server (
resources_servers/deepswe_external1/app.py)ResourcesSeedSessionRequest) validatestask_dataas the row'sTaskData(422 when invalid), starts the agent sandbox and lends it assandbox_accesswith anoperate-scoped descriptor and the row's workdir (/appor/workspace/repo). Repeating the seed for the same episode and task returns the same sandbox.verifyruns inside the base's verify wrapper: it collects the committed patch, stops the agent sandbox, and grades in a fresh verifier sandbox as before. An identical retry replays the verdict; a verify of another task is refused with 409; a verify after close is masked assession_lost./close_sessionis the base's: it stops the agent sandbox if verify did not (a failed stop raises and keeps the sandbox for a retried close) and fences later seeds. Episode sessions that are never closed expire with the sandbox'sttl_s.sandbox_handle/sandbox_descriptorfor the relay. Both kinds of seed now register the sandbox with the base, so verify, close and shutdown stop it; the server's own shutdown hook is gone. Only an episode session also expires: an agent-run seed that never reaches verify keeps its sandbox until a re-seed or shutdown, and the provider reclaims it afterttl_s. An agent-run seed cannot replace an episode session (409), and a flat row that names aresources_session_idmust validate as an episode seed (422).cleanup_errorsnames the verifier only when it is still running.agent_sandbox_idand still refuses a verifier that reuses the agent sandbox.ttl_s.RuntimeError).DeepsweExternal1ResourcesServer(DeepSWEResourcesServer, SandboxSessionResourcesServer): DeepSWE supplies collection and grading, the base the session lifecycle.close_resources_sessionis pinned to the base, so a session lifecycle added toDeepSWEResourcesServerlater cannot take over these sessions.Configs
configs/deepswe_external1_opencode.yamlnow runsopencode_agentthroughsingle_agent_turn(rows reach it through thedeepswe_external1taskset), following the naming of feat(swe): run the SWE OpenCode configs through single_agent_turn and keep the relay configs as *_legacy_agent #5762.configs/deepswe_external1_opencode_legacy_agent.yamlwith a deprecation note. Nothing else in the repository cited the old file.single_agent_turnadmits 8 episodes at a time (max_concurrent_episodes, matchingopencode_agent's defaultconcurrency), queues the rest for up to a week, and gives each episode 18,000 s (default_episode_timeout_seconds), the sandbox'sttl_s. Without this, every dispatched row seeded its sandbox at once and held it while waiting for an OpenCode slot, and the 6 h episode default outlived the sandbox'sttl_s.opencode_agentneeds its whole offline bundle pinned (sandbox_executable_*,sandbox_ripgrep_*,sandbox_plugin_dependencies_*) or images with the runtime cached at/tmp/nemo-gym-opencode-runtime-<opencode_version>.Relation to #4560. #4560 (draft) moves
deepsweitself to agent sessions with its own session code. This PR does not depend on it and does not touchresources_servers/deepswe. I did not stack on it: #4560's branch is about 600 commits behindmainand conflicts in nine files, mostly inopencode_agent, wheremainhas since addedsandbox_executable_pathand the task-HOME hook for tool shells. If #4560 later movesdeepsweonto the same base, this subclass needs no change.Issue
No public issue. This is the
deepswe_external1part of the resources-session migration of the SWE servers (thedeepswepart is #4560).Compatibility
deepswe_external1_opencode.yamlnow startsopencode_agent+single_agent_turninstead ofopencode_sandboxed_agent+legacy_agent. Runs that need the relay usedeepswe_external1_opencode_legacy_agent.yaml; overrides ofdeepswe_external1_opencode_sandboxed_agent.*belong with that file.deepswe_external1taskset, routed throughenvironment_server_routes.deepswe_external1_resources_server; the relay config keepsdeepswe_external1_opencode_resources_server.token_id_capture: true(the relay preset did), like the otheropencode_agentsession presets onmain. Training runs settoken_id_capture.all_agents=trueor override the agent.max_concurrent_episodestogether withopencode_agent.concurrencyto run faster.opencode_agent, not in this server or config, so this PR leaves them: no 1 h cap per model call (opencode_agentsends"timeout": falseand accepts onlypermissionandtoolsinopencode_config), noremaining_context, no hostartifacts_dir, and thecompaction/agent/titlekeys refused.execution_failure_reward_zerois not a difference: the relay preset leaves itfalse.Validation
pytest resources_servers/deepswe_external1/tests resources_servers/deepswe/tests tests/unit_tests/test_session_contract_repo.py: 247 passed (primary venv with this worktree on the path). The verifier-ownership, cancellation, retry and validation-cancellation tests each fail with their fix reverted. Newtests/test_sessions.pycovers, through the HTTP routes with fake sandboxes: episode seed →sandbox_access→ verify → replay → close → fenced seed → masked late verify; close without verify, with a failed stop retried; a verify of another task refused; failed agent cleanup masked with no verifier started; validation modes refusing episode seeds; the agent-run seed path; andcheck_resources_session_contractwithverify_body. Existing tests now seed through the base's registry.gym env validateondeepswe_external1.yaml,deepswe_external1_opencode.yamlanddeepswe_external1_opencode_legacy_agent.yaml: valid (thepolicy_modelreference warning is expected without a model config).pre-commit runon the changed files: passed.Rollouts
Real-model pairing runs of
configs/deepswe_external1_opencode.yamlat 0dc538e on a workstation's Docker, on the public exampleactionlint-action-pinning-lint(Go, 55 FAIL_TO_PASS / 145 PASS_TO_PASS tests). They predate the admission settings and the verify/cleanup fixes above, which only unit tests cover so far.nvidia/nemotron-3.5-super-vl-120b-a12bthrough a hosted endpoint and Gym'svllm_modelserver, thinking off,max_output_tokens16,384 and a 1,200 s agent timeout. Collection usedgym env start+gym eval run --no-serve --limit 1, with servers on the docker0 address.opencode_agentdownloaded OpenCode 1.17.11 at seed. On a provider that enforces it, setsandbox_executable_pathas the README says./seed_session→/v1/agent_sessions(borrowing the task sandbox) → (agent turn, 91 model calls) →/v1/agent_sessions/close→/verify→/close_sessionevaluation_completed: true,mask_sample: false; FAIL_TO_PASS 0/55, PASS_TO_PASS 145/145, verifier exit 0,cleanup_errors: []/seed_session→/v1/agent_sessions→/v1/responses500 (OpenCode launch outcome is unknown) →/v1/agent_sessions/close500 →/close_sessionenvironment_server_failed, no/verify, no reward/seed_session→/v1/agent_sessions500 →/v1/agent_sessions/close500 →/close_sessionenvironment_server_failed, no/verify, no rewardWhy the full episode scored 0. This is the task's own result, not a lifecycle failure. The agent branched, wrote the rule, its tests and config parsing, and ran
go test. Its last model call then hit the 16,384-token output cap (finish_reason: length), so OpenCode ended the turn (incomplete) before the agent committed. The task prompt says to commit everything, and collection takes only committed changes (README, "Verification contract"). The captured patch is therefore empty (0 bytes), and the base tree fails FAIL_TO_PASS.In the interrupted runs the sandbox is the task's, lent to the agent. Once it was gone,
opencode_agentcould not remove its session files from it, so its close returned 500 and it kept the session.single_agent_turnlogged "Episode cleanup failed: agent session" and still sent/close_session, which released the task sandbox. That close behavior belongs to the shared agent-session code, not to this PR.🤖 Generated with Claude Code