Skip to content

feat(checkpoint): prepared verification, so a checkpoint never waits for SWE-bench grading - #4778

Draft
pthombre wants to merge 1 commit into
amahishi/opencode-resume-tool-call-lineagefrom
pthombre/partial-ckpt-sandbox-prepared-verify
Draft

pthombre wants to merge 1 commit into
amahishi/opencode-resume-tool-call-lineagefrom
pthombre/partial-ckpt-sandbox-prepared-verify

Conversation

@pthombre

@pthombre pthombre commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

What changed and why

A checkpoint has to wait for grading. SWE-bench's /verify is a wait step: a checkpoint's prepare waits for every grading in flight. A grading can take up to evaluation_timeout (1800 s), longer than a controller's prepare deadline. In a 32-node SWE-bench run with OpenCode, two prepares took 833 s and 1126 s, idling every node.

Verification can now take two steps, so a checkpoint never waits for grading:

  • POST /prepare_verify is a short wait step for the caller. It captures the patch, ends the session and stops the agent's sandbox. A retry of a lost reply gets the same patch.
  • POST /verify_prepared grades the captured patch in a fresh sandbox. It touches no session state, so the server declares it replayable: a checkpoint neither waits for it nor refuses it, and after a crash it simply runs again.

What this PR adds:

  • Replayable routes on resources servers (nemo_gym/base_resources_server.py, nemo_gym/_checkpoint/resources.py).

    • New: checkpoint_replayable_paths, a class variable listing further routes that are safe to run again after a crash and change no checkpointed session state. ResourcesParticipant treats them like a replay-mode /verify.
    • Validation: paths are checked like checkpoint_session_starts.
    • /prepare_verify and /verify_prepared join the reserved routes.
  • SWE-bench (resources_servers/swebench/app.py):

    • implements /prepare_verify, which captures the model patch and ends the session once (later calls get the same capture);
    • implements /verify_prepared, which grades a given model_patch in a fresh sandbox;
    • declares /verify_prepared replayable.
  • The driver (nemo_gym/_checkpoint/harness_run.py): an optional adapter protocol, PreparedVerification (prepares_verification, prepare_verification, verify_prepared). With it the run:

    • records the verify bookmark;
    • runs prepare_verification as a wait step;
    • stores the capture in the bookmark (VerifyBookmark.prepared);
    • grades it as a replay step.

    A restore at a prepared verify bookmark grades the saved capture again without preparing again.

  • verify_agent_response (nemo_gym/sandbox/agent_tools.py) takes the route (url_path) and extra body fields (extra).

  • OpenCode opts in with prepare_verification: true (default false) when checkpointing is on.

  • From fix(checkpoint): wake sandbox command polls while a harness launch is stopped #4553 (co-authored by Anish Mahishi, who designed the same routes for the OpenCode agent before the harness driver):

    • a grading that fails or is cancelled before run_instance's own cleanup still stops its sandbox, and the container stop is shielded from cancellation;
    • run_instance gives each grading its own logger and no longer returns from its finally, which swallowed the cancellation of an interrupted grading;
    • the capture is a helper that leaves the sandbox running when it fails;
    • six SWE-bench tests in test_prepared_verification.py.

How it works

sequenceDiagram
  participant C as Checkpoint
  participant D as Driver (#4274)
  participant R as SWE-bench
  D->>D: bookmark {next: verify, prepared: null}
  D->>R: /prepare_verify (a wait step: capture the patch, end the session)
  R-->>D: {model_patch}
  D->>D: bookmark {next: verify, prepared: {model_patch}}
  D->>R: /verify_prepared (a replay step, in a fresh sandbox)
  C->>D: park requested
  Note over C,D: the checkpoint does not wait for grading:<br/>the run is exported at its prepared bookmark
  Note over C,R: after a crash, the restored run grades the saved patch again
  R-->>D: reward
  D->>D: bookmark {next: return}
Loading
Step Checkpoint behaviour After a crash
/prepare_verify waits (short: capture and end the session) prepares again; a retry gets the same capture
/verify_prepared does not wait, does not refuse grades the saved capture again
/verify (one step, unchanged) waits for grading grades again

Where this sits in the stack

Stack #4578, on ananthsub/partial-ckpt-fault-tests: #4220 → #4221 → #4222 → #4576 → #4274 → #4451 → #4553 → #4778 (this PR) → #4779 → #4936.

This PR depends on #4274's driver and bookmarks. It does not depend on #4451 or #4553; it is stacked on top only to keep the stack linear.

Issue

Part of #3284 (sandboxed blackbox agents). It was split out of #4274 so that #4274 stays focused on the harness.

Validation

On this head (1a9635095), in the rl-gym.nightly container on Slurm (job 8087405):

  • Gym suites (SWE-bench, OpenCode, and the checkpoint, sandbox, OpenSandbox and token-capture unit tests): 2321 passed, 9 skipped, 0 failed.
  • ruff is clean, and the commit carries Signed-off-by.

Tests:

  • tests/unit_tests/test_checkpoint_harness_run.py:
    • prepared verification does not hold up a checkpoint for grading;
    • a continuation at a prepared verify grades the saved capture without preparing again;
    • a run that fails after preparing does not close the session that preparing already ended.
  • resources_servers/swebench/tests/test_checkpoint.py:
    • prepared verification captures, then grades while a checkpoint is open;
    • a prepare for a session without a sandbox is refused.
  • resources_servers/swebench/tests/test_prepared_verification.py (from fix(checkpoint): wake sandbox command polls while a harness launch is stopped #4553):
    • retries return the captured patch after the original sandbox is stopped;
    • a failed capture keeps the original sandbox available;
    • one-step /verify still holds up prepare;
    • a slow prepared grading does not, and replays in a restarted server without the original sandbox;
    • /verify_prepared requires a patch but accepts an empty diff;
    • run_instance propagates cancellation after cleanup.

Rollout evidence

32-node GRPO runs (nano-3.5 SWE policy, SWE-bench, 64 prompts × 2, 5 steps) with prepare_verification: true:

Prepare time
Before (one-step verify) two prepares took 833 s and 1126 s
After (prepared verify), stop and relaunch about 31 s median
After (prepared verify), with #4274's pause 24 s median, 31.7 s max over 19 checkpoints (job 8078235)
After, with the whole stack on top (this head plus #4779) 9.8 s median, 32 s max over 18 checkpoints (job 8093570)

In those runs prepare_verify reported 0 errors, and rollouts restored at verify or return bookmarks were graded again from the stored patch.

Compatibility

  • Opt-in: OpenCode's prepare_verification defaults to false, and one-step /verify is unchanged.
  • New optional API:
    • PreparedVerification (adapter protocol);
    • checkpoint_replayable_paths (resources server);
    • url_path and extra on verify_agent_response.
  • Resources-server requirement: a resources server needs both routes for an agent to enable prepared verification. SWE-bench is the first.

🤖 Generated with Claude Code

@copy-pr-bot

copy-pr-bot Bot commented Oct 20, 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 area:core Shared APIs, servers, telemetry, health, and registries feature New capabilities, enhancements, or enablement work labels Oct 20, 2026
pthombre added a commit that referenced this pull request Oct 20, 2026
…t a failed session database snapshot in full

- README: a "Checkpoint resume" section. A checkpoint pauses OpenCode, and OpenCode is relaunched on its saved
  session only after a crash restore or when a pause cannot be confirmed. The relaunch re-enters the saved user
  message through resume_opencode.py without a new message. The section also gives the sandbox requirements and
  how to run the real-runtime resume regression.
- The error for a failed `opencode db VACUUM INTO` names the destination, return code, error type and the tail
  of stdout and stderr. A background execution returns both streams in stdout, so stderr alone often held only
  a status.

From #4553 (b53e39f, 4d077ea), whose resume helper and the rest of whose changes are now in #4274 and #4778.

Signed-off-by: Anish Mahishi <[email protected]>
Co-authored-by: Pranav Prashant Thombre <[email protected]>
Signed-off-by: Pranav Prashant Thombre <[email protected]>
@pthombre
pthombre force-pushed the pthombre/partial-ckpt-sandbox-prepared-verify branch from a639248 to 1a96350 Compare October 20, 2026 17:01
@pthombre
pthombre changed the base branch from pthombre/partial-ckpt-sandbox-capture to amahishi/opencode-resume-tool-call-lineage October 20, 2026 17:01
@pthombre
pthombre added this pull request to stack #4696 October 20, 2026 17:03
pthombre added a commit that referenced this pull request Oct 20, 2026
…t a failed session database snapshot in full

- README: a "Checkpoint resume" section. A checkpoint pauses OpenCode, and OpenCode is relaunched on its saved
  session only after a crash restore or when a pause cannot be confirmed. The relaunch re-enters the saved user
  message through resume_opencode.py without a new message. The section also gives the sandbox requirements and
  how to run the real-runtime resume regression.
- The error for a failed `opencode db VACUUM INTO` names the destination, return code, error type and the tail
  of stdout and stderr. A background execution returns both streams in stdout, so stderr alone often held only
  a status.

From #4553 (b53e39f, 4d077ea), whose resume helper and the rest of whose changes are now in #4274 and #4778.

Signed-off-by: Anish Mahishi <[email protected]>
Co-authored-by: Pranav Prashant Thombre <[email protected]>
Signed-off-by: Pranav Prashant Thombre <[email protected]>
@pthombre
pthombre force-pushed the pthombre/partial-ckpt-sandbox-prepared-verify branch from 1a96350 to 4a7590c Compare October 20, 2026 22:18
pthombre added a commit that referenced this pull request Oct 21, 2026
…t a failed session database snapshot in full

- README: a "Checkpoint resume" section. A checkpoint pauses OpenCode, and OpenCode is relaunched on its saved
  session only after a crash restore or when a pause cannot be confirmed. The relaunch re-enters the saved user
  message through resume_opencode.py without a new message. The section also gives the sandbox requirements and
  how to run the real-runtime resume regression.
- The error for a failed `opencode db VACUUM INTO` names the destination, return code, error type and the tail
  of stdout and stderr. A background execution returns both streams in stdout, so stderr alone often held only
  a status.

From #4553 (b53e39f, 4d077ea), whose resume helper and the rest of whose changes are now in #4274 and #4778.

Signed-off-by: Anish Mahishi <[email protected]>
Co-authored-by: Pranav Prashant Thombre <[email protected]>
Signed-off-by: Pranav Prashant Thombre <[email protected]>
@pthombre
pthombre force-pushed the pthombre/partial-ckpt-sandbox-prepared-verify branch from 4a7590c to 37f5c84 Compare October 21, 2026 03:05
@pthombre
pthombre force-pushed the pthombre/partial-ckpt-sandbox-prepared-verify branch from 37f5c84 to 5fbfcb9 Compare October 25, 2026 02:47
…for SWE-bench grading

SWE-bench's /verify is a wait step: a checkpoint's prepare waits for every in-flight grading, which can take up
to evaluation_timeout (1800 s, longer than a controller's prepare deadline). In a 32-node SWE-bench run two
prepares took 833 s and 1126 s, idling every node.

Verification can now take two steps:

- /prepare_verify (a wait step for the caller): capture the patch, end the session and stop the agent's
  sandbox. A retry of a lost reply gets the same patch.
- /verify_prepared: grade the captured patch in a fresh sandbox. It touches no session state, so the server
  declares it in the new checkpoint_replayable_paths: a checkpoint neither waits for it nor refuses it.

SandboxedHarnessAgent runs an adapter's optional PreparedVerification: the capture is recorded in the verify
bookmark, grading is a replay step, and a restore grades the saved capture again. OpenCode opts in with
prepare_verification: true. verify_agent_response takes the route and extra body fields.

From #4553 (4d077ea), which designed the same routes for the OpenCode agent before the harness driver:

- A grading that fails or is cancelled before run_instance's own cleanup still stops its sandbox, and the
  container stop is shielded from cancellation.
- run_instance gives each grading its own logger and no longer returns from its finally, which swallowed the
  cancellation of an interrupted grading.
- The capture is a helper that leaves the sandbox running when it fails.
- test_prepared_verification.py: retries return the captured patch after the sandbox stopped; a failed capture
  keeps the sandbox; one-step /verify still holds up prepare; a slow prepared grading does not, and replays
  in a restarted server without the original sandbox; /verify_prepared requires a patch but accepts an empty
  diff; and run_instance propagates cancellation after cleanup.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-authored-by: Anish Mahishi <[email protected]>
Signed-off-by: Pranav Prashant Thombre <[email protected]>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core Shared APIs, servers, telemetry, health, and registries feature New capabilities, enhancements, or enablement work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants