Skip to content

test(checkpoint): end-to-end harness scenarios, SWE-bench recipe, docs - #5269

Merged
pthombre merged 6 commits into
mainfrom
pranav/envckpt-5-e2e-docs
Nov 21, 2026
Merged

pthombre merged 6 commits into
mainfrom
pranav/envckpt-5-e2e-docs

Conversation

@pthombre

@pthombre pthombre commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

What changed and why

The earlier PRs each test their own piece with fakes. This PR shows the pieces compose across real Gym processes, the real bash process supervisor and real signals, and documents how a resources server or a harness adopts them. It changes no product code; its one config change is the recipe's sandbox lifetime.

  • End-to-end harness scenarios, skipped unless NEMO_GYM_CHECKPOINT_E2E=1, like the rest of the process-level suite:

    Scenario Pass when
    Commit, then resume, while the harness runs Paused in place, no relaunch, the episode finishes with reward 1
    The pause fails Stopped, relaunched once after resume, the episode finishes
    Crash at invoke_agent, then restore One fork of the snapshot, both sessions re-seeded, the harness continues in the fork and makes only the missing calls
    The harness finishes as the park arrives, then a crash The checkpoint lands at close_agent; after the restore no call runs again
    Crash during verify, after the capture Only the session's data is exported (no snapshot); grading runs again and passes; no call and no sandbox after the capture
    Two checkpoints, then release Both pauses were in place; releasing the older checkpoint deletes its snapshot; releasing everything deletes the rest
    A provider without snapshots The resources server reports restart_only; commits succeed; the replacement starts over in a new sandbox and passes
    A checkpoint of a restored episode, the older checkpoint released, a second crash and restore Each restore forks its own checkpoint's snapshot; the episode finishes with reward 1
    A second crash before the replacement attempt starts The restored sessions nobody has claimed are checkpointed and restored again; the episode finishes in a fork

    The commit-and-resume and crash scenarios run through both single_agent_turn and single_agent_turn_legacy. The last two scenarios are new in this revision and found no product defect.

  • Test components: a fake harness agent that borrows the task sandbox and runs a small harness under the real supervisor with run_until_parked; a workspace resources server on the checkpointing session base (feat(swebench): checkpoint the task sandboxes of episode sessions #5266) that grades what its verify captured once; and a local-directory sandbox provider, with and without snapshots, where a snapshot is a copy and a fork keeps the same path.

    • A deployment's teardown kills what its local sandboxes still run, so a test that fails between a prepare and its resume leaves no paused harness on the machine, and prints the server logs.
    • The local provider forks whatever is at the snapshot's path (running or stopped), leaves fifos and sockets out of a snapshot, and leaves no half-written snapshot behind.
    • Control deadlines default to 90 s (a pause may take 45 s to confirm); waits are bounded and no test sleeps a fixed time.
  • Recipe: main now ships the OpenCode and SWE-bench Verified pairing as benchmarks/swebench/verified/opencode.yaml (feat(swe): run the SWE OpenCode configs through single_agent_turn and keep the relay configs as *_legacy_agent #5762), so this PR no longer adds a recipe file of its own. It adds to main's file a comment block on what checkpointing needs (a provider that can snapshot, and one checkpoint.state_dir per job on a filesystem every restart reads), and raises the sandbox lifetime from ttl_s: 25200 to 28800, so the sandbox outlives the episode timeout plus the pause allowance. A unit test resolves the recipe.

  • Docs: "Make a Resources Server Checkpointable" (CheckpointedSandboxSessionResourcesServer, new_task_sandbox, task state, checkpoint_mode = "restart_only" for a server whose grader needs what a snapshot does not keep, what replay requires of /verify, check_sandbox_session_checkpoints), "Make a Harness Checkpointable" (capability tiers, pause in place, Activation.slot, resume after a crash, check_harness_adapter), the checkpoint block and the sandbox_checkpoint settings in the configuration reference, and a checkpoints section in the OpenCode agent's README (metadata.harness_launches, which sessions restart). Samples import from the public API and check their exec results.

The fake harness and e2e infrastructure build on #4222 and #4221 in the legacy stack, rewritten as an Environment Server session agent.

How it works

Where this PR sits in the overall flow

This PR adds no component. The e2e deploys every box below as a real process, with the fake harness agent in place of OpenCode, the workspace server in place of SWE-bench, and local directories in place of OpenSandbox.

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_until_parked, re-bind, resume"]
  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
Loading

This PR

The e2e deployment of one scenario. Every box is its own process.

flowchart LR
  T["Test scenario<br/>drives runs and coordination"]
  E["single_agent_turn<br/>or single_agent_turn_legacy"]
  A["Fake harness agent<br/>run_until_parked"]
  R["Workspace server<br/>session base with checkpoints"]
  M["Policy model server"]
  B["Fake model backend<br/>hold, release, call log"]
  L[("Local directory sandboxes<br/>snapshots are copies")]
  H["Small harness under<br/>the process supervisor"]
  T --> E
  T -. "prepare, commit, resume,<br/>restore, release" .-> E & A & R & M
  E --> R & A
  R --> L
  A --> H
  H --> M --> B
  H --- L
Loading

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, #5265 and #5266 have merged, and the rest of the stack is rebased onto main after them. Each PR is based on the one before it, so each diff shows only that PR's change. The stack runs parallel to the legacy_agent path of #4220 to #4936, which it does not change or depend on.

  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 (this PR)
  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
  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. 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 7c249d2c94, on #5268 dd86bc238b. 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.
  • Not done: a scenario with several episodes checkpointed together; the rewritten tutorial samples were read, not executed.
  • Real-model evidence is tracked on the OpenCode PR. The recipe has not been run against OpenSandbox on this head.
  • Not run: pre-commit run --all-files; any live sandbox, real-model or training run on this head.
  • 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

  • Tests, docs and a recipe change only; no product code changes.
  • benchmarks/swebench/verified/opencode.yaml: ttl_s goes from 25200 to 28800.
  • The new e2e scenarios are skipped unless NEMO_GYM_CHECKPOINT_E2E=1, as the existing process-level checkpoint suite is.

🤖 Generated with Claude Code

@copy-pr-bot

copy-pr-bot Bot commented Oct 29, 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 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 29, 2026
@pthombre
pthombre added this pull request to stack #5270 October 29, 2026 05:56
@pthombre
pthombre force-pushed the pranav/envckpt-5-e2e-docs branch 2 times, most recently from 04afe42 to 9369e25 Compare October 31, 2026 18:07
@pthombre
pthombre force-pushed the pranav/envckpt-5-e2e-docs branch 2 times, most recently from 060c6a6 to f6a9791 Compare November 3, 2026 06:40
@pthombre
pthombre force-pushed the pranav/envckpt-5-e2e-docs branch from f6a9791 to e90468f 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-5-e2e-docs branch 2 times, most recently from 803a0cc to 548d212 Compare November 14, 2026 09:59
@pthombre
pthombre force-pushed the pranav/envckpt-5-e2e-docs branch from 548d212 to 86e43ff Compare November 16, 2026 21:44

@macandro96 macandro96 left a comment

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.

mostly lgtm; minor stuff

# A snapshot without meta.json is listed by nothing, so nothing would delete it.
shutil.rmtree(directory, ignore_errors=True)
raise
(directory / "meta.json").write_text(

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.

NOTE: Publish snapshot metadata atomically.

meta.json is written directly to its published path, while list_snapshots() reads and parses that path without handling incomplete JSON. With a concurrent reader forced between creation and completion of the write, listing raises JSONDecodeError.

Could this write to a temporary file and atomically replace meta.json, as _save() already does for box metadata? This is a hardening suggestion; I have not demonstrated that the existing scenarios perform this overlapping read.

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 a4c254c: snapshot() writes meta.json.tmp and renames it into place, as _save() does for the sandbox records, so list_snapshots() and wait_snapshot_ready() never see a half-written file.

box = self._box(handle.sandbox_id)
except RuntimeError:
return
kill_sandbox_processes(handle.sandbox_id)

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.

NOTE: Move process scanning off the event loop.

close() and create_from_snapshot() call kill_sandbox_processes() synchronously. That function scans /proc repeatedly and uses time.sleep, preventing other coroutines in the server from progressing during cleanup. A diagnostic with injected scan latency confirmed that an already-scheduled event-loop callback could not run until close() returned.

Could both calls use await asyncio.to_thread(kill_sandbox_processes, sandbox_id)? This preserves cleanup ordering while allowing other requests to progress.

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 a4c254c: close() and create_from_snapshot() now call kill_sandbox_processes through asyncio.to_thread.

Two things followed from the await this adds:

  • Both methods read the sandbox record again after the scan, with no await before the save, so a close and a fork of the same sandbox do not save over what the other changed meanwhile.
  • E10 failed every time with the scan off the loop. A restore stops the sandbox it replaced in a background task; that used to finish in one step of the event loop, and now takes real time, so E10's immediate second crash killed the server before the sandbox was recorded as stopped. E10 now waits (bounded, 60 s) for that stop before its second checkpoint. This changes the scenario, not the product: a crash that races the background stop still leaves the replaced sandbox running, which is the documented best-effort behaviour.

Validation on this change (Slurm job 9222537, NEMO_GYM_CHECKPOINT_E2E=1): the harness scenarios passed 11 of 11 in three consecutive passes, and the whole tests/e2e/checkpoint directory was 67 passed, 14 skipped.

@pthombre
pthombre force-pushed the pranav/envckpt-5-e2e-docs branch from 7c249d2 to edb3082 Compare November 21, 2026 07:02
@pthombre

Copy link
Copy Markdown
Contributor Author

/ok to test a4c254c

@nemo-automation-bot
nemo-automation-bot Bot requested review from a team November 21, 2026 08:20
@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

macandro96
macandro96 previously approved these changes Nov 21, 2026
@pthombre

Copy link
Copy Markdown
Contributor Author

/ok to test 3a03227

@pthombre
pthombre requested a review from macandro96 November 21, 2026 20:27
Base automatically changed from pranav/envckpt-4-opencode to main November 21, 2026 20:41
pthombre and others added 6 commits November 21, 2026 12:41
- tests/e2e/checkpoint: a fake harness agent that borrows the task sandbox and runs a python harness under the
  real process supervisor with run_until_parked; a workspace server on CheckpointedSandboxSessionResourcesServer; and local
  sandboxes (directories whose snapshots fork with the same paths, with or without snapshot support). Scenarios
  E1-E8: pause in place, the stop fallback and relaunch, a crash at invoke_agent, close_agent and verify then a
  restore, a harness that finishes as the park arrives, release, and a provider without snapshots. E1 and E3
  run through both single_agent_turn and single_agent_turn_legacy.
- benchmarks/swebench/verified/opencode_sessions.yaml: OpenCode on SWE-bench Verified through
  single_agent_turn_legacy, on OpenSandbox, with checkpoint.state_dir.
- Docs: "Make a resources server checkpointable", "Make a harness checkpointable", and a checkpoint section in
  the opencode_agent README.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Pranav Thombre <[email protected]>
…ugh create_from_snapshot

The local_dir provider forked a snapshot through `create` with `provider_options["snapshot_id"]`, the convention
#5265's protocol replaced. It now implements `create_from_snapshot` and raises `SandboxSnapshotNotFoundError` for
a snapshot it does not have.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Pranav Thombre <[email protected]>
…apshotInfo, and name the moved conformance kits in the docs

Follow the sandbox snapshot contract the stack is now based on.

- The local e2e provider returns SandboxSnapshotInfo from list_snapshots.
- The resources server tutorial names state_dir_id, which replaced run_id, and imports
  check_sandbox_session_checkpoints from resources_servers.swebench.testing.
- The harness tutorial imports check_harness_adapter from nemo_gym.server_runtime.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: Pranav Thombre <[email protected]>
…ode sessions restart

- Only a server that exports its sessions refuses to start without a `state_dir`: a golden-patch server, or one on
  a provider that cannot snapshot, starts.
- OpenCode's README lists sessions that continue an imported conversation among those that restart after a crash.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: Pranav Thombre <[email protected]>
… scenarios, correct the recipe and docs

Found in a review of the end-to-end harness scenarios, the SWE-bench recipe and the docs.

End-to-end infrastructure:
- A deployment's teardown kills what its local-directory sandboxes still run. A harness a checkpoint paused waits
  for its continue for ever and outlives the servers, so a test that failed between a prepare and its resume left
  it on the machine.
- The local provider forks a snapshot whatever is at the snapshot's path, running or stopped; before, a restore
  after the source sandbox had stopped failed with FileExistsError. A snapshot leaves out fifos, sockets and files
  that went away, and a copy that fails leaves no half-written snapshot. The tree copies run off the event loop.
  `wait_snapshot_ready` raises SandboxSnapshotNotFoundError, as the provider contract says.
- The fake harness agent fails an activation whose harness died instead of reporting it completed, starts a failed
  activation again at its retry, counts an injected pause failure when it installs it, uploads its harness with
  `upload_text`, and releases the sandbox connection when the install fails.
- The workspace server raises when the notes cannot be read instead of capturing empty notes.
- Control deadlines default to 90 s (a pause may take 45 s to confirm) and the server logs are printed at teardown.

Scenarios:
- E5 shows the episode continued (no call and no sandbox after the capture) and waits with a deadline; its
  grading outlasts the checkpoint on a busy machine. E7 waits for the releases instead of sleeping and shows
  both pauses were in place. E8 shows the replacement started over in a new sandbox. E3 cannot pass on an empty set.
- E9: a checkpoint of a restored episode, the older checkpoint released, a second crash and restore.
- E10: a second crash before the replacement attempt starts, with restored sessions nothing has claimed yet.

Recipe: the sandbox outlives the episode and its pause allowance (`ttl_s: 28800`); the `timeout` comment
described another setting; OpenCode needs no "no tool grants" condition; one `state_dir` per job. A test resolves it.

Docs: samples import from the public API and check their exec results; `Activation.slot`; what `replay` requires
of `/verify`; the `checkpoint` block and the `sandbox_checkpoint` settings; `metadata.harness_launches`; one
`state_dir` per job; cross-links between the two pages.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: Pranav Thombre <[email protected]>
…and harden the local e2e sandbox provider

E1 reads the state of the harness process between the commit and the resume: the backend holds the
harness's model call, so the reward and the call and launch counts alone would pass with a pause that
sent no signal.

The local sandbox provider renames a snapshot's meta.json into place, so a listing never reads a
half-written file, and scans /proc for a sandbox's processes off the event loop. A close and a fork
read the sandbox's record again after the scan, so neither saves what the other changed meanwhile.

With the scan off the event loop, stopping a superseded sandbox no longer completes in one step of
the loop, so E10 waits for it before its second crash.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: Pranav Thombre <[email protected]>
@pthombre
pthombre force-pushed the pranav/envckpt-5-e2e-docs branch from 3a03227 to a0a5ec2 Compare November 21, 2026 20:41
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the ready-to-merge PR is approved, current, and waiting for final CI or merge label Nov 21, 2026
@pthombre

Copy link
Copy Markdown
Contributor Author

/ok to test a0a5ec2

@pthombre
pthombre enabled stacked auto-merge November 21, 2026 21:08
@pthombre
pthombre added this pull request to the merge queue Nov 21, 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/44951280453

Merged via the queue into main with commit 4bbd832 Nov 21, 2026
71 checks passed
@pthombre
pthombre deleted the pranav/envckpt-5-e2e-docs branch November 21, 2026 21:38
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