Repository navigation
feat(checkpoint): hold-pause a harness when the sandbox snapshot keeps its processes - #5411
Conversation
bdd2ef3 to
d37376c
Compare
d37376c to
4aee956
Compare
4aee956 to
122b586
Compare
122b586 to
42dabe5
Compare
33acd80 to
8ddbaa7
Compare
8ddbaa7 to
7c2b211
Compare
37d9fe7 to
2f2be52
Compare
d7da1aa to
1a09291
Compare
1a09291 to
8ec70b0
Compare
| # The launch command was already sent: its supervisor reads this request as it starts and holds the | ||
| # launch. Ask once more for its acknowledgement, which names it, so the pause is recorded with the | ||
| # supervisor that holds it. The request is the same one, so repeating it changes nothing. | ||
| outcome, acknowledgement = await request_pause( |
There was a problem hiding this comment.
Consider waiting for a sent launch in the original pause request
For an already-sent launch, consider passing that state into the request transport and waiting within the original request's timeout for the launch claim and acknowledgement. This would avoid a second remote exec round trip and address the delayed-launch race already discussed in this PR. Preserve immediate confirmation before any launch has been sent, and return unconfirmed if a sent hold-mode launch still has no acknowledgement when the bound expires.
There was a problem hiding this comment.
Done in ae32b2c50a. request_pause takes launch_sent, and the session passes whether its launch command was sent. With it, the one exec waits within the request's timeout for the launch claim and then the acknowledgement, so the second request is gone. Before any launch command the answer is still not_launched at once. When the bound ends with no claim the answer is not_launched, which a hold-mode session reports as unconfirmed; with a claim and no acknowledgement it is timeout.
Transport tests cover a claim and acknowledgement that arrive during the wait, a launch that never claims (answered only after the bound), one that claims and never answers, and one a stop fences meanwhile.
| acknowledge() { | ||
| printf '{"seq": %s, "confirmed": %s, "pids": [%s], "error": %s}' "$2" "$3" "$4" "$5" >"$1.tmp" && mv -f "$1.tmp" "$1" | ||
| local named=null | ||
| [[ -n ${identity-} ]] && named="\"$identity\"" |
There was a problem hiding this comment.
[P3] Clear inherited identity before the startup acknowledgement
The startup continue acknowledgement runs before identity is assigned. If the sandbox environment contains an identity variable, acknowledge() uses that inherited value instead of null; quotes or newlines in it also produce invalid JSON. Initialize identity= before the startup acknowledgement and add a regression with an inherited value.
There was a problem hiding this comment.
Fixed in ae32b2c50a: the supervisor sets identity= before anything can acknowledge. test_an_identity_variable_in_the_sandbox_environment_is_not_taken_for_the_supervisor_s starts it with an inherited identity containing a quote and a newline, and checks that the startup acknowledgement names none and a later one names the supervisor.
| parked. | ||
|
|
||
| On a provider whose snapshot keeps the sandbox's processes (`capabilities.snapshot_keeps`), create the session with | ||
| `pause_mode="hold"`, and pass the same `pause_mode` to `SandboxSession.rebind` after a restore. The supervisor then |
There was a problem hiding this comment.
[P3] Add glossary entries for the new pause concepts
This introduces pause mode and hold mode, but neither is defined in key-terminology.mdx. The root terminology instructions require glossary entries for new concepts in the same PR. Add concise definitions distinguishing stop mode's process signals from hold mode's acknowledgement without signals.
There was a problem hiding this comment.
Added in ae32b2c50a: a Pause mode entry in key-terminology.mdx that defines stop mode (SIGSTOP and SIGCONT to every process the supervisor reaches) and hold mode (an acknowledgement and no signal, for a provider whose snapshot keeps processes).
8ec70b0 to
40f03f7
Compare
…s its processes A VM memory snapshot (AgentENV) captures the whole sandbox at one instant, processes included, so a checkpoint does not need the harness frozen to get a consistent copy; freezing it there only adds the pause failures a process in uninterruptible sleep causes. The supervisor gains `--pause-mode hold`: a pause is acknowledged at once without signalling anything, the deadline stops counting until the continue as before, and the checkpoint holds the harness's model calls instead. The default stays `stop` (SIGSTOP/SIGCONT), which a files-only snapshot still needs. Each acknowledgement now names the pause mode and the supervisor's identity (`PID.START`, the marker it gives the processes it launches). `SandboxSession(pause_mode=...)` launches in that mode, and `checkpoint_state()` records the pause the supervisor holds and its identity, so a restore of a process-keeping snapshot can find the launch again. The sandbox checkpointer records whether the provider's snapshots keep processes (`keeps_processes`, false for older records), and the docs say what a restore keeps is provider-dependent. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]>
…a held pause only while the launch runs Found in a review of the hold pause. - `SandboxSession.checkpoint_state()` reports a held pause only while the launch runs. A launch that was stopped while paused kept reporting it, and a restore would have looked for a supervisor that is gone. - A pause that reaches the sandbox after the launch command was sent, but before its supervisor started, is asked once more. The supervisor reads the request as it starts and holds the launch, and its acknowledgement names it; without the second request the checkpoint recorded a started launch and no supervisor holding it. - The supervisor's header says that it does not watch the harness during a hold: one that exits is reaped after the continue. Its usage text lists the pause options. - Docstrings and the harness tutorial page say what `confirmed` means in hold mode and that `reattach` takes the pause mode. - Tests: the hold-mode session test ends its harness itself and no longer leaves it behind when it fails; the supervisor's hold test checks the child and a detached service too and no longer races the deadline; a harness that ends during a hold, a stop during a hold, a hold before the launch, the branches of `checkpoint_state()`, `reattach` with a held pause, and the pause mode in the launch command. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]>
…capabilities The E2B provider now declares it as SandboxCapabilities.snapshot_keeps in place of the untyped snapshot_keeps_processes attribute, so the checkpointer reads it with provider_capabilities(). Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]>
…uest, and do not confirm a hold nothing names A pause requested after the launch command was sent, but before its supervisor claimed the launch, was asked a second time and confirmed when that also found no supervisor. In hold mode the supervisor could then start before a snapshot that keeps processes, holding a pause that no checkpoint state names. The pause request now waits, within its own timeout, for a sent launch to claim and acknowledge, in one exec. If no supervisor has started when the timeout ends, a hold-mode pause is unconfirmed, so the caller stops the launch, which fences it. Stop mode still confirms: its snapshot keeps no processes. Also: the supervisor clears an `identity` variable inherited from the sandbox environment, so the acknowledgement it writes before it has an identity names none; and the glossary defines pause mode, stop mode and hold mode. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]>
ae32b2c to
1962337
Compare
|
/ok to test 1962337 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/45084680930 |
What changed and why
At a checkpoint, the process supervisor (#5268) freezes the harness with
SIGSTOPand continues it withSIGCONTafterwards. That is needed when the snapshot copies only files, as on OpenSandbox. But a process in uninterruptible sleep cannot be stopped, so the pause is then not confirmed and the harness is killed and relaunched.A VM memory snapshot (AgentENV, #5410) captures the whole sandbox at one instant, processes included, so the harness does not need to be frozen for a consistent copy. This PR adds a pause that holds the harness without signalling it, and records what a later restore needs to find the paused launch again.
Hold pause
stop.SandboxSession(pause_mode=...)launches the supervisor in that mode.What each acknowledgement records
Every pause and continue acknowledgement now carries:
mode:stoporhold.identity: the supervisor's PID and process start time.SandboxSession.checkpoint_state()records the held pause and the supervisor's identity. After a restore of a process-keeping snapshot, #5412 uses these to recognise the same launch.Checkpointer record
The sandbox checkpointer (#5265) records whether the provider's snapshots keep processes (
keeps_processes). Older records read asfalse. The resources-server tutorial and the SWE-bench checkpoint module say that what a snapshot keeps depends on the provider.Found in the review of this PR and fixed here (last commit)
checkpoint_state()reports a held pause only while the launch runs. A launch that was stopped while paused kept reporting it, and a restore would have looked for a supervisor that is gone.confirmedmeans in hold mode;reattachtakes the pause mode.How it works
sequenceDiagram participant G as Gym (prepare and resume) participant S as Process supervisor participant H as Harness (OpenCode) G->>S: pause N alt stop mode (OpenSandbox) S->>H: SIGSTOP S-->>G: ack with seq N, mode stop, identity else hold mode (AgentENV) Note over H: keeps running, model calls held by the relay (PR 5412) S-->>G: ack with seq N, mode hold, identity end Note over G: snapshot the sandbox G->>S: continue N S->>H: SIGCONT (stop mode only)Where 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 is the checkpoint-side half of AgentENV in-place resume. #5412 and #5413 build on the pause mode and the recorded identity.
Validation
Head
37d9fe7184, on #5410937c63b37b. 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.3d0e643db9, which includes this PR (jobs 9188099, 9188102): import-linter clean;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.mainonly by tests that fail when the node is loaded and pass when their file runs alone (test_harness_pause.py::test_a_hold_before_the_launch_is_not_added_to_the_deadline_again_by_a_later_pause,test_exec_transport.py::test_confirmed_cleanup_cancels_stuck_transport) andtest_docker_compose.pytests that fail from run to run onmaintoo. The whole core suite was run per level on the previous base (feat(swebench): checkpoint the task sandboxes of episode sessions #5266's head before it was squash-merged), with the same result; on this base it ran on the tip only.NEMO_GYM_CHECKPOINT_E2E=1): harness scenarios 11 passed, sandbox 6, sequences 4, fake backend 1,test_checkpoint_e2e.py45 passed and 12 skipped.checkpoint_state(),reattachwith a held pause, the pause mode in the launch command, unchanged stop mode, and thekeeps_processesrecord.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.Compatibility
pause_modedefaults tostop, so OpenSandbox and every existing harness behave as before.keeps_processes, which reads asfalsewhen absent.checkpoint_state()no longer reports a held pause for a launch that has ended.🤖 Generated with Claude Code