Skip to content

feat(swe): checkpoint the episode sessions of the repository-task servers - #5331

Merged
pthombre merged 6 commits into
mainfrom
pranav/envckpt-6-repo-task-servers
Nov 21, 2026
Merged

pthombre merged 6 commits into
mainfrom
pranav/envckpt-6-repo-task-servers

Conversation

@pthombre

@pthombre pthombre commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

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_v2 and swe_next.

main has since done most of what earlier versions of this PR did. #4304 put swe_rebench, swemer_v1 and swemer_v2 on SandboxSessionResourcesServer with typed episode sessions, #5112 did the same for swe_next, and #6177 added the block on egress from the agent's sandbox. This PR is now a thin layer on those servers as main has them (their session tests from main pass), 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 on CheckpointedSandboxSessionResourcesServer (#5266). Each server changes by a few dozen lines.

  • 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, with its extraction error and whether the sandbox could not run the capture, so a /verify after a restore grades the saved outcome. checkpoint_verify = "replay".
  • Golden-patch servers run restart_only.
  • swe_next's allowed_agents adds opencode_agent.
  • scale_swe is 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_swe now 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)

  • The anti-cheat scrub and the committer-identity step are retried on provider errors (3 attempts, 2 s then 4 s), for every server that calls the shared helpers. At scale a sandbox gateway can briefly return an error, and the best-effort scrub then handed the agent a git history that still held the task's fix.
  • anti_cheat_required (repo-task servers; on in swe_rebench_legacy_agent.yaml, which swe_rebench.yaml includes): 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 when git gc failed 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.
  • Agent egress rule: 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; the agent_network_policy field 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.

  • The base-commit read, the pristine-file listing, swe_next's link of the workdir and its removal of the grading artifacts, and the swemer servers' check for a repository go through exec_idempotent, each with a 180 s budget (what sandbox.exec allows one command by default; exec_idempotent sets no limit of its own).
  • A pristine-file listing that cannot run, that the provider interrupted, or that git refuses fails the seed instead of returning an empty list, which would let the patch capture count the image's own untracked files as the agent's.
  • A repository check the provider reports as not run fails the seed instead of reading as "no repository", which initialised a new repository on top of one that may exist.

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 this
Loading

This 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)"]
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, #5266, #5268 and #5269 have merged, and this PR is rebased onto main after 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 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 (merged)
  6. test(checkpoint): end-to-end harness scenarios, SWE-bench recipe, docs #5269: test(checkpoint): end-to-end harness scenarios, SWE-bench recipe, docs (merged)
  7. feat(swe): checkpoint the episode sessions of the repository-task servers #5331: feat(swe): checkpoint the episode sessions of the repository-task servers (this PR)
  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 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, on main 4bbd832940 (Slurm job 9236333, rl-gym CI container, one node): import-linter clean; ruff check and ruff format --diff clean on the changed files; the suites of swebench, swe_rebench, swe_next, swemer_v1, swemer_v2, scale_swe and opencode_agent, and tests/unit_tests/agents and tests/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], and test_review_boundary_interfaces.py (collection). tests/e2e/checkpoint with NEMO_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 under enforce_agent_no_network forks 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 #5269 7c249d2c94. 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.
  • Tests added: the conformance kit on the four servers; episode and flat seeds; the replayable verify; a restore that 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 eval scripts with stdout and stderr apart; the scrub and identity retries; each anti_cheat_required rule; the shipped swe_rebench configs require the scrub; the retried first commands. main's agent-network tests for the four servers pass with the session's sandbox coming from new_task_sandbox.
  • Not covered: the conformance kit's optional comparison of a replayed /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.
  • Review: three reviewers and a second pass that challenged their findings; the confirmed ones are fixed in the last commit.
  • Not run on this head: golden patches per server on a provider that returns the streams apart; a seed on AgentENV with anti_cheat_required on (the stricter rule needs the scrub's summary line to reach stdout there); enforce_agent_no_network together with a restore on a live provider (covered by a unit test on a fake provider only).
  • 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.

Follow-ups, not in this PR:

  • A retry around a patch capture that the provider failed to run (today it is saved as an incomplete capture).
  • anti_cheat_required for swemer_v1, swemer_v2 and swe_next.
  • scale_swe on the checkpoint layer.
  • The conformance kit's verify_body check for these servers (see Validation).

Compatibility

Versus main:

  • swe_rebench, swemer_v1, swemer_v2, swe_next without 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_agents adds opencode_agent.
  • swe_rebench: anti_cheat_required is on in the shipped configs, so a seed whose scrub did not complete, or did not prune, fails and is retried.
  • Seeds fail, and the caller retries them, when the pristine-file listing or the repository check cannot run or is refused.
  • Scrub: retries apply to every caller of the shared helpers.
  • Eval output: stderr is joined to stdout in five servers' eval scripts. On a provider that returns them apart (not the shipped OpenSandbox config), tests whose output fell outside the marker region are now graded instead of counted as missing; benchmark results can change there.
  • scale_swe: sessions unchanged; with checkpointing on, its episodes start over after a crash.
  • Checkpointing on: the four servers need checkpoint.state_dir when their provider can snapshot.

Versus earlier versions of this PR:

  • swe_next's episode sessions are main's (feat(swe): support SWE-Next episode sessions #5112); this PR's own commit for them is dropped.
  • agent_network_policy and the applies_network_policy startup check are gone; main's egress block (feat(swe): block egress from the agent's sandbox in the SWE servers #6177) replaces them.
  • The seed check that the task id names the row is gone (main's seed has none).
  • A capture the sandbox could not run is masked as incomplete instead of graded as an empty patch. A capture that git refuses is still graded as an empty patch.
  • opencode_agent is not added to swe_rebench, swemer_v1 or swemer_v2 here: main's default configs already pair them with it.

🤖 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 this pull request to stack #5270 October 29, 2026 19:26
@svcnvidia-nemo-ci svcnvidia-nemo-ci added area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers feature New capabilities, enhancements, or enablement work labels Oct 29, 2026
@pthombre
pthombre force-pushed the pranav/envckpt-6-repo-task-servers branch from d1901c1 to 90142af Compare October 31, 2026 18:07
@pthombre
pthombre force-pushed the pranav/envckpt-6-repo-task-servers branch from 1105fdf to 7ee8313 Compare November 3, 2026 03:22
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:

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.

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?

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.

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.

Comment thread resources_servers/swe_rebench/app.py Outdated
started = time()
try:
sandbox = await self._create_sandbox(body, files=files)
sandbox = await self.start_grading_sandbox(body, files)

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.

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.

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.

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.

@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-6-repo-task-servers branch from 679a601 to d38da2d Compare November 12, 2026 20:35
@pthombre
pthombre force-pushed the pranav/envckpt-6-repo-task-servers branch from 4d24b91 to 4c2cd84 Compare November 21, 2026 07:02

@zyzhou5 zyzhou5 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.

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.

Comment thread resources_servers/swe_rebench/app.py Resolved
Base automatically changed from pranav/envckpt-5-e2e-docs to main November 21, 2026 21:38
pthombre and others added 6 commits November 21, 2026 13:41
…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]>
@pthombre
pthombre force-pushed the pranav/envckpt-6-repo-task-servers branch from 4c2cd84 to ab8cfb0 Compare November 21, 2026 22:19
@pthombre pthombre changed the title feat(swe): repository-task servers on the sandbox owner base feat(swe): checkpoint the episode sessions of the repository-task servers Nov 21, 2026
@pthombre

Copy link
Copy Markdown
Contributor Author

Rebased onto main (4bbd832940, after #5268 and #5269 merged); the head is ab8cfb0f0e, and the diff is this PR's six commits. Replies to the review comments that are not on a line:

@zyzhou5, description notes: all three are corrected.

  • The title is now "feat(swe): checkpoint the episode sessions of the repository-task servers".
  • The stderr change is described as affecting only providers that return stdout and stderr apart; the shipped OpenSandbox config returns one stream.
  • "A capture that fails is no longer graded as an empty patch" now reads: a capture the sandbox could not run is masked as incomplete; a capture that git refuses is still graded as an empty patch.

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 ab8cfb0f0e is the unit suites of the six SWE servers and opencode_agent, tests/unit_tests/agents, tests/unit_tests/server_runtime, and the process-level checkpoint e2e (Slurm job 9236333; results in the description). The smoke run the review asks for (five servers, a provider that returns the streams apart, swe_rebench with the required scrub, one restored episode) is still open.

The other RISK, a required scrub that accepts unpruned history, is fixed in ab8cfb0f0e; see the thread.

@pthombre

Copy link
Copy Markdown
Contributor Author

/ok to test ab8cfb0

@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team November 21, 2026 23:04
@pthombre
pthombre requested a review from zyzhou5 November 21, 2026 23:18
@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/44962878425

Merged via the queue into main with commit 591731a Nov 21, 2026
62 checks passed
@pthombre
pthombre deleted the pranav/envckpt-6-repo-task-servers branch November 21, 2026 23:53
zyzhou5 added a commit to zyzhou5/Gym that referenced this pull request Dec 2, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer risk:high Autobot PR risk: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants