Repository navigation
feat(opencode): resume OpenCode in place on sandboxes whose snapshots keep processes - #5413
Merged
Merged
Conversation
This was referenced Oct 31, 2026
pthombre
force-pushed
the
pranav/envckpt-10-opencode-in-place
branch
from
October 31, 2026 19:53
7725780 to
a3b18a2
Compare
pthombre
force-pushed
the
pranav/envckpt-10-opencode-in-place
branch
from
November 2, 2026 06:16
a3b18a2 to
744b51c
Compare
This was referenced Nov 2, 2026
pthombre
force-pushed
the
pranav/envckpt-10-opencode-in-place
branch
from
November 3, 2026 03:22
744b51c to
4bcb151
Compare
pthombre
force-pushed
the
pranav/envckpt-10-opencode-in-place
branch
from
November 3, 2026 06:40
4bcb151 to
15099f2
Compare
pthombre
force-pushed
the
pranav/envckpt-10-opencode-in-place
branch
from
November 5, 2026 20:07
15099f2 to
abf7b47
Compare
Contributor
Author
pthombre
force-pushed
the
pranav/envckpt-10-opencode-in-place
branch
from
November 8, 2026 04:51
abf7b47 to
2b4046b
Compare
pthombre
force-pushed
the
pranav/envckpt-10-opencode-in-place
branch
from
November 9, 2026 05:37
2b4046b to
27962ac
Compare
macandro96
reviewed
Nov 23, 2026
… keep processes On a provider whose snapshots keep the sandbox's processes (`snapshot_keeps_processes`, AgentENV), a checkpointed OpenCode session now runs its supervisor in hold mode and calls the model through the model relay in the sandbox (`sandbox_model_relay_port`, default 18431); without Python 3.6+ in the image the runner falls back to the direct model URL. Other providers launch exactly as before. After a crash, the re-bind checks the restored launch (`check_restored`): when its supervisor, held pause and relay survived, or the launch had already ended, the activation points the relay at the replacement attempt's model URL (endpoint generation + 1) before it continues the pause, and takes the launch over with `SandboxSession.adopt`, so the call the checkpoint cut is re-sent byte for byte and nothing is relaunched. Otherwise the launch is abandoned (killed, nothing continued) and relaunched from the saved conversation as before; a failed take-over falls back the same way. The bookmark carries `keeps_processes` and `relay_gen`. WARNING lines `OpenCode resumed in place:`, `OpenCode cannot resume in place:` and `OpenCode abandoned a restored launch:` count the outcomes. Adds benchmarks/swebench/verified/opencode_sessions_agentenv.yaml and documents the path. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]>
…n, and log them at INFO Some task images have no Python 3.6 or later. The model relay cannot run there, so every launch runs without it and a restore cannot continue it in place: it is relaunched from its saved conversation (7% of resumed launches in one 16-node job). That was only visible as a WARNING at restore time. - At seed, a process-keeping session checks once for the relay's Python, as the runner looks for it, and records it with the session's checkpoint (`relay_python`). Without one it logs a single WARNING naming the session, the task and the sandbox: its launches cannot resume in place after a restore. - On restore, `relay_unavailable` for such a session reports "no Python in the image". - `relay_unavailable` and `relay_gone` are expected outcomes and are logged at INFO, with the abandonment that follows. Every other reason (`adopt_failed`, `supervisor_gone`, `identity_mismatch`, `pause_mismatch`) stays a WARNING. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]>
…y image can resume in place The relay was model_relay.py on the task image's Python, so a launch on an image without Python 3.6+ ran without it and a restore relaunched it instead of resuming it in place. OpenCode's binary is Bun, which runs model_relay.mjs with BUN_BE_BUN=1; the runner sets that for the relay's process only, since OpenCode itself would start as Bun with it. Verified in AgentENV sandboxes on images with and without Python. The seed-time Python probe and its warning go, and a launch without a relay is now logged at WARNING: it no longer happens by design. The in-place resume tests' stand-in OpenCode runs the relay the same way. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]>
…oes not take it over Review fixes for resume in place. - A take-over that fails before the launch is continued (resolving the model URL, pointing the relay) abandons the restored launch before the relaunch: the session had launched nothing itself, so `cleanup_confirmed` was true and the abandon was skipped while that launch still ran. The abandon is now skipped only when a positive receipt was read. - A launch taken over that ended by itself and then failed raises, as after `execute`, instead of being run again. - A launch taken over whose receipt says it was stopped (a stop or an earlier abandon) is relaunched, not reported as finished. - A checkpoint between the re-bind and the take-over exports the pause the restored launch still holds, so the next restore checks that launch again instead of relaunching beside it. - A restored-launch check that raises or is cancelled undoes the re-bind, so the retried seed decides again. - A check that could not run (`check_failed`) is made once more before a launch that may be resumable is ended. - An abandon that fails is tried once more, except after a termination failure. - Closing a session whose restored launch was never taken over ends that launch. - A session with a launch and no held pause stops what the restore may have brought back of it before relaunching (`stop_and_confirm_cleanup`, now exported from `nemo_gym.agents`). - `resumed_conversation` is saved and restored, so a resumed launch taken over is graded as a resumed launch. - README: `relay_gone` fallbacks are logged at INFO. The base sessions recipe names AgentENV. `check_restored` is in its alphabetical place in the public API. Tests: the model-calling fake wraps `started()` instead of patching `run()`; longer control deadlines; the relay is checked to be up before the checkpoint; one clean-up helper that also ends the crashed attempt. New unit tests cover each fix above. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]>
…pabilities The E2B provider now declares it as SandboxCapabilities.snapshot_keeps in place of the untyped snapshot_keeps_processes attribute, and names its lease create.renew_ttl_s. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]>
zyzhou5
force-pushed
the
pranav/envckpt-10-opencode-in-place
branch
from
November 23, 2026 22:52
03f98a2 to
dae470f
Compare
Contributor
|
/ok to test dae470f |
Contributor
…e check, log a resume once it happened - A restored launch that had ended before the re-bind checked it calls no model: its take-over now only collects its receipt and what it left, without pointing the relay. A relay upload that failed used to abandon it and run the task again. - A restored launch whose held pause expired before the take-over (`pause_expired`) was ended by the supervisor at the pause's limit, not by OpenCode: it is relaunched, as one a stop ended, instead of being reported as finished. - A restored-launch check that still cannot run when asked again fails the re-bind, so the retried seed checks again, instead of ending a launch that may be resumable. A check that answers keeps ending the launches it rules out. - "OpenCode resumed in place" is logged once the take-over has continued the launch. Before it, the take-over logs "taking over a restored launch" (or "collecting a restored launch that had ended") at INFO, so a failed take-over no longer logs a resume as well. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Zeyu Zhou <[email protected]>
Contributor
|
/ok to test ac24b39 |
… run From the review of resume in place: - An abandon of a restored launch that still fails after its retry, or ends in a termination failure, now raises. The re-bind, activation or close that asked fails instead of relaunching OpenCode beside a launch that may still run, and its retry ends the launch again. - A running restored launch whose seed granted episode MCP tools is not taken over: its process keeps the previous attempt's MCP URLs and credentials. It is ended and relaunched, which renders the replacement attempt's grants (`mcp_tool_grants`, logged at INFO as an expected fallback). One that had ended is still collected. - A take-over cancelled before it started the launch (a close or retire while the relay is re-pointed) leaves the restored launch pending, so the close ends it. - A close forgets the restored launch only once it is ended, so a close cancelled or failed while ending it ends it on its retry, before the sandbox is released. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Zeyu Zhou <[email protected]>
Contributor
|
/ok to test 83a3c3d |
A close relaunches nothing, and the sandbox's owner stops the sandbox at the end of the episode, so a close whose abandon of the restored launch still fails after its retry now logs the failure and releases the session, as before 83a3c3d. Failing it held the session for retries that could not succeed. A re-bind or activation still fails rather than relaunch beside the launch, and a close cancelled while it ends the launch still ends it on its retry. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Zeyu Zhou <[email protected]>
Contributor
|
/ok to test ce15983 |
… tools on both attempts - A restored launch that recorded no held pause is stopped before the relaunch. A stop that cannot be confirmed now raises, as an abandon does, so the re-bind fails and its retry stops it again instead of relaunching beside it. - The restore decision gets the replacement attempt's seed. A running launch is not taken over when the launch's own attempt or the replacement attempt has MCP tools, configured or granted (`effective_tool_accesses`): the process keeps the MCP servers it was launched with, and only a relaunch renders the replacement attempt's. This covers a configured server the replacement overrides and grants only the replacement adds. A launch that had ended is still collected. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Zeyu Zhou <[email protected]>
Contributor
|
/ok to test e025edd |
macandro96
approved these changes
Nov 24, 2026
Contributor
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/45483710387 |
This was referenced Nov 25, 2026
7 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed and why
On OpenSandbox, a crash restore relaunches OpenCode from its saved conversation (#5268). On AgentENV, whose snapshots keep the sandbox's processes (#5410), the restored sandbox is still running OpenCode mid-task. #5411 and #5412 added the pieces to hold it through a checkpoint and take it over after a restore. This PR wires them into the OpenCode agent, so a restored OpenCode session continues in place: its next model call reaches the new job's model server, and nothing is relaunched.
At launch (only when
snapshot_keeps_processes)sandbox_model_relay_port. OpenCode's own binary runs the relay as Bun (BUN_BE_BUN=1, set for the relay's process alone), so every image runs it, with or without Python. Only if the relay does not come up does OpenCode use the direct model URL, and that session relaunches on restore.keeps_processesandrelay_gen.Other providers launch exactly as before.
After a crash (the re-bind)
check_restoredchecks that the restored launch's supervisor is alive with the same identity, still holding the pause, with its relay up.SandboxSession.adopt. The relay re-sends the cut call, and OpenCode sees only a slow model call. A launch that had already ended is collected the same way.Each outcome is logged so a run can count it.
relay_gone(the checkpoint was taken before the launch's relay started) is expected and logged at INFO; a launch resumed in place and every other reason a launch cannot resume (relay_unavailableincluded, since every image runs the relay) are logged at WARNING.The wall clock
OpenCode orders a conversation by message IDs it makes from the clock, so a clock that jumps while OpenCode runs can put a message out of order. Gym does not set the sandbox's clock; that is the provider's to keep. On AgentENV,
snapshots.keep_guest_clock(#5410, on in the AgentENV config) makes a restored sandbox continue from the clock its snapshot was taken at.Setting
sandbox_model_relay_port(a fixed default): the sandbox port of the model relay on providers whose snapshots keep processes.Also adds a SWE-bench Verified benchmark config for OpenCode sessions on AgentENV (
benchmarks/swebench/verified/opencode_agentenv.yaml, on top ofmain'sopencode.yaml), and docs for both restore paths.Found in the review of this PR and fixed here (last commit)
Every path that does not take a restored launch over now ends it or checks it again; before, some left it running beside a relaunch.
execute, instead of being run again.stopped(a stop, or an earlier abandon) is relaunched, not reported as finished.check_failedand a failed abandon are each tried once more (the abandon not after a termination failure). An abandon that still fails is logged and the relaunch goes on; see the follow-ups.resumed_conversationis saved and restored with the session, so a resumed launch that is taken over is judged as a resumed launch.How it works
flowchart TD CK["checkpoint: hold pause N,<br/>relay holds model calls,<br/>AgentENV memory snapshot"] --> CR["crash, new job: fork from snapshot,<br/>environment server re-seeds, agent re-binds"] CR --> KP{"bookmark keeps processes?"} KP -->|"no"| RL["relaunch from saved conversation<br/>(as on OpenSandbox)"] KP -->|"yes"| CHK{"check_restored"} CHK -->|"RestoredLaunch"| EP["re-point relay: new model URL,<br/>generation plus 1"] EP --> AD["continue pause N, adopt launch"] AD --> OK["OpenCode continues in place,<br/>cut call re-sent byte for byte"] AD -->|"take-over fails"| AB CHK -->|"NotResumable"| AB["abandon launch (KILL, no CONT)"] AB --> RLWhere this sits in the stack
This stack checkpoints environment-server episodes whose agent harness runs in a sandbox the resources server lends. #5264, #5265 and #5266 have merged, and the rest of the stack is rebased onto
mainafter them. #5265 to #5331 add checkpoints for OpenCode and the SWE servers on OpenSandbox. #5410 to #5413 add AgentENV (E2B API, VM memory snapshots), where a restored sandbox still runs the harness's processes, so OpenCode continues in place instead of being relaunched. Each PR's diff shows only that PR's change.Issue
No tracking issue exists. This finishes AgentENV in-place resume for OpenCode, the harness used in SWE training.
Validation
Head
3d0e643db9, on #54126ff53fb3ac. The stack was rebased ontomainafter #5266 merged. Tests ran as Slurm jobs on one node each, in therl-gymCI container with the repository's dev dependencies; nothing ran on a login node. In that containermainitself has 179 failures and 13 errors in the core unit suite (job 9188100), so results are compared withmain's list by test id. Two test files that hang there, onmaintoo, are left out:tests/unit_tests/test_slurm_control.pyandtests/unit_tests/benchmarks/test_agentic_vbench_staging.py.ruff checkandruff format --checkclean; all ten server suites pass; the core suite differs frommain's list only by tests that fail from run to run on either side.NEMO_GYM_CHECKPOINT_E2E=1): harness scenarios 11 passed, sandbox 6, sequences 4, fake backend 1,test_checkpoint_e2e.py45 passed and 12 skipped.stoppedreceipt after a take-over; an abandon that fails twice; a launch that ended by itself and failed; close with a pending take-over; thecheck_failedretry; stopping a launch with no held pause; and, end to end, a launch taken over once, checkpointed, and taken over again (one launch,pause 2, relay generation 3, the held call re-sent byte for byte to the third model server).BUN_BE_BUN=1). Arelay_unavailablewarning in a live run would be the first sign that it does not start there.pre-commit run --all-files; any live sandbox, real-model or training run on this head.e62ed9ca9a), not repeated on this head: 16-node full-SWE run on AgentENV, Slurm job 9048275 (2 h, five routes, 8 Gym replicas), compared with reference job 8760594 on an earlier stack. 3 training steps (2981 s, 2567 s, 670 s; reference 2948 s, 2606 s, 681 s); 8 rollout checkpoints saved, 0 failed (reference 7 / 0); checkpoint save median 57 s, Gym commit median 50 s (reference 65 s and 48 s); 351 full 16-rollout batches, median 730 s (reference 347, 720 s); no snapshot, fork, anti-cheat, base-commit or patch-extract failures. The AgentENV gateway returned about four times as many 502s as in the reference; on the servers of this stack each was a retried first attempt and none exhausted its retries. Not exercised: the run had no crash, so no restore and no resume in place ran;scale_sweis not on the checkpoint layer.Follow-ups, not in this PR:
Compatibility
snapshots.keep_guest_clock, feat(sandbox): AgentENV snapshots, lease and kill-at-timeout for the E2B provider #5410).keeps_processesandrelay_gen. Older bookmarks restore through the relaunch path; arelay_pythonfield from an earlier version of this PR is ignored.resumed_conversationand, for a restored launch not yet taken over, its held pause; older state restores through the relaunch path.nemo_gym.agentsexportscheck_restored,RestoredLaunch,NotResumable,abandon_launchandstop_and_confirm_cleanup.OpenCode resumed in place:(WARNING),cannot resume in place: ... reason ...(INFO forrelay_gone, which also covers a relay that died or was restarting; WARNING otherwise),abandoned a restored launch,could not abandon.🤖 Generated with Claude Code