Skip to content

feat(checkpoint): hold-pause a harness when the sandbox snapshot keeps its processes - #5411

Merged
pthombre merged 4 commits into
mainfrom
pranav/envckpt-8-hold-pause
Nov 22, 2026
Merged

pthombre merged 4 commits into
mainfrom
pranav/envckpt-8-hold-pause

Conversation

@pthombre

@pthombre pthombre commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

What changed and why

At a checkpoint, the process supervisor (#5268) freezes the harness with SIGSTOP and continues it with SIGCONT afterwards. 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

What each acknowledgement records

Every pause and continue acknowledgement now carries:

  • mode: stop or hold.
  • 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 as false. 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.
  • 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.
  • Documented: the supervisor does not watch the harness during a hold (one that exits is reaped after the continue); what confirmed means in hold mode; reattach takes 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)
Loading

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 main after 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.

  1. feat(checkpoint): protocol for harnesses that borrow a sandbox #5264: feat(checkpoint): protocol for harnesses that borrow a sandbox (merged)
  2. feat(sandbox): snapshot, fork and delete for OpenSandbox, with a checkpointer #5265: feat(sandbox): snapshot, fork and delete for OpenSandbox, with a checkpointer (merged)
  3. feat(swebench): checkpoint the task sandboxes of episode sessions #5266: feat(swebench): checkpoint the task sandboxes of episode sessions (merged)
  4. feat(swebench): typed sessions on the owner base with capture-once verify #5267: feat(swebench): typed sessions on the owner base with capture-once verify
  5. feat(opencode): pause at checkpoints and resume after a crash #5268: feat(opencode): pause at checkpoints and resume after a crash
  6. test(checkpoint): end-to-end harness scenarios, SWE-bench recipe, docs #5269: test(checkpoint): end-to-end harness scenarios, SWE-bench recipe, docs
  7. feat(swe): checkpoint the episode sessions of the repository-task servers #5331: feat(swe): repository-task servers on the sandbox owner base
  8. feat(sandbox): AgentENV snapshots, lease and kill-at-timeout for the E2B provider #5410: feat(sandbox): AgentENV snapshots, lease and kill-at-timeout for the E2B provider
  9. feat(checkpoint): hold-pause a harness when the sandbox snapshot keeps its processes #5411: feat(checkpoint): hold-pause a harness when the sandbox snapshot keeps its processes (this PR)
  10. feat(agent-utils): resume a supervised harness in place after a restore that kept its processes #5412: feat(agent-utils): resume a supervised harness in place after a restore that kept its processes
  11. feat(opencode): resume OpenCode in place on sandboxes whose snapshots keep processes #5413: feat(opencode): resume OpenCode in place on sandboxes whose snapshots keep processes

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 #5410 937c63b37b. The stack was rebased onto main after #5266 merged. Tests ran as Slurm jobs on one node each, in the rl-gym CI container with the repository's dev dependencies; nothing ran on a login node. In that container main itself has 179 failures and 13 errors in the core unit suite (job 9188100), so results are compared with main's list by test id. Two test files that hang there, on main too, are left out: tests/unit_tests/test_slurm_control.py and tests/unit_tests/benchmarks/test_agentic_vbench_staging.py.

  • Stack tip 3d0e643db9, which includes this PR (jobs 9188099, 9188102): import-linter clean; ruff check and ruff format --check clean; all ten server suites pass; the core suite differs from main's list only by tests that fail from run to run on either side.
  • This head (jobs 9188114, 9188115): the test areas the stack touches (OpenCode, SWE-bench, swe_rebench, agents, server runtime, sandbox, models) differ from main only 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) and test_docker_compose.py tests that fail from run to run on main too. 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.
  • Process-level checkpoint e2e on the stack tip (jobs 9188102, 9188735, NEMO_GYM_CHECKPOINT_E2E=1): harness scenarios 11 passed, sandbox 6, sequences 4, fake backend 1, test_checkpoint_e2e.py 45 passed and 12 skipped.
  • Rebase: the restore-policy change of the previous version is dropped, because feat(swebench): checkpoint the task sandboxes of episode sessions #5266 merged without a restore policy setting.
  • Tests: the hold pause (immediate acknowledgement, no signal to the child or to a detached service, deadline credited), a harness that ends during a hold, a stop during a hold, a hold before the launch, the new acknowledgement fields, each branch of checkpoint_state(), reattach with a held pause, the pause mode in the launch command, unchanged stop mode, and the keeps_processes record.
  • Review: two reviewers; no critical or major defect; what they found is fixed in the last commit.
  • Not run: pre-commit run --all-files; any live sandbox, real-model or training run on this head.
  • Earlier evidence, not repeated on this head (previous versions of the stack): live tests against AgentENV in which a held harness kept running through the snapshot and the continue was acknowledged in the forked sandbox; checkpoint and resume at 8 and 16 nodes.
  • Training run, on the stack two rebases ago (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_swe is not on the checkpoint layer.

Compatibility

  • Default unchanged. pause_mode defaults to stop, so OpenSandbox and every existing harness behave as before.
  • New acknowledgement fields are additive; readers ignore fields they do not know.
  • Checkpoint state gains the optional held pause and supervisor identity. Checkpointer records gain keeps_processes, which reads as false when absent.
  • checkpoint_state() no longer reports a held pause for a launch that has ended.

🤖 Generated with Claude Code

@pthombre pthombre added feature New capabilities, enhancements, or enablement work area:env-infra Shared environment framework, lifecycle, registry, scaffolding, and validation complexity:medium Single-domain change with interacting parts or a moderate review surface labels Oct 31, 2026
@copy-pr-bot

copy-pr-bot Bot commented Oct 31, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@pthombre
pthombre added this pull request to stack #5270 October 31, 2026 18:08
@pthombre
pthombre force-pushed the pranav/envckpt-8-hold-pause branch 2 times, most recently from bdd2ef3 to d37376c Compare November 2, 2026 06:16
@pthombre
pthombre force-pushed the pranav/envckpt-8-hold-pause branch from d37376c to 4aee956 Compare November 3, 2026 03:22
@pthombre
pthombre force-pushed the pranav/envckpt-8-hold-pause branch from 4aee956 to 122b586 Compare November 3, 2026 06:40
@pthombre
pthombre force-pushed the pranav/envckpt-8-hold-pause branch from 122b586 to 42dabe5 Compare November 5, 2026 20:07
@pthombre

pthombre commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

Being rebased onto current main, after #5264 and #5265 (already rebased). Until this branch is pushed, its diff still shows their old commits. Not ready for review yet.

@pthombre
pthombre force-pushed the pranav/envckpt-8-hold-pause branch 2 times, most recently from 33acd80 to 8ddbaa7 Compare November 12, 2026 20:35
@pthombre
pthombre force-pushed the pranav/envckpt-8-hold-pause branch from 8ddbaa7 to 7c2b211 Compare November 16, 2026 21:44
@pthombre
pthombre force-pushed the pranav/envckpt-8-hold-pause branch from 37d9fe7 to 2f2be52 Compare November 21, 2026 07:02
@pthombre
pthombre force-pushed the pranav/envckpt-8-hold-pause branch 2 times, most recently from d7da1aa to 1a09291 Compare November 22, 2026 00:20
@pthombre
pthombre force-pushed the pranav/envckpt-8-hold-pause branch from 1a09291 to 8ec70b0 Compare November 22, 2026 05:58
# 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(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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\""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@pthombre
pthombre force-pushed the pranav/envckpt-8-hold-pause branch from 8ec70b0 to 40f03f7 Compare November 22, 2026 20:06
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the ready-to-merge PR is approved, current, and waiting for final CI or merge label Nov 22, 2026
Base automatically changed from pranav/envckpt-7-agentenv-provider to main November 22, 2026 23:25
pthombre and others added 4 commits November 22, 2026 15:25
…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]>
@pthombre
pthombre force-pushed the pranav/envckpt-8-hold-pause branch from ae32b2c to 1962337 Compare November 22, 2026 23:25
@pthombre

Copy link
Copy Markdown
Contributor Author

/ok to test 1962337

@pthombre
pthombre enabled stacked auto-merge November 22, 2026 23:27
@nemo-automation-bot
nemo-automation-bot Bot requested review from a team November 22, 2026 23:27
@github-actions

Copy link
Copy Markdown
Contributor

@pthombre
pthombre added this pull request to the merge queue Nov 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/45084680930

Merged via the queue into main with commit 51630ce Nov 22, 2026
82 of 85 checks passed
@pthombre
pthombre deleted the pranav/envckpt-8-hold-pause branch November 22, 2026 23:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:env-infra Shared environment framework, lifecycle, registry, scaffolding, and validation complexity:medium Single-domain change with interacting parts or a moderate review surface feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer ready-to-merge PR is approved, current, and waiting for final CI or merge risk:high Autobot PR risk: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants