Repository navigation
feat(opencode): pause at checkpoints and resume after a crash - #5268
Conversation
77110b2 to
f0e3843
Compare
f0e3843 to
36ae821
Compare
36ae821 to
ba4d1bd
Compare
| async with participant.activation( | ||
| state.request.agent_session_id, state.request.episode_id, index=index | ||
| ) as activation: | ||
| response = await self._session_response(state, body, prompt=prompt, system=system, activation=activation) |
There was a problem hiding this comment.
_activation_task calls this without a deadline, so launch_deadline stays None and every relaunch gets the original full timeout. The continuation path uses started + timeout and adds paused time back. Is a stopped launch supposed to get only what is left of the budget?
There was a problem hiding this comment.
Fixed in an earlier revision and still so: a relaunch gets what is left of the activation's budget, deadline + paused time (_run_launches), not the full timeout again.
| await state.discard_conversation(timeout=timeout) | ||
| state.harness_session_id = None | ||
| state.message_ids = [] | ||
| return payload |
There was a problem hiding this comment.
This fresh-start path clears harness_session_id and moves the data directory aside, but the command in payload was already built with --session for the old id. Does opencode run --session then look that id up instead of running the original prompt? Should the command be rebuilt after the id is cleared?
There was a problem hiding this comment.
Fixed in an earlier revision: the launch command is built after the reprompt decision (_relaunch_payload takes the payload as a callable), so a fresh start no longer names the conversation it set aside.
| command.extend(["--session", state.harness_session_id]) | ||
| payload = { | ||
| activation_id = {} | ||
| if state.is_continuation: |
There was a problem hiding this comment.
This launch tag is set only when is_continuation, and those sessions are the ones _seed_restarts keeps out of checkpointing. The relaunch loop is the checkpointed path, which never sets NEMO_GYM_OPENCODE_ACTIVATION_ID, so the header plugin sends no X-Session-Id. Do relaunched calls still join the one invocation, or should this tag be on the checkpointed launches?
There was a problem hiding this comment.
The tag is only needed by continuation sessions, where one sandbox serves several activations and the header tells them apart. A checkpointed session has one activation, and its invocation ID is the rollout's capture key, so every relaunch's calls join the same invocation without the header. No change.
0b71f66 to
ecf2a34
Compare
ecf2a34 to
df4d0b9
Compare
OpenCode episodes were restarted from scratch by every checkpoint restore, and a checkpoint had to wait for the harness. The agent now exports its sessions and uses the shared pause mechanism. - checkpoint_mode = "exported" and rebinds_tool_accesses = True. A session whose sandbox the agent owns (no sandbox_access) or a continuation session restarts instead. - A checkpointed session keeps OpenCode's conversation under the sandbox's session root, on the snapshotted disk, and the activation runs inside participant.activation(), so close and retire cancel the launch. - The launch loop runs run_until_parked: a confirmed pause parks the activation and continues the harness in place; a stopped harness is relaunched with the unspent budget (time paused does not count). A relaunch, or the first launch after a restore, resumes the saved conversation when it starts with the task and has a completed assistant message: resume_opencode.sh starts `opencode serve` in the sandbox and re-posts the last user message with empty parts, so no user turn is added. Otherwise the original prompt runs fresh, with the reason logged. - A re-sent activation index is answered from the saved reply; the reply metadata reports harness_launches. - Hooks: export_agent_sessions, restore_agent_sessions (unconnected), and _rebind_restored_agent_session_state, which connects to the forked sandbox, reattaches the SandboxSession and reinstalls missing files. A restored session that was never re-bound answers 409. - nemo_gym/testing/checkpoint_conformance.py: check_harness_adapter(), run here against OpenCode with a fake `opencode` that implements both `run` and `serve`. Provenance: #4274's pause idea, resume decision and resume helper, and #4553's agent half (legacy stack), rebuilt on main's SandboxSession and bash supervisor. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]>
…atabase snapshot.py keeps each message's id beside its info, because OpenCode stores the id on the message row and not in its data; resume_payload read it from info and failed with KeyError 'id' on every real export, so every relaunch and restore started the task afresh (16-node job 8459954: 2 of 2 relaunches). Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]>
…nch that saved nothing in one line A sandbox that was just created or restored can refuse a connection for a few seconds after it first answered (a gateway 502). OpenCode's seed failed on its first commands then, and the rollout started over (job 8539361: the workdir, preparation and runtime install failed for 3+ sandboxes each). - `exec_idempotent` (agent utilities) runs a command and retries it, twice, when the provider raises; a returned result, any exit code, is final. Only for commands that are safe to run twice. - OpenCode runs its workdir creation, sandbox preparation (it checks before it installs), runtime install (the installer serializes and skips a runtime in place) and the "set the conversation aside" move through it. - A restore that finds OpenCode had written no conversation yet (no root session) logs one INFO line and starts afresh, as before, instead of a WARNING with a traceback (`NoRootSessionError`). - A launch that ended without finishing and left no session database or no root session raises `NothingCapturedError`, which the session logs as one WARNING line with the runner's log, instead of a chained capture traceback on top of the launch's own error. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]>
…arked session's slot always comes back The slot was taken inside Activation.queued() but given back by a try/finally that began only after it. A retire or close of a session parked on the way out of queued(), after taking a slot while a checkpoint was open, raised before that finally, and the agent server ran with one slot fewer for good. Activation.slot() takes and releases the slot in one scope; without checkpointing, the same holds through a local helper. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]>
…the checkpoint pause Found in a review of the harness pause and of OpenCode's relaunch. Relaunch and re-bind (OpenCode): - A relaunch that starts the task afresh no longer names the conversation it set aside. The launch command was built before the decision, so it kept `--session <id>` of the discarded conversation; it is now built after it, and the fresh start also drops the observations and trajectory of the discarded launch. - A saved conversation that cannot be read is no longer taken for a missing one. The relaunch reads the database itself, three times, and raises if it still cannot, instead of setting a resumable conversation aside after one failed download on a sandbox a restore just forked. - A restored session gets back what its seed had set and a checkpoint does not carry: `export_dir` and the environment of OpenCode's import and export. Without them a restored episode wrote no exports. - The re-bind's first command on the forked sandbox goes through `exec_idempotent`, and a re-bind that fails releases its sandbox connection instead of leaving one behind per retried seed. - A resumed launch that ends in a reported model error (API error, context overflow) is recognised: `resume_opencode.sh` exits 0 once the server answered, where `opencode run` exits 1. - A session that continues an imported conversation (`session_import_path`) restarts after a crash: a relaunch compared the imported conversation's first prompt with the task's and discarded it. - A reply given again from a saved one forwards its verification failure report, as the first reply does. - Text parts OpenCode marks synthetic are not part of the prompt a saved conversation is matched against. `resume_opencode.sh`: - The prompt request runs in the background and is waited for. Bash runs a trap only between foreground commands, so the supervisor's TERM was held until the turn ended: every stop of a resumed launch took the full grace period and the server was killed. - The server is ended with TERM: bash starts a background command with INT ignored. - The loopback request ignores proxy variables, and a path outside ASCII is encoded as its UTF-8 bytes. Pause and stop (agent utils): - A stop of a launch that is still staging cancels it. The stop had no harness to end, and the launch then ran its harness through the checkpoint, or waited until the provider deadline for the continue of a pause request that did reach the sandbox. - An error of a launch that left no receipt of a stop, for example because its sandbox died, propagates as the launch's own failure instead of parking a dead session. - A pause waits, bounded, for a launch that is staging, so a snapshot does not run beside the uploads and the launch command's polls are held like a running launch's. Process supervisor: - A hold before the launch is not added to the harness deadline again by the first pause after it. - An expire that arrives during a hold before the launch launches nothing. - A pause scans until a scan finds no new process, not twice. Other: - The launch number in the client session id is gone. Only a continuation session sets that id and only a checkpointed session relaunches, and a session is never both, so nothing could send it. - "discarded N abandoned call row(s)" is logged only when rows were dropped. - The OpenCode runtime's sandbox path prefix is a module constant, so a test whose sandbox is the test machine installs its fake CLI under its own directory instead of one /tmp path shared by every run on the node. Tests: the cases above; the receipt of a stop that fenced a launch, which has `stopped` since the pause in place; the kit's local provider; pause numbering, malformed requests and receipts; deterministic replacements for races and fixed sleeps (a harness that ticks until the test ends it, bounded waits, cleanup of a paused harness when a test fails half way); larger limits around the real supervisor. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]>
…he calls it deletes "disconnected" Review of #5268. - `CheckpointableLedger` requires the method, and the model server refuses a ledger without it at startup, so the `getattr` fallback and its warning could not be reached. The method is called directly. - "abandoned" already means a rollout attempt the framework gave up on, and "discard" a fenced write. The calls are now `disconnected` (`GateSnapshot.disconnected`, `take_disconnected`), the ledger method is `delete_calls`, and the helper `delete_disconnected_calls`. Nothing of this is released, so there is no alias. - The comments describe the rule the code applies (a call that ended while admission was closed, before its response started) and the rows it leaves: an intent row and, sometimes, a failure row. - `FileLineageStore.delete_calls` removes the rollout from the cache through `_ledger_cache_pop`, which also drops the lineage caches. - `PolicyWorkerLink` uses its gate's ledger instead of a second copy. - New test: a worker deletes the rows of such a call when it reopens. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]>
…ever park beside a launch that still writes Review of #5268. Supervisor (`process_supervisor.sh`): - `--max-pause SECONDS`: a pause nobody continues used to hold the harness for good, with the deadline not running and an expire waiting for the continue. Past the limit the supervisor ends the harness as at its time limit and the receipt records `pause_expired`. The limit counts the supervisor's polls, not the clock. `SandboxSession.execute` passes the pause allowance as the limit. - The wait for a continue also ends when the harness is gone. - The usage text lists the pause options. Pause and continue requests (`supervisor_client._request`): - bounded as a whole, so a request queued behind a full provider does not wait for a harness to end; - run from `control_cwd`, so they do not need a workdir the task moved or deleted. `SandboxSession.pause_harness` answers `unconfirmed` while the launch is still staging after its wait: a pause request would only hold the launch command, and staging would keep writing during the snapshot. `run_until_parked` is now `run_with_checkpoint_pauses` (it returns when the launch ends, parked or not), and `Finished`/`Stopped` are `LaunchFinished`/`LaunchStopped`. It also: - repeats a pause request that failed in transport (4 attempts, 1 s doubling) and waits the same way between continue attempts; a timeout or an answer of the supervisor is not repeated; - treats a `receipt_missing` receipt (main's #6280: the supervisor died and the provider proved the sandbox empty) after its own stop as a stopped launch, not a finished one; - raises, and does not park, when a launch cancelled while staging does not end within the stop timeout; - reads the exception of a park request or an abandoned launch, so asyncio does not log it as never retrieved. `SandboxSession.reattach` is now `rebind`, the word the checkpoint code uses; `ParkingActivation` and `SandboxSessionCheckpoint` are exported. `exec_idempotent` takes `cwd`, `env` and `timeout_s` explicitly. The conformance kit moves to `nemo_gym.agents.testing` as `check_harness_checkpointing`: it checks an agent adapter, and can now import `AGENT_ACTIVATION_HEADER`. Its local provider is private. The crash scenario ends the first agent (handles, processes, tasks) before the restore and cleans up in a `finally`, and an adapter can supply `crash_recovery_assertion` to prove the recovery continued the saved conversation. Tests: the deadline-extension test now fails without the extension, the hold test no longer asserts a tight real-time bound, and each change above has tests. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]>
… in a checkpoint, and reprompt like a first launch Review of #5268. - A saved reply is given again only to the request that produced it: the session keeps the request's SHA-256 with the reply, also in the checkpoint, and a different request under the same activation index is a 409, as before this PR. - The checkpoint keeps a finished session's trajectory, restored under the replacement attempt's rollout ID, so a session that finished before the checkpoint still closes with it, also when closed before it is re-bound. - A re-bind that has to install the runtime again passes the seed's pinned ripgrep and plugin dependencies, and stages them through the sandbox connection it holds (`state.session` is not set yet). - "Resume" names the checkpoint step, so continuing a saved conversation is a reprompt: `reprompt.py`, `reprompt_opencode.sh`, `RepromptDecision`. `discard_conversation` is `set_conversation_aside` (`data.set-aside-N`). - The reprompt helper rejects permission requests, as `opencode run` does; under `opencode serve` nothing answered one and the turn waited until the harness deadline. It keeps the server's log and the request's status in the launch directory, and prints the log's end when the request fails. - A saved conversation that downloads but cannot be parsed starts the task afresh under its own reason; one that cannot be downloaded is still retried and then fails the activation. - Tool calls a relaunch finds unfinished are counted once each (`interrupted_tool_calls` in the launch record) and mark the observations with the gap `tool_call_interrupted_by_relaunch`. - The reply's metadata carries `harness_paused_seconds` next to `harness_launches`. - `_reported_model_error` keeps main's exit-0 context overflow (#6471) for a launch that did not reprompt. - The preparation command's package install takes a lock, so a retry that overlaps its first run waits for it. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]>
…nd the supervisor's pause files Review of #5268: the OpenCode README gets a section on checkpoints (settings, what a pause and a stop do, pause limits, clocks, recovery after a crash, the reprompt, interrupted tool calls, restart-only sessions); the agent integration page summarizes it; the harness guide lists the pause and continue files, `stopped` and `pause_expired` in the receipt, and `run_with_checkpoint_pauses`. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]>
…he launch The supervisor now records that a stop request, not the harness's own exit or the deadline, ended or fenced the launch. Hermes's test compared the whole receipt. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]>
…get, and report a timeout after a stop Second review round of #5268. - A continue the supervisor answered with a refusal is not sent again: the same sequence number would read the same answer from the acknowledgement file. `HarnessPauseResult.acknowledged` tells such an answer from a lost one, which is still retried. - `exec_idempotent`'s `timeout_s` is the budget of all attempts and the waits between them, not of each attempt. - When a launch was stopped at a checkpoint and the activation's budget is spent, nothing is relaunched: the reply is built from the stopped launch and reports a timeout. Preparing the relaunch used to discard that launch's output and then raise. - A re-bind installs the runtime again only when the check of its files ran and found some missing. A check the provider could not run is repeated and then fails the re-bind. - `prepare_launch` creates the launch directory through `exec_idempotent`. - The observation bundle of a restored session closed before its re-bind is schema 2.0, like every other close. - The saved conversation's export is read and decoded in the worker thread that makes it. - The test of the unread park-request exception now fails without its fix. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]>
…nimal adapter in the core suite The kit's main check only ran in OpenCode's server suite, which the core coverage gate does not measure, so the combined core coverage fell to 94.86%. A reference adapter whose harness is a shell loop now takes the kit through every scenario with the real process supervisor, and a second test shows the kit fails an adapter that cannot pause in place. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]>
…ound retries by one deadline, and report a timeout when the relaunch budget runs out - run_with_checkpoint_pauses: a launch cancelled while staging is not reported stopped while its staging task still runs, and no error leaves the activation until the launch has ended and staging no longer runs. Until then the session is not ready, so the checkpoint waits for it up to its own deadline. SandboxSession gains staging and wait_staged. - exec_idempotent: every attempt runs under the one deadline, which now also bounds a provider's wait for capacity; no attempt starts once the budget is spent. - OpenCode: what a stopped launch produced is kept until its relaunch has started its harness. A budget that runs out before then, while the relaunch is prepared or staged, ends the activation as a timeout with the stopped launch's output. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]>
…oted as one argv word With argv_prompt_quoting (#5458) a launch sends the prompt as `opencode run` builds it from one argv word, so the saved user turn holds the quoted text. A relaunch after a stop compared that turn with the unquoted prompt, found no match, and started the task afresh every time. It now compares with the prompt as the launch sent it. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]>
3e47342 to
dc1ad56
Compare
|
/ok to test dc1ad56 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/44946254966 |
…e-v1-v2 Resolve conflicts with main's checkpoint/resume (#5268) and task-container (#5458) work: - app.py: keep main's _reported_model_error signature (reprompted) with the _CLASSIFIED_OPENCODE_VERSIONS docstring; take main's _install_session_files call and pass the release digests for every pinned version there, as the PR did inline. - README.md: OpenCode 2 prints v2.3.2, plus main's task-container sentence. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
What changed and why
OpenCode episodes could not be checkpointed: a checkpoint either waited for the harness (which can take an hour) or, after a crash, started the episode over. This PR makes OpenCode the first harness that is paused in place at a checkpoint and, after a stop or a crash, continued without an added user turn. The pausing mechanism is shared, so other harnesses on
SandboxSessioncan adopt it.Terms used below: the activation parks at a checkpoint; the harness (OpenCode's processes) is paused and continued; a restored session is re-bound to the sandbox its replacement attempt borrows; relaunching OpenCode on its saved conversation is a reprompt (the last user message is posted again with no new parts). "Resume" is kept for the checkpoint step that releases parked participants.
Four parts:
4a. Capture fix (a cherry-pick of #4451)
Stopping a harness would otherwise poison the token-capture ledger. The policy gate records calls that ended while admission was closed, before their response started (
GateSnapshot.disconnected). The commit leaves them out like undelivered calls, and the resume deletes their rows from the live ledger (CheckpointableLedger.delete_calls, required of every ledger), in the coordinator and in each worker.4b. Pause in place (shared agent utilities)
--max-pause, set from the pause allowance). A pause nobody continues, for example because the agent server died during a checkpoint, ends the harness as at its time limit, and the receipt recordspause_expired. The limit counts the supervisor's own polls, not the clock. The wait also ends when the harness is gone.CleanupReceipt.stopped(optional): records that a requested stop ended the harness or fenced its launch.SandboxSession(pausable=True):pause_harness()andcontinue_harness(), a pause allowance on the provider's exec deadline, andcheckpoint_state()withrebind()to re-bind a session to the sandbox a restore forked. A pause waits, bounded, for a launch that is still staging; if staging is still running after that, the pause is not confirmed and the launch is stopped, so a snapshot never runs beside the uploads. Pause and continue requests are bounded as a whole (a request queued behind a full provider times out) and do not need the task's workdir to exist.run_with_checkpoint_pausesraces a launch against the activation's park request: pause, park, continue after the checkpoint, and repeat for the next one. It returnsLaunchFinishedorLaunchStopped. A pause or continue request that fails in transport is repeated with backoff and the same sequence number. An unconfirmed pause or a repeatedly failing continue falls back to a stop, and the adapter relaunches. A supervisor that died during that stop (main'sreceipt_missingreceipt, feat(agents): supervisor stop policy and Codex tool pid namespace #6280) counts as stopped. A launch cancelled while staging that does not end raises instead of parking. A cancelled activation still stops its harness.4c. OpenCode policy
checkpoint_mode = "exported". A re-bound session renders its configuration again, andmain's MCP grant check (feat(gdpval): run OpenCode and OpenClaw with task tools #5079) runs for every launch. These sessions restart instead: one whose sandbox the agent owns, a multi-turn continuation, one that continues an imported conversation (session_import_path), and an OpenCode 2 session (the reprompt uses OpenCode 1's server API and store). The deprecated local/runis a restart too.sandbox_session_root, which must be on the sandbox's snapshotted disk.Activation.slot), and a restored session that was never re-bound answers 409. A re-sent activation is answered from the saved reply only when it is the request that produced it: the session keeps the request's SHA-256 with the reply, also in the checkpoint, and a different request under the same activation index is a 409.reprompt_opencode.shstarts OpenCode's server in the sandbox and re-posts the last user message, which OpenCode runs again without adding a turn. Otherwise the task starts afresh and the saved conversation is set aside, with the reason logged at WARNING. Replies reportharness_launchesandharness_paused_seconds.[Tool execution was interrupted](OpenCode's text). The rollout is kept and marked: the observations carry the gaptool_call_interrupted_by_relaunch, and the launch record counts the calls.opencode runexits 1); main's exit-0 context overflow of OpenCode 1.15 (fix(opencode): score a context overflow that OpenCode 1.15 reports with exit 0 #6471) is kept for launches that did not reprompt.reprompt_opencode.sh: rejects permission requests, asopencode rundoes (underopencode servenothing answered one, and the turn waited until the harness deadline); keeps the server's log and the request's status in the launch directory and prints the log's end when the request fails; runs the prompt request in the background so the supervisor's TERM acts at once.check_harness_checkpointing(nemo_gym/agents/testing/checkpoint_conformance.py, exported fromnemo_gym.agents), run against OpenCode with a fake OpenCode binary under the real supervisor. Its crash scenario ends the first agent before the restore, and an adapter hook asserts that the recovery continued the saved conversation.4d. Setup retries and capture errors (from the AgentENV training runs)
exec_idempotent(shared agent utilities) runs a setup command again, twice, with a short backoff, when the provider fails to run it; a returned result, any exit code, is final. Only for commands that are safe to run twice, also at the same time: the preparation command's package install takes a lock for that.NothingCapturedError).Known limit: a pause stops OpenCode's processes, not their clocks. A tool that runs across a pause sees the paused time, so its timeout can fire when OpenCode continues (the shell tool's default is two minutes). Model calls are not affected. #5411 removes the freeze on sandboxes whose snapshots keep processes.
This builds on ideas from #4274, #4553 and #4222 in the legacy stack, rebuilt on
main'sSandboxSession(#4747) and bash supervisor (#5151).How it works
Where this PR sits in the overall flow
The highlighted parts are what this PR changes.
flowchart LR C["Controller<br/>NeMo RL, or rollout collection"] CO["Coordination<br/>prepare, commit, resume, restore,<br/>retire, forget, release"] E["Environment server<br/>single_agent_turn, single_agent_turn_legacy<br/>bookmarks, re-seed after a restore"] A["Harness agent, e.g. OpenCode<br/>run_with_checkpoint_pauses, re-bind, reprompt"] S["Process supervisor in the task sandbox<br/>pause, continue, stop"] R["Resources server, e.g. SWE-bench<br/>owns and lends the task sandbox"] OB["Session base with checkpoints<br/>export, restore, release"] K["Sandbox checkpointer<br/>snapshot index, release, gc"] P["Sandbox provider, e.g. OpenSandbox<br/>snapshot, fork, delete, list"] M["Policy model<br/>held calls, capture ledger"] D[("Checkpoint directory<br/>and state_dir")] C --> CO --> E & A & R & M E -- "seed, re-seed" --> R E -- "seed, re-seed, activation" --> A R -. "sandbox_access" .-> A A --> S R --- OB --> K --> P A -- "model calls" --> M CO --> D classDef this fill:gold,stroke:darkorange,stroke-width:2px,color:black class A,S,M thisThis PR
One activation under
run_with_checkpoint_pauses, across a checkpoint with a confirmed pause, a checkpoint whose pause fails, and a crash.A checkpoint while OpenCode works, end to end:
Where this sits in the stack
This is one PR in a stack for checkpointing environment-server episodes whose agent harness runs in a sandbox the resources server lends (first pair: OpenCode and SWE-bench on OpenSandbox; #5410 to #5413 add AgentENV, where OpenCode resumes in place after a restore). #5264 to #5267 have merged, and this PR is rebased onto
mainafter them. #5269 and later are still based on the previous version of this PR and are restacked next. The stack runs parallel to thelegacy_agentpath of #4220 to #4936, which it does not change or depend on.Issue
No tracking issue. This implements the environment-server plan for checkpointing sandboxed harnesses, on top of the merged partial-rollout checkpoint stack (#3882 to #3909, #4997).
Validation
Head
23543cf01e, onmain662dc7559f. 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 fails 176 tests with 12 errors in the core unit suite, 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.main(jobs 9214018, 9214020): all oftests/unit_tests, the SWE-bench and SWE-rebench server tests and the environment server tests. The same 176 failures and 12 errors on both; no test fails on this head that passes onmain.tests/unit_tests/agents,tests/unit_tests/models: 4382 passed, 25 skipped, 5 failed. The 5 are the container's, onmaintoo: three needcloudpickle, which the test environment lacks, and two compare a shell's stderr that the image adds lines to.ruff checkandruff format --checkclean on the changed files (ruff 0.9.9).run_with_checkpoint_pauses, including retries, a staging launch and a lost supervisor; the capture fix in the coordinator and in a worker; the conformance kit against OpenCode (pause in place, relaunch, crash then re-bind and reprompt, with the recovery assertion); the saved reply and its request before and after a restore; the trajectory through a checkpoint; the pins on a re-bind; the two unusable-conversation cases; interrupted tool calls; the reprompt helper's permission reject on both of its transports.opencode runleaves in its database, and message order after a reprompt.pre-commit run --all-files; any live sandbox, real-model or training run.e62ed9ca9aplus baseline-parity switches), not repeated on this head: the MR 69 50-step recipe on AgentENV, 16 nodes, five SWE harnesses as OpenCode sessions, once without sandbox resume and once with it.Follow-ups: a smoke run of the pause, the stop and relaunch and the reprompt with a real OpenCode and model on this head; the pause mode in each launch record (#5411).
Compatibility
--max-pause, used only by pausable sessions; other harnesses launch exactly as before.CleanupReceipt.stoppedandpause_expiredare optional.SandboxSession:pausabledefaults to false; the new methods are additive.sandbox_session_root(default/tmp/nemo-gym-opencode-sessions), and replies carryharness_launchesandharness_paused_seconds. New settingssandbox_session_rootandcheckpoint_pause_allowance_seconds(default one hour): a launch's pauses must fit within it, and one pause longer than it ends the harness as at its time limit.checkpoint.policymust implementdelete_calls; the checkpoint protocol is in no release, andFileLineageStoreis its only implementation.main's grant check runs for every launch, including a relaunch after a stop and the first launch after a restore.🤖 Generated with Claude Code