Repository navigation
feat(swe): checkpoint the episode sessions of the repository-task servers - #5331
Conversation
d1901c1 to
90142af
Compare
1105fdf to
7ee8313
Compare
| raise AntiCheatSetupError(f"{instance_id}: anti-cheat setup raised: {error!r}") from error | ||
| print(f"[{log_prefix}] {instance_id}: anti-cheat setup raised (non-fatal)", format_exc(), file=sys.stderr) | ||
| return | ||
| if result.return_code == 0: |
There was a problem hiding this comment.
anti_cheat_required treats a zero exit as a finished scrub. anti_cheat_setup.sh exits 0 when it skips, and also when non_ancestor_left is not 0 (gc_rc is only printed). For swe_rebench, can the agent still be handed a history that contains the fix? Should a required scrub fail the seed in those cases?
There was a problem hiding this comment.
Yes, it could. A required scrub now reads the script's summary line, not only the exit code: it fails the seed when the command did not run to its end, when the script printed no summary or skipped the repository, when non_ancestor_left is not 0 (1f19022), and, as of ab8cfb0, when gc_rc is not 0. swe_rebench ships with anti_cheat_required: true. A scrub that is not required still reads the exit code alone.
| started = time() | ||
| try: | ||
| sandbox = await self._create_sandbox(body, files=files) | ||
| sandbox = await self.start_grading_sandbox(body, files) |
There was a problem hiding this comment.
The finally below stops this sandbox with an unshielded await, and except Exception does not catch cancellation, so a cancelled verify cancels the stop too. SWE-bench shields that stop. Should this server, and the same finally in scale_swe, swe_next, swemer_v1, and swemer_v2, do the same? A cancel inside start_grading_sandbox, before sandbox is assigned, also looks like it would miss the finally.
There was a problem hiding this comment.
After the rebase these four servers use main's verifier handling from SandboxSessionResourcesServer (resources_servers/swebench/sandbox_sessions.py), which this PR does not change. _create_sandbox records the grading sandbox in _verifier_sandboxes before it starts it, so a cancel inside the start does not lose the handle. The stop in the finally is still not shielded, but _stop_verifier_sandbox forgets the handle only after the stop returns, so a stop that a cancel interrupts is tried again by close, session expiry and shutdown. scale_swe keeps its own shielded stop. I have not added a test that cancels a verify in this PR.
7ee8313 to
4987302
Compare
4987302 to
679a601
Compare
679a601 to
d38da2d
Compare
4d24b91 to
4c2cd84
Compare
zyzhou5
left a comment
There was a problem hiding this comment.
Minor comments on PR description:
- The title still says "on the sandbox owner base", which the body says no longer exists.
- The shipped OpenSandbox config already returns one combined stream, so the stderr change matters only on providers that return stdout and stderr apart.
- "A capture that fails is no longer graded as an empty patch": a capture that git refuses still is.
…vers swe_rebench, swemer_v1, swemer_v2 and swe_next keep the seed and verify they have, and now derive from RepoTaskSessionResourcesServer (resources_servers/swebench/repo_task_sessions.py), a thin layer on CheckpointedSandboxSessionResourcesServer, so their episodes take part in partial-rollout checkpoints: the agent's sandbox is snapshotted with its work and forked on a restore. - The agent's sandbox is created with new_task_sandbox, on the provider every session shares; grading sandboxes stay on a provider of their own and are not session state. - The files the checkout held untracked before the agent started, and the commit the patch is taken against where the seed records one (swemer_v1, swemer_v2, swe_next), are exported and restored with the session. - The captured patch is saved as a JSON value (saved_capture / loaded_capture), with its extraction error and whether the sandbox could not run the capture, so a commit can store it and a /verify after a restore grades the saved patch. checkpoint_verify = "replay". - Golden-patch servers run restart_only. - swe_next's allowed_agents adds opencode_agent. scale_swe keeps its own episode-session implementation. Signed-off-by: Pranav Thombre <[email protected]> Co-Authored-By: Claude Fable 5.2 <[email protected]>
The swe_rebench, scale_swe, swemer_v1, swemer_v2 and swe_next graders parse only the region between their start and end markers, from the command's stdout followed by its stderr. A provider that returns a command's stdout and stderr apart (E2B) puts every line a test runner writes on stderr after the end marker, so tests that report there (jest does) grade as missing. Each eval script now sends its stderr to stdout, in order, before anything runs. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]>
…po-task server require it On AgentENV at 16-node scale, 16 scrubs per run hit a gateway 502 after the sandbox had answered; the best-effort scrub then handed the agent a git history that still held the task's fix. The scrub and the committer-identity step are idempotent and are now retried on a provider error (3 attempts, 2 s then 4 s) for every server that calls them. A repo-task server (swe_rebench, swemer_v1, swemer_v2, swe_next) with `anti_cheat_required` raises AntiCheatSetupError instead of continuing past a scrub that did not complete, so the seed fails and the rollout is retried; swe_rebench's resources config turns it on. The repo-task servers also take `agent_network_policy`: a provider-neutral egress rule applied to the agent's sandbox only (grading sandboxes keep the spec's network). It is recorded with the sandbox, so a restore's fork gets the same rule; an address range stays valid across jobs. Signed-off-by: Pranav Thombre <[email protected]> Co-Authored-By: Claude Fable 5.2 <[email protected]>
…istine files cannot be listed A sandbox that was just created or restored can refuse a connection for a few seconds (a gateway 502). The repository-task seed's `git rev-parse HEAD` then failed the seed, and the pristine untracked-file listing silently became empty (job 8539361: 6 sandboxes). An empty list makes the patch capture count the image's own untracked files as the agent's new files, so the rollout could be graded on a wrong patch instead of being retried. Both reads are read-only and now go through `exec_idempotent`. The listing moves from each server into RepoTaskSessionResourcesServer. A listing that still cannot run, or that the provider interrupted, fails the seed, so the row is dispatched again; a listing that runs and fails (the workdir is not a git repository) still gives the empty set with a warning. Signed-off-by: Pranav Thombre <[email protected]> Co-Authored-By: Claude Fable 5.2 <[email protected]>
… pristine files git refuses to list, and retry the first commands Found in a review of the repository-task servers' checkpoints and hardening. - The agent sandbox's egress rule is main's `AgentNetworkConfig` (`enforce_agent_no_network`, `sandbox_model_server`), which refuses a provider that cannot enforce it. This PR's own `agent_network_policy` field is gone. The rule is recorded with the sandbox, so the fork a restore makes keeps the rule of the job that seeded it; the module docstring says so. - `anti_cheat_required` only read the scrub's exit code, and `anti_cheat_setup.sh` exits 0 when it skipped the repository and when refs still reach commits after the base. A required scrub now also fails when the command was not run to its end, when the script printed no summary, when it skipped, and when it counted commits that are no ancestor of the base. A `git gc` that failed after the refs were removed is logged, since no name reaches those commits; it is tried again only when an earlier attempt raised, because that attempt's gc may still be running. A scrub that is not required reads the exit code alone, as before. - A listing of the pristine untracked files that git refuses now fails the seed, like one the provider could not run. It used to give the empty set, and the patch capture then counted the image's own untracked files as the agent's. - The commands that really run first in a new sandbox are retried when the provider raises: swe_next's link of the workdir and its removal of the grading artifacts, and the swemer servers' check for a repository. A check the provider reports as not run now fails the seed instead of reading as "no repository", which initialised a new one on top of a repository that may exist. - Tests: a restore keeps the outcome of a capture that failed (git refused it, or the sandbox could not run it); a seed that reads no base commit fails and stops its sandbox; the committer-identity retry; the shipped swe_rebench configs require the scrub. The eval-script tests run in a temporary directory and refuse to run anything but the script's redirect, so a reworded script can no longer run a real checkout reset where pytest was started. The commit-during-grading test bounds its waits, and no anti-cheat test waits for the retry delay any more. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]>
… the seed's first commands, and fork a restored sandbox with the restoring job's egress rule Review of #5331: - A required anti-cheat scrub now also raises when the refs are gone but `git gc` did not prune (`non_ancestor_left=0 gc_rc!=0`). The commits no name reaches are still objects in `.git`, so the agent could list and read the fix. A scrub that is not required stays best effort. A test runs the shipped script against a repository whose gc fails and shows the fix commit is still readable. - The commands a seed runs with `exec_idempotent` (the pristine-file listing, the base-commit read, the repository check, swe_next's workdir link and removal of grading artifacts) get a 180 s budget. Without `timeout_s`, `exec_idempotent` passes no limit to `sandbox.exec`, whose own default these commands had before. - With `enforce_agent_no_network`, a restore forks each agent sandbox with the egress rule of the job that restores it. The saved rule allows the model server host of the job that took the checkpoint, which a job resubmitted on other nodes no longer serves from. After the rebase onto main: main's `exec_idempotent` passes `cwd` and `env` and bounds its attempts with `asyncio.timeout`, so the swe_next test sandboxes accept those arguments and the retry tests keep the real `asyncio.timeout` while they replace the wait. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Pranav Thombre <[email protected]>
4c2cd84 to
ab8cfb0
Compare
|
Rebased onto @zyzhou5, description notes: all three are corrected.
CI review, RISK "validate the current seed and verifier behavior with real rollouts": not done. No live sandbox or real-model run has been made on this head, and the description says so under Validation. What ran on The other RISK, a required scrub that accepts unpruned history, is fixed in |
|
/ok to test ab8cfb0 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/44962878425 |
…sk servers (NVIDIA-NeMo#6763) * feat(swe): checkpoint the episode sessions of five more repository-task servers swemer_oml, r2e_gym, swe_internal_v1, swe_gym and swemer_ultra move onto RepoTaskSessionResourcesServer, as NVIDIA-NeMo#5331 did for swe_rebench, swemer_v1, swemer_v2 and swe_next: a commit snapshots the agent's task sandbox with the files the checkout held untracked before the agent started (and the base commit where the server records one), a restore continues the episode in a fork, and a verify after the restore grades the saved patch. Golden-patch grading runs restart_only. - Each server starts its task sandbox with new_task_sandbox, drops its own pristine-untracked and base-commit maps for the base's, and saves its capture with saved_capture / loaded_capture. - Setup reads of a new sandbox (HEAD, the repository check, r2e_gym's removal of the held-out tests) are retried, as in NVIDIA-NeMo#5331's servers. A seed whose untracked-file listing fails now fails instead of continuing with none. - r2e_gym, swe_gym and swemer_ultra join the eval command's stderr to its stdout, so tests that report on stderr are graded on a provider that returns the two apart. - repo_task_sessions: a restore re-applies the agent egress rule only for a config that has one; r2e_gym, swe_gym and swemer_ultra have no AgentNetworkConfig. - Tests: a shared helper (tests/helpers/swe_repo_task_checkpoints.py) and a test_checkpoints.py per server, including the checkpoint conformance kit with verify_body. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Zeyu Zhou <[email protected]> * docs(swebench): describe the repository-task servers without listing them The module now serves nine servers, and three of them have no agent egress rule. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Zeyu Zhou <[email protected]> * revert(swe): keep the eval scripts' stdout and stderr apart in r2e_gym and swe_gym r2e_gym and swe_gym run pytest, which prints its results on stdout next to the markers, so a provider that returns the streams apart already grades them. Joining stderr into stdout let a stderr write land inside a test result line and corrupt its test ID, and checkpointing does not need it. swemer_ultra keeps the join: some of its test runners report on stderr. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Zeyu Zhou <[email protected]> * fix(r2e_gym): say why removing the held-out tests failed A command the provider ended without an exit status, such as one that ran out of time, has no stderr either, so the error read "rc=-1: None". Fail on its error_type too and name it, as the untracked-file listing does. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Zeyu Zhou <[email protected]> * fix(r2e_gym): take the agent's patch against the commit it started from The patch was taken against HEAD at verify, so a fix the agent committed moved HEAD and the patch came out empty. The seed now records the starting commit, as the other repository-task servers do, and a checkpoint keeps it with the session. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Zeyu Zhou <[email protected]> --------- Signed-off-by: Zeyu Zhou <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
What changed and why
The stack makes SWE-bench Verified checkpointable (#5267), but the SWE training blend runs on other resources servers. This PR lets a checkpoint export the episode sessions of
swe_rebench,swemer_v1,swemer_v2andswe_next.mainhas since done most of what earlier versions of this PR did. #4304 putswe_rebench,swemer_v1andswemer_v2onSandboxSessionResourcesServerwith typed episode sessions, #5112 did the same forswe_next, and #6177 added the block on egress from the agent's sandbox. This PR is now a thin layer on those servers asmainhas them (their session tests frommainpass), the way #5267 is for SWE-bench.Checkpoints (first commit)
The four servers derive from
RepoTaskSessionResourcesServer(resources_servers/swebench/repo_task_sessions.py, about 120 lines), a thin layer onCheckpointedSandboxSessionResourcesServer(#5266). Each server changes by a few dozen lines.new_task_sandbox, on the provider every session shares; grading sandboxes stay on a provider of their own and are not session state.swemer_v1,swemer_v2,swe_next), are exported and restored with the session./verifyafter a restore grades the saved outcome.checkpoint_verify = "replay".restart_only.swe_next'sallowed_agentsaddsopencode_agent.scale_sweis not included. It keeps its own episode-session implementation, and its episodes start over after a crash (restart_only). Of the changes below it gets the eval stderr fix and the scrub retries.Eval output (second commit)
The graders parse only the region between their start and end markers. Each eval script of the four servers and of
scale_swenow sends its stderr to its stdout, in order, before anything runs, so on a provider that returns the two streams apart (E2B and AgentENV) test output is graded inside the region. This changes the graded text only on such providers: the shipped OpenSandbox config already returns one combined stream.Scrub hardening (third and last commits)
anti_cheat_required(repo-task servers; on inswe_rebench_legacy_agent.yaml, whichswe_rebench.yamlincludes): a scrub that did not complete raises, the seed fails, and the rollout is retried. "Did not complete" is more than a non-zero exit code, because the scrub script exits 0 when it skipped the repository and when refs still reach commits after the base: a required scrub also fails when the command was not run to its end, when the script printed no summary, when it skipped, when it counted commits that are no ancestor of the base, and whengit gcfailed after the refs were removed (the unpruned commits are still objects the agent can list and read). A scrub that is not required reads the exit code alone, as before.main's (enforce_agent_no_network,sandbox_model_server, feat(swe): block egress from the agent's sandbox in the SWE servers #6177) is the only one; theagent_network_policyfield of earlier versions of this PR is gone. The rule allows the model server host of the job that created the sandbox and is saved with it, so a restore forks each agent sandbox with the rule of the job that restores it: a job resubmitted on other nodes serves its model from another host.First commands on a new sandbox (fourth and last commits)
A sandbox that was just created or restored can refuse a connection for a few seconds.
swe_next's link of the workdir and its removal of the grading artifacts, and the swemer servers' check for a repository go throughexec_idempotent, each with a 180 s budget (whatsandbox.execallows one command by default;exec_idempotentsets no limit of its own).How it works
Where this PR sits in the overall flow
The highlighted part is 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/>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 servers<br/>SWE-bench, and now swe_rebench,<br/>swemer_v1, swemer_v2, swe_next"] 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:khaki,stroke:darkgoldenrod,stroke-width:2px,color:black class R thisThis PR
flowchart TD T["Episode seed from the Environment Server,<br/>or a flat seed from an agent's own run"] --> SU SU["Start the task sandbox through new_task_sandbox,<br/>prepare the repository (first commands retried),<br/>scrub (retried; required on swe_rebench),<br/>keep the base commit and pristine untracked files"] SU -- "a step cannot run or is refused" --> X["seed fails, sandbox stopped,<br/>the caller retries"] SU --> W["Agent works in the lent sandbox<br/>a checkpoint snapshots it and exports<br/>the base commit and pristine files"] W --> VE["verify"] --> CO{"Capture already saved?"} CO -- "yes (replay, or after a restore)" --> G CO -- "no" --> CA["Capture the patch against the base commit,<br/>drop pristine untracked files,<br/>save the outcome, stop the agent's sandbox"] CA -- "patch" --> G["Grade in fresh sandboxes,<br/>inconclusive runs retried as on main"] CA -- "the sandbox could not run the capture" --> M["masked, incomplete verdict (main's rule)"]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, #5266, #5268 and #5269 have merged, and this PR is rebased onto
mainafter them (4bbd832940). 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 extends the environment-server checkpoint plan from SWE-bench Verified to four servers of the SWE training blend, so a training run can checkpoint them.
Validation
Head
ab8cfb0f0e, onmain4bbd832940(Slurm job 9236333,rl-gymCI container, one node): import-linter clean;ruff checkandruff format --diffclean on the changed files; the suites ofswebench,swe_rebench,swe_next,swemer_v1,swemer_v2,scale_sweandopencode_agent, andtests/unit_tests/agentsandtests/unit_tests/server_runtime: 4884 passed, 26 skipped, 6 failed, 1 collection error. The 6 failures and the error are the same test ids that fail in that container on #5269's tree before this PR (job 9233804):test_outcome_policy.py::test_upload_evidence_roundtrips_in_reports_and_process_projection(3),test_sandbox_supervisor_bootstrap.py::test_fenced_delayed_launch_does_not_require_bash(2),test_task_container_sessions.py::test_resolved_root_workdir_check[False], andtest_review_boundary_interfaces.py(collection).tests/e2e/checkpointwithNEMO_GYM_CHECKPOINT_E2E=1: 67 passed, 14 skipped. Tests added on this head: a required scrub whose gc failed raises, and the shipped script run against a repository whose gc fails leaves the fix commit readable; the seed's first commands carry the 180 s budget; a restore underenforce_agent_no_networkforks with the restoring job's rule. Not run on this head: the whole core suite,pre-commit run --all-files, any live sandbox or real-model run.The rest of this section is from earlier heads and was not repeated.
Head
4d24b91c8e, on #52697c249d2c94. 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.anti_cheat_requiredrule; the shippedswe_rebenchconfigs require the scrub; the retried first commands.main's agent-network tests for the four servers pass with the session's sandbox coming fromnew_task_sandbox./verify(verify_body) is not used. The kit compares whole replies, and these servers' replies carry timings and sandbox IDs, so it needs a change in the kit first.anti_cheat_requiredon (the stricter rule needs the scrub's summary line to reach stdout there);enforce_agent_no_networktogether with a restore on a live provider (covered by a unit test on a fake provider only).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.Follow-ups, not in this PR:
anti_cheat_requiredforswemer_v1,swemer_v2andswe_next.scale_sweon the checkpoint layer.verify_bodycheck for these servers (see Validation).Compatibility
Versus
main:swe_rebench,swemer_v1,swemer_v2,swe_nextwithout checkpoints: the same seed, patch capture, grading and close. The agent's sandbox now runs on the provider the server's sessions share.swe_next:allowed_agentsaddsopencode_agent.swe_rebench:anti_cheat_requiredis on in the shipped configs, so a seed whose scrub did not complete, or did not prune, fails and is retried.scale_swe: sessions unchanged; with checkpointing on, its episodes start over after a crash.checkpoint.state_dirwhen their provider can snapshot.Versus earlier versions of this PR:
swe_next's episode sessions aremain's (feat(swe): support SWE-Next episode sessions #5112); this PR's own commit for them is dropped.agent_network_policyand theapplies_network_policystartup check are gone;main's egress block (feat(swe): block egress from the agent's sandbox in the SWE servers #6177) replaces them.main's seed has none).opencode_agentis not added toswe_rebench,swemer_v1orswemer_v2here:main's default configs already pair them with it.🤖 Generated with Claude Code