Repository navigation
feat(swe): checkpoint the episode sessions of five more repository-task servers - #6763
Conversation
…sk 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]>
…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]>
|
/ok to test 0917b60 |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
SHIP WITH CARE
I reviewed all 21 changed files with four topic reviewers, including the five server migrations, shared restore logic, checkpoint test helper, callers and target-base compatibility. I found one validation-evidence RISK and no confirmed code defect.
RISK: add representative real rollout evidence
Could you add the representative real model smoke rollouts required by AGENTS.md? The PR’s rollout section still says “Not yet”. This changes task-sandbox ownership and checkpoint restoration across five training environments, including R2E-Gym, and changes stderr-based grading in three verifiers.
The new checkpoint helper uses fake snapshots and mocked grading. It checks bookkeeping, but cannot show that a real provider restores the repository and reconnects the agent successfully. This is a validation gap, not a reproduced provider failure.
The smallest correction is to attach representative model-rollout results for the migrated servers, including the planned OpenSandbox checkpoint → crash → restore continuation. Record the head, task IDs, agent/model/provider configuration, captured patch, verifier outcome and cleanup. Acceptance should show that resumed edits use the original diff base, verification grades the intended patch, and task/verifier sandboxes close. Preserve flat-row compatibility, saved-capture replay and provider-error masking. These are training environments, so I am not asking for a full reward profile; golden-patch checks alone do not replace the required model smoke.
Validation
- I relied on this head’s successful
Lint check,Unit tests / Test,Unit tests / Server suite, all four core shards, all eight server shards, sandbox tests and combined core coverage. I checked the workflow’s aggregation rules and job results.Build Gym container, changed-server tests and session-routing end-to-end were skipped, not passed. I did not rerun passing CI suites locally. - CPU probes ran in
766267172432.dkr.ecr.us-east-1.amazonaws.com/gym:cd1b05dcdf72d6101a3a2b8292608422f0f93eb7, the default-branch CI image because this head’s build was skipped. The completed probes passed:r2e-swe-gym-1/probe.pycovered mid-grading checkpoints, saved fallback replay and stderr parsing;internal-oml-1/probe.pycovered 11 failure, cleanup and golden-verification scenarios; the twoultra-checkpoint-kit-1/probe_*.pyprobes covered full generated-script stderr grading and capture-failure attribution. - My
network_restore_probe.pycomparison confirmed that head fixes restore withoutAgentNetworkConfigwhile preserving enabled-policy replacement.base-drift-compat-1/probe.pyexercised the five changed servers against the target base’s checkpoint implementation and passed snapshot/export, fork, saved-capture replay and cleanup with fake providers. This was not a materialized merge test.
Initial probe setup/import errors were corrected before the reported successful runs. No real provider/model rollout or GPU work ran during this review. All admitted checkouts still matched their assigned SHAs and were clean.
Review generated by codex. This was a full review. Request a full review with /review reset=true.
macandro96
left a comment
There was a problem hiding this comment.
Review covers patch-capture failure handling, test-output parsing, setup diagnostics, the pre-existing R2E diff-base bug, and the outstanding real-provider rollout evidence. The diff-base issue is pre-existing; the rollout-evidence requirement was also raised in the existing review.
| except Exception as exc: | ||
| return PatchCapture.static("", mode, "none"), f"Failed to extract model patch: {exc}" | ||
| error = f"Failed to extract model patch: {exc}" | ||
| return saved_capture(PatchCapture.static("", mode, "none"), error, False) |
There was a problem hiding this comment.
If the sandbox cannot capture the patch, we save an empty patch and grade it normally. Checkpoint restore then reuses that failed capture. This also applies to swe_gym. Please follow swemer_oml: distinguish provider failures from git failures, return an incomplete response, and mask the sample. Preserve and check the saved incomplete flag rather than discarding it. Add a test covering capture failure followed by checkpoint and restore.
There was a problem hiding this comment.
#6670 adds this rule to r2e_gym and swe_gym so i will leave it out for this PR.
| return f"""#!/bin/bash | ||
| # Test runners report on stderr as often as on stdout. One ordered stream keeps the graded region between the | ||
| # markers whole on every provider: E2B returns a command's stdout and stderr apart. | ||
| exec 2>&1 |
There was a problem hiding this comment.
Merging stderr into stdout can corrupt the test IDs used for grading. I reproduced this locally with 1,000 passing pytest tests, capture disabled (-s), and a background thread writing diagnostics to stderr: both the R2E-Gym and SWE-Gym parsers produced incorrect test IDs in all three repeats, while separate streams preserved the expected IDs. For example, a diagnostic became attached directly to the end of a PASSED test ID. PYTHONUNBUFFERED=1 also failed in all three repeats. Please preserve reliable test boundaries or use structured test results, and add a regression test. This reproduction covers r2e_gym and swe_gym; it does not establish the same failure for swemer_ultra.
There was a problem hiding this comment.
| result = await exec_idempotent( | ||
| sandbox, hide_from_agent_command(), what="r2e_gym: hiding the held-out tests", timeout_s=120 | ||
| ) | ||
| if result.return_code != 0: |
There was a problem hiding this comment.
Please check error_type as well as return_code, and include it in the exception, as _pristine_untracked_files does. When exec_idempotent exhausts its total deadline, it can return return_code=-1, error_type='timeout', and stderr=None. The current message then reports rc=-1: None, hiding why setup failed.
| async def test_checkpoints(monkeypatch, tmp_path, scenario): | ||
| # The patch is taken against the checkout's HEAD, which the seed does not record. | ||
| await _helpers["check_repo_task_checkpoints"]( | ||
| monkeypatch, tmp_path, "r2e_gym", "R2EGym", scenario, records_base_commit=False, base_commit="HEAD" |
There was a problem hiding this comment.
Pre-existing correctness issue: this test preserves capture against the current HEAD, which loses changes the agent already committed. I reproduced a committed fix producing an empty patch against HEAD and a nonempty patch against the starting SHA. Please record the starting commit during setup, preserve it in checkpoints, and capture against that SHA. Add a test where the agent commits its fix before verification. This can be tracked as a separate fix if it is outside this PR's scope.
| completed=True, resolved=True, patch_applied=True, test_results={}, test_output="ok", error=None | ||
| ) | ||
| grade = AsyncMock(return_value=passing) | ||
| monkeypatch.setattr(app, "run_verification", grade) |
There was a problem hiding this comment.
Before merging, please attach the planned golden-patch comparisons and an OpenSandbox checkpoint -> crash -> restore smoke test, including a representative model rollout as required by AGENTS.md. These fake-provider tests with mocked grading cannot establish that a real provider restores the repository and reconnects the agent. Confirm that edits survive, verification grades the intended patch, and task and grading sandboxes are cleaned up. The PR's rollout-evidence section still says these checks are pending. This requirement was also raised in the existing review.
…m 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]>
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]>
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]>
|
/ok to test fbf3f38 |
| # The fallback is saved with the session too, so a retry after the task sandbox stopped grades it again. | ||
| capture, extraction_error = await self.capture_task_sandbox_patch(session_id, capture_or_fallback) | ||
| # Saved as a JSON value, so a checkpoint can export it. | ||
| capture, extraction_error, _ = loaded_capture( |
There was a problem hiding this comment.
Please preserve #6670's capture-failure handling when rebasing this and swe_gym. Main now distinguishes a failed Git command from an incomplete capture, but this version saves incomplete=False for every failure and discards the loaded flag. Keep main's classification, pass the resulting flag to saved_capture, unpack it as capture_incomplete, and return the incomplete/masked response after cleanup when it is set. Otherwise resolving the conflict with this version would undo the merged fix and checkpoint replay would keep grading the empty patch. Please add a capture-failure -> checkpoint -> restore test that checks the reward and masking stay consistent.
| A server whose config has no ``AgentNetworkConfig`` puts no rule on its agent's sandbox. | ||
| """ | ||
| if self.config.enforce_agent_no_network: | ||
| if getattr(self.config, "enforce_agent_no_network", False): |
There was a problem hiding this comment.
#6670 has merged and adds AgentNetworkConfig to r2e_gym, swe_gym and swemer_ultra, so all five migrated servers now support agent network enforcement. When rebasing, please preserve those config bases, startup checks, and sandbox_provider_options(provider_config, for_agent=session_id is not None) on the SandboxSpec while keeping new_task_sandbox. Extend restore_applies_the_restoring_job_s_egress_rule to these three servers as well; the scenario already checks the initial policy and the restoring job's model host, so it would catch accidentally dropping either behavior during the merge. The getattr fallback here can also return to direct config access, and the explanation about those configs lacking AgentNetworkConfig should be updated.
Resolve the overlap with NVIDIA-NeMo#6670, keeping both changes: - r2e_gym and swe_gym keep NVIDIA-NeMo#6670's capture classification: a capture the sandbox could not run is masked, a git failure stays a measured 0. The flag is now saved with the capture, so a verify after a restore replies the same; a shared scenario checks that for all five servers. - r2e_gym, swe_gym and swemer_ultra keep NVIDIA-NeMo#6670's AgentNetworkConfig with new_task_sandbox. Their network tests make the task sandbox through new_task_sandbox, and their checkpoint tests check that a restore forks with the restoring job's egress rule. - Every repository-task server now has AgentNetworkConfig, so the restore reads enforce_agent_no_network directly again. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Zeyu Zhou <[email protected]>
|
/ok to test 7147143 |
macandro96
left a comment
There was a problem hiding this comment.
LGTM. Verified the capture-failure replay and network-enforcement integration fixes; 245 focused tests passed locally and CI is green. The documented recovery rollout and comparison results address the outstanding validation request.
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/46766964473 |
Brings in NVIDIA-NeMo#6763, whose shared checkpoint test helper the next commit uses. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Zeyu Zhou <[email protected]>
Scale-SWE's checkpoint tests repeated the scenarios NVIDIA-NeMo#6763's helper runs for every repository-task server (conformance, the seed's saved diff base, a restored verify, a capture the sandbox could not run, a fork capturing against the saved base, the agent's own /run, golden-patch restart_only and the restoring job's egress rule). Run the helper instead, and keep the Scale-SWE tests: grading in a fresh sandbox, the stored failure kind, a commit during grading or during the stop after capture, and the /run seed refusal. The helper's seed HEAD is now a full object name and its passing run prints the server's start marker, as Scale-SWE requires; the other servers accept both. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Zeyu Zhou <[email protected]>
…h checkpoints (NVIDIA-NeMo#6765) * feat(scale_swe): run episode sessions on the shared session base, with checkpoints scale_swe was the one SWE server with its own episode-session code on SimpleResourcesServer. It now runs on RepoTaskSessionResourcesServer and takes part in partial-rollout checkpoints like the other repository-task servers. Grading, the patch-capture failure semantics and the failure kinds are unchanged. - The base supplies the session record, lock, close fences, expiry and checkpoint export/restore. Overrides keep scale_swe's own behaviour where the base differs: a close claims the session before waiting for its lock, bounded stop waits that never cut a stop short, verifier sandboxes kept until their stop succeeds, a 503 for a retry after an attempt without a verdict, bounded shutdown, and the lenient untracked-file listing. - New for scale_swe: an episode session never closed expires after the sandbox's ttl_s; shutdown retries task sandboxes whose stop failed; an agent-run seed naming an episode session gets a 409. - The patch capture, failure kind included, is saved as a JSON value so a verify after a restore grades the same patch. - partner_if (a ScaleSWEResourcesServer subclass with its own sessions) declares restart_only and checkpoint_verify wait, keeping its behaviour. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Zeyu Zhou <[email protected]> * refactor(scale_swe): verify and close episode sessions with the shared base Scale-SWE kept its own verify and close on the session base. Use the base's, as the other repository-task servers do: - an identical retry gets the first verification back, masked or not; a verification that ended before it replied runs again on the patch it captured instead of answering 503; - a task sandbox that does not stop after the capture fails that verify, and the retry grades the captured patch; - a close waits for a seed or verify in progress instead of claiming the session first; - a verify after a close is masked as session_lost instead of refused with 409; - a /run verify that finds no task sandbox, such as a retry, is masked as session_lost instead of grading an empty patch. Grading, patch capture and the bounded sandbox stops are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Zeyu Zhou <[email protected]> * fix(scale_swe): fail the seed when the untracked-file listing fails Use the repository-task base's listing, as the other repository-task servers do: it retries a listing the provider refused and fails the seed when it still cannot run, instead of going on with an empty list that would count the image's own untracked files as the agent's patch. The grader's apply drops those files' sections, so rewards do not change. The episode, the /run seed and partner_if's seed are retried instead. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Zeyu Zhou <[email protected]> * docs(scale_swe): say a late verify after expiry is masked as session_lost Once the close retry window has passed, the expired session is forgotten and a verify is masked as session_lost, not session_expired. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Zeyu Zhou <[email protected]> * docs(scale_swe): leave checkpoint behavior out of the README The other repository-task servers document checkpoint behavior in code only. The README keeps the session behavior it documented before. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Zeyu Zhou <[email protected]> * docs(partner_if): give the real reason its verify is not replayable A restart_only server never holds up a checkpoint. It declares wait because its judge-graded verify is not safe to run again, so it must not inherit Scale-SWE's replay. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Zeyu Zhou <[email protected]> * test(scale_swe): cover the stop under the export lock and the /run seed refusal A commit that arrives while the task sandbox's stop after capture is running waits for it and snapshots nothing, and an agent's own /run seed cannot replace an episode session. Each test fails when its protection is removed. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Zeyu Zhou <[email protected]> * refactor(scale_swe): stop sandboxes and shut down as the shared session base does Scale-SWE waited a bounded time for each sandbox stop and left the stop running after the wait, and bounded its shutdown wait for a busy session. On the session base that stop collided with the base's own: a close that gave up let an identical seed replay a sandbox being deleted, shutdown started a second stop and closed the provider under the first, a checkpoint could snapshot a sandbox mid-deletion, and a slow verifier stop was waited for twice. Use the base's stop and shutdown, as the other repository-task servers do: each stop waits for the provider's own stop, and shutdown stops every sandbox the server holds, the cookie path's included. sandbox_stop_timeout_seconds still loads, with a warning, and is ignored. Each grading attempt's verifier sandbox still stays with the session until its stop succeeds. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Zeyu Zhou <[email protected]> * fix(partner_if): honor anti_cheat_required in the SWE seed SWEIFConfig inherits anti_cheat_required from Scale-SWE's config, but the seed called the scrub without it, so the setting did nothing. Pass it, so a required scrub that did not complete fails the seed and stops its sandbox. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Zeyu Zhou <[email protected]> * test(scale_swe): run the shared repository-task checkpoint scenarios Scale-SWE's checkpoint tests repeated the scenarios NVIDIA-NeMo#6763's helper runs for every repository-task server (conformance, the seed's saved diff base, a restored verify, a capture the sandbox could not run, a fork capturing against the saved base, the agent's own /run, golden-patch restart_only and the restoring job's egress rule). Run the helper instead, and keep the Scale-SWE tests: grading in a fresh sandbox, the stored failure kind, a commit during grading or during the stop after capture, and the /run seed refusal. The helper's seed HEAD is now a full object name and its passing run prints the server's start marker, as Scale-SWE requires; the other servers accept both. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Zeyu Zhou <[email protected]> * fix(scale_swe): seed an agent's /run under the session lock The /run seed took no session lock, so another seed for the same ID, such as a retry or an episode seed, could replace its sandbox during setup; a setup that then failed cleaned up the replacement's sandbox and saved state. Seed under the lock, as the other repository-task servers and every episode seed do: an overlapping seed waits until this one is done. A /run re-seed now also waits for a verification in progress on the same session. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Zeyu Zhou <[email protected]> * fix(scale_swe): stop the last grading sandbox once, when verify ends Scale-SWE stopped every grading attempt's sandbox, the last one included, and the shared verify wrapper stopped a sandbox whose stop had failed again before replying: a provider that hung on both delayed the reply by two stop timeouts. Stop an attempt's sandbox only when another attempt follows and leave the last one to the wrapper's single stop, as the other repository-task servers do. A sandbox whose stop fails stays with the session for close and shutdown. 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
Partial-rollout checkpointing for sandboxed SWE episodes (stack #5264–#5413) covers SWE-bench and the four repository-task servers of #5331. The Nemotron-4 post-training runs on Slurm need it for more of the SWE training mix. This PR brings five more servers onto it, with the same per-server change #5331 made:
swemer_oml,r2e_gym,swe_internal_v1,swe_gym,swemer_ultraSandboxSessionResourcesServertoRepoTaskSessionResourcesServer, addsRepoTaskSessionFieldsto its config and setstask_model.new_task_sandbox, so it runs on the provider the sessions share and is registered for checkpoints.swe_internal_v1keeps itsstart_with_setupsetup.saved_capture/loaded_capture, so a verify after a restore grades the saved patch. Golden-patch grading runsrestart_only.r2e_gym's removal of the held-out tests. A seed whose untracked-file listing fails now fails instead of continuing with an empty list (the wrong-patch case feat(swe): checkpoint the episode sessions of the repository-task servers #5331 fixed).swemer_ultrajoins the eval command's stderr to its stdout, so tests that report on stderr are graded on a provider that returns the two apart (E2B).swemer_omlandswe_internal_v1already route it into the graded region;r2e_gymandswe_gymrun pytest, which reports on stdout.r2e_gym's diff base: the seed records the commit the agent starts from and the patch is taken against it, so a fix the agent committed is captured. Before, the patch was taken against HEAD at verify and came out empty.r2e_gymandswe_gymkeep its capture rule (a capture the sandbox could not run is masked; a git exit stays a measured 0), now saved with the capture so a verify after a restore replies the same.r2e_gym,swe_gymandswemer_ultrakeep itsAgentNetworkConfigon the sandboxnew_task_sandboxstarts.Shared code:
resources_servers/swebench/repo_task_sessions.pychanges only its module docstring, which now describes the repository-task servers without listing them.Issue
No GitHub issue. Requested for the Nemotron-4 post-training environments marked for rollout checkpointing.
Validation
gym env testdoes, sinceget_global_config_dict()parsessys.argv): the five servers,swebench/tests/test_repo_task_sessions.py,swebench/tests/test_sandbox_session_checkpoints.py, and the suites ofswemer_v1,swemer_v2,swe_rebench,swe_next(they share the base): 937 passed, 0 failed.tests/helpers/swe_repo_task_checkpoints.pyand atest_checkpoints.pyper server (40 tests): the checkpoint conformance kit withverify_body, the saved diff base, a replayed verify after a restore, a capture the sandbox could not run, still masked after a restore, a fork capturing against the saved base commit, the agent's own/runwith a flat row, golden-patchrestart_only, and the egress rule after a restore (all five servers).pre-commit run --fileson the changed files: passed.Rollout evidence
Real model on OpenSandbox, AGA (Slurm job 2480319). Nemotron-3-Nano-30B-A3B on vLLM, OpenCode through
single_agent_turn, this PR atfbf3f3803dd(before the #6670 merge, which changes grading and egress rules but not the checkpoint path). Per server, up to 5 example rows: the first episode still running after at least 3 model calls and a change to the checkout was checkpointed, Gym was killed and restored, and the episode finished and was verified.r2e_gymswemer_omlswe_gymswemer_ultraswe_internal_v1Local, on Docker (stdout and stderr apart), no model, each row's golden patch standing in for the agent:
swe_gym4/5 on both (one image name has capitals that Docker refuses).docker commitsnapshot stand-in also ran checkpoint → crash → restore forswemer_omlandr2e_gym: verify completed, same patch.Compatibility
r2e_gymnow captures a fix the agent committed; before, such a rollout scored 0.checkpoint.state_dirand refuses to start without it; before, it ranrestart_only.🤖 Generated with Claude Code