Repository navigation
test(checkpoint): end-to-end harness scenarios, SWE-bench recipe, docs - #5269
Conversation
04afe42 to
9369e25
Compare
060c6a6 to
f6a9791
Compare
f6a9791 to
e90468f
Compare
803a0cc to
548d212
Compare
548d212 to
86e43ff
Compare
macandro96
left a comment
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
7c249d2 to
edb3082
Compare
|
/ok to test a4c254c |
a4c254c to
3a03227
Compare
|
/ok to test 3a03227 |
- 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]>
3a03227 to
a0a5ec2
Compare
|
/ok to test a0a5ec2 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/44951280453 |
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:invoke_agent, then restoreclose_agent; after the restore no call runs againrestart_only; commits succeed; the replacement starts over in a new sandbox and passesThe commit-and-resume and crash scenarios run through both
single_agent_turnandsingle_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.Recipe:
mainnow ships the OpenCode and SWE-bench Verified pairing asbenchmarks/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 tomain's file a comment block on what checkpointing needs (a provider that can snapshot, and onecheckpoint.state_dirper job on a filesystem every restart reads), and raises the sandbox lifetime fromttl_s: 25200to28800, 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, whatreplayrequires of/verify,check_sandbox_session_checkpoints), "Make a Harness Checkpointable" (capability tiers, pause in place,Activation.slot, resume after a crash,check_harness_adapter), thecheckpointblock and thesandbox_checkpointsettings 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 --> DThis 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 --- LWhere 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
mainafter them. Each PR is based on the one before it, so each diff shows only that PR's change. 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
7c249d2c94, on #5268dd86bc238b. 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.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
benchmarks/swebench/verified/opencode.yaml:ttl_sgoes from 25200 to 28800.NEMO_GYM_CHECKPOINT_E2E=1, as the existing process-level checkpoint suite is.🤖 Generated with Claude Code