Skip to content

feat(scale_swe): run episode sessions on the shared session base, with checkpoints - #6765

Merged
zyzhou5 merged 14 commits into
NVIDIA-NeMo:mainfrom
zyzhou5:zezhou/ckpt-scale-swe
Dec 2, 2026
Merged

zyzhou5 merged 14 commits into
NVIDIA-NeMo:mainfrom
zyzhou5:zezhou/ckpt-scale-swe

Conversation

@zyzhou5

@zyzhou5 zyzhou5 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What changed and why

scale_swe was the one SWE server with its own episode-session code on SimpleResourcesServer, so #5331 left it restart_only. This PR moves it onto the shared session base and partial-rollout checkpoints, as RepoTaskSessionResourcesServer. Grading, the patch-capture failure semantics (_PatchCaptureError / _UnreadablePatchError) and the failure kinds are unchanged.

  • From the base: the session record and lock, seed, verify and close, close fences, expiry, sandbox stops and shutdown, and checkpoint export/restore. The task sandbox starts with new_task_sandbox.
  • Kept through overrides, where the base differs: golden-patch, invalid-row, shutdown and missing-base-commit seed refusals; verifier sandboxes kept with the session until their stop succeeds (a verification that retries on a fresh sandbox can start several).
  • Capture: saved as a JSON value with its failure kind, so a verify after a restore grades the same patch, or masks a lost capture as the first verify did.
  • fix(swe): mask verifications without a verdict and block agent egress in more SWE servers #6670, merged in: the /run path grades and masks like an episode session. Its capture takes the sandbox and its state out of the session first, so a re-seed during the capture keeps its own sandbox.
  • partner_if (a ScaleSWEResourcesServer subclass with its own sessions) declares checkpoint_mode = "restart_only" and checkpoint_verify = "wait", keeping its behaviour. It also passes anti_cheat_required, which it inherits from Scale-SWE's config, to its scrub.

Behaviour changes without checkpoints

  • An episode session never closed expires after the sandbox's ttl_s (18000 s in the shipped config); a later verify is masked as session_expired, or session_lost once the close retry window has passed. The provider's TTL ended the sandbox at the same time before.
  • Each sandbox stop waits for the provider's own stop, and a stop that failed is retried. Shutdown stops every sandbox the server holds, the /run path's included, after any request in progress on that session finishes. Before, each stop had a bounded wait (sandbox_stop_timeout_seconds), and the /run path's sandboxes were left to the TTL at shutdown. sandbox_stop_timeout_seconds still loads, with a warning, and is ignored.
  • An agent-run (/run) seed naming an episode session gets a 409 instead of replacing that session's sandbox.
  • A seed conflict uses the base's 409 wording.
  • An identical verify retry gets the first result back, masked or not. A verify that ended before it replied runs again on the captured patch. Before, a retry after an attempt without a verdict got a 503.
  • A task sandbox that does not stop after the capture fails that verify, and the retry grades the captured patch. Before, the failure was logged and grading went on.
  • A close waits for a seed or verify in progress. A verify after a close is masked as session_lost; before, it got a 409.
  • A /run verify that finds no task sandbox is masked as session_lost. Before, it graded an empty patch.
  • A seed whose untracked-file listing still fails after retries now fails, and the episode is retried. Before, it went on with an empty list.
  • A /run seed whose setup failed stops its sandbox, and a later verify grades nothing.
  • An agent's /run seed holds the session lock, as the other repository-task servers' do: another seed for the same ID, or a re-seed during a verification, waits until it is done.
  • A grading attempt's sandbox is stopped right away only when another attempt follows; the last one is stopped once, when verify ends.

Notes for reviewers

  • The overrides use private hooks and state of the session base (_task_sessions, _task_session_fences, _task_sandbox_response, _stop_failed_seed_sandbox, _TaskSession), so this server is tied to the base's internals.
  • With checkpointing on and a sandbox provider that can snapshot, the server needs checkpoint.state_dir and refuses to start without it; before, it ran restart_only.

Issue

No GitHub issue. Requested for the Nemotron-4 post-training environments marked for rollout checkpointing.

Validation

In an existing Gym venv with NEMO_GYM_CONFIG_DICT='{}' (otherwise Hydra parses pytest's arguments and the session tests error on main too):

Suite This PR
scale_swe/tests 148 passed
agentic_if/tests 927 passed
partner_if/tests 682 passed, 22 failed

The 22 partner_if failures (test_recorded_context_*) fail identically on main: the venv has no ripgrep.

  • scale_swe/tests/test_checkpoints.py (15 tests): the eight scenarios feat(swe): checkpoint the episode sessions of five more repository-task servers #6763's helper runs for every repository-task server (tests/helpers/swe_repo_task_checkpoints.py, whose fake HEAD is now a full object name and whose passing run prints the start marker), plus Scale-SWE's own: grading in a fresh sandbox, the stored failure kind, a commit during grading or during the stop after capture, and the /run seed refusal. Existing tests changed where they assert internals that moved (session fields renamed to the base's, the fake _create_sandbox taking session_id), and where they asserted the verify, close and listing rules and the stop and shutdown this PR now takes from the base.
  • pre-commit run --files on 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 at baec436f9be (before the #6670 merge and the move to the base's stops and shutdown). The checkpoint landed during verify, after 8 model calls. After Gym was killed and restored, the saved capture was graded; verify completed, not masked.

Local, on Docker, no model, each row's golden patch standing in for the agent: golden-patch grading and the episode path give the same rewards and the same captured patch on main and this PR for all 5 example rows. A docker commit snapshot stand-in also ran checkpoint → crash → restore: verify completed, same patch.

🤖 Generated with Claude Code

…h 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]>
@copy-pr-bot

copy-pr-bot Bot commented Nov 25, 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.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added risk:high Autobot PR risk: high feature New capabilities, enhancements, or enablement work area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers labels Nov 25, 2026
zyzhou5 and others added 6 commits November 25, 2026 22:22
…d 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]>
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]>
…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]>
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]>
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]>
…ed 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]>
@zyzhou5
zyzhou5 marked this pull request as ready for review November 25, 2026 23:23
@zyzhou5

zyzhou5 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test baec436

@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team November 25, 2026 23:24
@github-actions

Copy link
Copy Markdown
Contributor

@svcnvidia-nemo-ci svcnvidia-nemo-ci 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.

SHIP WITH CARE.

I found four reliability risks in slow-stop and shutdown paths. I did not find a demonstrated score-calculation regression. The inline findings include reproductions and acceptance checks.

RISK: Required real rollout evidence is missing

Could you attach a representative model rollout and the planned OpenSandbox checkpoint → crash → restore smoke? The PR’s current description still says these have not run. This changes task-sandbox ownership, verification replay and restore behavior, so the real-run requirement in AGENTS.md applies. Include the task IDs, configuration, inspected agent/verifier outcomes and evidence that the resumed session grades the same patch. Mock tests and golden-patch grading alone do not cover that production agent path.

Coverage and validation

  • I reviewed all seven PR-changed files with three delegated topic reviewers. I also accounted for the other differences against the admitted base: those paths match the merge-base and are upstream drift, not PR-authored removals. The new Scale-SWE checkpoint path passed fake-provider conformance probes against both admitted shared-runtime versions.
  • CI on baec436f9beecdd0f100c6dd23703db83ba592cc is green for Nemo_CICD_Test, Unit tests / Test, core shards, sandbox tests, combined coverage, changed-server tests and Lint check. The changed-server log records 132 Scale-SWE tests passed and 701 partner_if tests passed. Full server-suite shards, session-routing end-to-end and provider E2E were skipped, not passed.
  • Local probes used 766267172432.dkr.ecr.us-east-1.amazonaws.com/gym:cd1b05dcdf72d6101a3a2b8292608422f0f93eb7, the default-branch CI image because the head’s container build was skipped. Successful probes covered saved-patch replay/restore, cancelled verification, failure-kind persistence, partner_if’s inherited verify and restart-only behavior. Slow-provider probes reproduced the inline issues. Existing green CI suites were not rerun.
  • All local execution was CPU-only with fake providers. Initial probe setup failures were corrected before interpreting results; no real model or OpenSandbox rollout ran. The admitted source checkout has no tracked-file changes.

Inline comments (escaped v1):

  • resources_servers/swebench/sandbox_sessions.py line 245: RISK: An identical seed can return a sandbox that close already deleted.

    Scale-SWE newly adopts this seed path at app.py:562. Its bounded close wait leaves the actual stop running, but shared close records its fence only after that wait succeeds. After a timeout, this membership check accepts the cached response both during deletion and after the detached stop completes, because the sandbox stays in the map.

    probe_seed_after_stop_comparison.py, using a real AsyncSandbox over a scripted provider, returned status=200 sandbox_access_returned=True sandbox_started=False on head; base rejected the same sequence with 409. This hands a retrying episode a dead or dying sandbox.

    Could you keep close intent recorded across the bounded timeout and reject seed replay until cleanup is reconciled? Preserve identical-seed replay for genuinely open sessions and retryable close ownership. Acceptance: replay seed before and after an overlong provider deletion completes; both must be rejected, and retried close must join the original stop without starting another deletion.

  • resources_servers/swebench/sandbox_session_checkpoints.py line 171: RISK: Inherited shutdown starts a second stop and closes the provider beneath the first.

    The new Scale-SWE shutdown delegation first runs _stop_abandoned_session. When its bounded wait expires, the shielded stop continues. This checkpointer pass still owns the same sandbox and calls sandbox.stop() directly instead of joining Scale-SWE’s _stop_tasks; provider aclose() then runs while the original stop is pending.

    A real-wrapper/fake-provider probe observed two concurrent provider closes, cancellation of the second, and provider-client closure with the first still running. The probe shortened the checkpointer deadline to exercise the ordering. This also occurs with checkpoint control disabled because episode sandboxes are still tracked.

    Could you give both shutdown passes one joining stop owner and keep the provider available until pending stops settle or reach an explicit bounded backstop? Preserve cleanup of checkpointer-only restore forks. Acceptance: stall a sandbox created through new_task_sandbox past the wait; assert one concurrent deletion, no duplicate-stop cancellation, and no premature provider closure.

  • resources_servers/scale_swe/app.py line 376: RISK: The export lock defeats the busy-session shutdown bound.

    _stop_abandoned_session bounds acquisition of the session lock, then tries to stop the sandbox anyway. This second lock acquisition has no bound. Patch capture holds the export lock for its entire callback, so a stalled capture prevents shutdown from even reaching _wait_for_stop.

    probe_shutdown_comparison.py held capture on an event with a 0.02-second shutdown wait. After 150 ms, head was still waiting with zero stop calls; base had finished shutdown and called stop once. Head finished only after capture was cancelled. Production capture commands have their own longer timeout, but the configured shutdown bound is lost.

    Could you include export-lock acquisition and its owning operation in the bounded shutdown policy? Coordinate draining/cancellation or explicitly hand unresolved cleanup to the TTL backstop; do not destroy a sandbox concurrently with snapshotting. Acceptance: hold the lock through both capture and checkpoint export beyond the shutdown budget and verify bounded, diagnosed cleanup.

  • resources_servers/scale_swe/app.py line 379: RISK: A timed-out stop releases snapshot exclusion while deletion continues.

    _wait_for_stop times out only the waiter, leaving the actual stop running. On that exception this context releases _export_locks, while the sandbox stays registered and started. A subsequent checkpoint therefore snapshots a sandbox whose deletion is still in flight, despite already having its saved capture.

    probe_snapshot_during_stop.py drove the HTTP seed, verify and checkpoint routes with an event-held provider close. It printed underlying sandbox stop still running=True followed by checkpoint completed; snapshots=1 snapshot while stop was running=True. The added stop/checkpoint test releases deletion before the wait expires, so it misses this ordering. The PR notes that overlong stops can block commits; this additionally demonstrates that export can race deletion rather than wait or fail cleanly.

    Could you make export account for the actual stop task, not only its bounded waiter? Either refuse/wait within the checkpoint deadline, or export the saved capture without snapshotting while keeping independent cleanup ownership. Preserve bounded caller waits and the original capture. Acceptance: hold close past sandbox_stop_timeout_seconds, attempt a commit, and assert no snapshot starts until deletion settles; cover both completion and failure without orphaning the sandbox.

Review generated by codex. This was a full review. Request a full review with /review reset=true.

@yaoyu-33
yaoyu-33 requested a review from prokotg November 26, 2026 02:10
@github-actions github-actions Bot added the sla:review-overdue Review response is over the one-business-day SLA label Nov 27, 2026

@macandro96 macandro96 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review comments on session cleanup, configuration propagation, and shared checkpoint test coverage.

Comment thread resources_servers/scale_swe/app.py Resolved
Comment thread resources_servers/scale_swe/app.py Resolved
Comment thread resources_servers/scale_swe/app.py Resolved
Comment thread resources_servers/scale_swe/app.py Resolved
Resolve the overlap with NVIDIA-NeMo#6670, keeping both changes:
- The /run (cookie) path grades and masks like an episode session, as NVIDIA-NeMo#6670 made it: a capture
  lost to infrastructure is masked, a repository the agent broke is a measured 0. Its capture takes
  the sandbox and its state out of the session first, so a re-seed during the capture keeps its own
  sandbox; episode sessions keep the base-backed capture that is saved for checkpoints.
- A /run seed whose setup failed forgets what the capture would read and stops its sandbox, so a
  later verify cannot grade it, even when the stop fails.
- The untracked-file listing stays the repository-task base's.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Zeyu Zhou <[email protected]>
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the needs-review PR is ready for code review and waiting on a reviewer label Dec 1, 2026
zyzhou5 and others added 2 commits December 1, 2026 19:36
…on 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]>
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]>
@zyzhou5

zyzhou5 commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 00ccb47

zyzhou5 and others added 2 commits December 1, 2026 23:48
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]>
@zyzhou5

zyzhou5 commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test a9ec8bf

@nemo-pr-automation
nemo-pr-automation Bot requested a review from a team December 2, 2026 00:11

@macandro96 macandro96 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up review: failed-seed cleanup ownership and clarification of shared shutdown and verifier cleanup budgets.

Comment thread resources_servers/scale_swe/app.py Resolved
Comment thread resources_servers/scale_swe/app.py Resolved
Comment thread resources_servers/scale_swe/app.py Resolved
zyzhou5 and others added 2 commits December 2, 2026 18:30
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]>
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]>
@zyzhou5

zyzhou5 commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 3818e3e

@zyzhou5
zyzhou5 removed the request for review from a team December 2, 2026 20:01
@zyzhou5
zyzhou5 added this pull request to the merge queue Dec 2, 2026
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/46958801829

Merged via the queue into NVIDIA-NeMo:main with commit cee3cb7 Dec 2, 2026
67 checks passed
@zyzhou5
zyzhou5 deleted the zezhou/ckpt-scale-swe branch December 2, 2026 20:24
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 sla:review-overdue Review response is over the one-business-day SLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants