Skip to content

feat(checkpoint): process-level evidence for resources-owned sandbox checkpoints, their release, and lease expiry - #4221

Open
pthombre wants to merge 1 commit into
pthombre/partial-ckpt-sandbox-corefrom
pthombre/partial-ckpt-sandbox-resources
Open

pthombre wants to merge 1 commit into
pthombre/partial-ckpt-sandbox-corefrom
pthombre/partial-ckpt-sandbox-resources

Conversation

@pthombre

@pthombre pthombre commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

What changed and why

#4220 adds what a sandbox owner builds on: a snapshot taken at commit as the restore point, a fork at restore, the snapshot index with the release call that deletes snapshots the controller no longer keeps, and sandboxes on a lease their creating process renews. This PR shows that the resources-server side of all of it works across real Gym processes, with every process killed between the checkpoint and the restore. It is test code only, and it runs without a cluster: a fake sandbox service stands in for OpenSandbox.

  • A fake sandbox service (tests/e2e/checkpoint/fake_sandbox_backend.py) shaped like OpenSandbox's management API. It runs as its own process, so it outlives a Gym crash as the real service does. Each sandbox is a small in-memory filesystem driven by commands such as append notes one and read notes. A snapshot is a copy made asynchronously (Creating, then Ready) and kept until deleted, whatever its sandbox does afterwards, and creating a sandbox with snapshot_id starts from that copy. A sandbox whose lease lapses expires, as on OpenSandbox. A control route makes the next call of a given kind on a given sandbox fail.
  • A fake provider (sandbox_notes_server/fake_sandbox_provider.py, registered as fake_remote) that talks to that service and renews the sandboxes it creates on the same lease the OpenSandbox provider uses.
  • A sandboxed resources server (sandbox_notes_server) that resolves its provider through a named sandbox block, as the SWE-bench server does. Each session owns a sandbox. The append_note tool writes a line into it, and verification reads the file back and rewards 1.0 when it holds exactly the expected lines. Its checkpoint hooks delegate to SandboxSessionCheckpointer: export snapshots under the commit's checkpoint ID, restore forks, verify and retire stop the sandbox and keep its snapshots, a commit the controller stops after parks the sandboxes, and release_external_state deletes the snapshots of checkpoints the controller dropped.
  • The sandbox topology in the e2e deployment: the legacy /run relay over Simple Agent and the notes server, with checkpoint.state_dir in the suite's work directory so the index survives a crash, and the fake_remote sandbox block (sandbox_lease adds a lease). Two fixes to the suite's harness come with it: spawned servers keep the inherited PYTHONPATH after the repository, so they import this checkout where another Gym is installed, and the fake inference backend's hold can move its threshold and release the calls it held in one step (release_held).
  • Scenarios, each across real server processes:
Scenario What it shows
A sandbox is restored with the episode After a crash the restore forks the snapshot and stops the crashed process's sandbox, and the replacement attempt finishes with reward 1.0. Once the controller publishes a later checkpoint and drops this one, the restarted process's release deletes the snapshot the crashed process indexed. Negative control: without the resources restore, the continued episode starts in an empty sandbox and gets reward 0, nothing forks the snapshot, and the crashed process's sandbox is left alone.
A sandbox that moved on after the checkpoint is rebuilt from its snapshot The episode writes into the live sandbox after the resume, then every process dies. The fork holds only what the snapshot held, so the replayed tool call lands once, not twice.
A crashed process's sandboxes expire on their lease A sandbox outlives several lease TTLs while its server renews it. Once every Gym process is killed, the service expires it within one TTL with no call from anyone, and the checkpoint still restores the episode into a fork on a lease of its own.
Retiring a sandboxed episode The retire stops the sandbox, and the rollout starts over in a fresh one.
A failed snapshot Injected through the fake service: the commit fails, only the resources participant reports the failure, and the episode continues in its sandbox after the resume.
A release keeps what the controller keeps Two checkpoints of one episode: a release that keeps only the second deletes only the first's snapshot while the episode continues, and release([]) empties the service and the index.
A release after a crash The restarted server's release deletes the snapshots of a checkpoint the dead process committed but never published.
A release while a checkpoint is open Refused.
  • A seeded random-sequence test (tests/unit_tests/test_checkpoint_sandbox_sequences.py, 40 seeds) interleaves tool calls, exports, releases of random kept sets, restores into fresh checkpointers over the same index (a crash), and stops, with injected faults including snapshots that never become ready and failed snapshot deletes. After every step it checks that no live session points at a stopped sandbox, every kept checkpoint's snapshot exists with the files its session had, every snapshot in the service is in the index, and a failed restore leaves nothing behind. At the end every kept checkpoint restores byte-equal, and once the faults stop, a release leaves exactly the kept checkpoints' snapshots.

No production server adopts the hooks in this PR. The first production resources-server owner is the SWE-bench server in #4576. #4222 adds the park request that a long-running agent harness in such a sandbox needs, with its process-level evidence.

How it works

What runs in the suite

The highlighted parts are what this PR adds. The test drives Gym the way a controller does, through nemo_gym._checkpoint.coordination, and kills and restarts the Gym processes; the two fake backends keep running, as an inference service and a sandbox service would.

flowchart LR
  T["e2e test<br/>acts as the controller"]
  subgraph G["Real Gym processes, killed and restarted by the test"]
    E["legacy_agent environment"]
    A["Simple Agent"]
    M["Policy model server"]
    R["sandbox_notes_server<br/>SandboxSessionCheckpointer"]
  end
  F[("Fake inference backend<br/>scripted tool calls")]
  S[("Fake sandbox service<br/>sandboxes, snapshots, leases")]
  I[("Snapshot index<br/>checkpoint.state_dir")]
  T -- "prepare, commit, restore, resume,<br/>retire, release" --> G
  T -- "/run" --> E
  E --> A
  A --> M
  M --> F
  A -- "append_note" --> R
  R -- "exec, snapshot, fork, renew, stop, delete" --> S
  R -- "one file per snapshot" --> I
  T -. "inspects sandboxes and snapshots" .-> S
  classDef this fill:#fde68a,stroke:#b45309,stroke-width:2px,color:#1f2937
  class R,S this
Loading

A sandbox that moved on after the checkpoint

sequenceDiagram
  participant T as e2e test
  participant G as Gym processes
  participant S as Fake sandbox service
  T->>G: /run, the model appends "one"
  G->>S: append notes one, in sandbox A
  T->>G: checkpoint c1
  G->>S: snapshot A, which holds "one"
  T->>G: resume, the model appends "two"
  G->>S: append notes two, so A holds "one, two"
  Note over T,G: crash - the test kills every Gym process
  T->>G: restart and restore c1
  G->>S: fork the snapshot into sandbox B, which holds "one"
  G->>S: stop A
  T->>G: /run as attempt 1, continuing after "one"
  G->>S: append notes two, then three, in B
  G-->>T: verify reads exactly "one, two, three", reward 1.0
Loading

A crashed process's sandboxes expire on their lease

sequenceDiagram
  participant T as e2e test
  participant R as sandbox_notes_server
  participant S as Fake sandbox service
  R->>S: create sandbox A on a lease
  loop every renewal interval while the server lives
    R->>S: renew the lease of A
  end
  T->>R: checkpoint c1, a snapshot of A
  Note over T,R: crash - the test kills every Gym process, and nobody renews A
  Note over S: the lease of A lapses, and the service expires A within one TTL
  T->>R: restart and restore c1
  R->>S: fork the snapshot into sandbox B, on a lease of its own
  Note over R,S: the replacement attempt finishes in B
Loading

Where this sits in the stack

This PR is one of a series that adds sandbox checkpointing on top of the partial-rollout checkpointing stack, whose top is #4197 (ananthsub/partial-ckpt-fault-tests). Each PR's base is the branch of the PR before it, so each diff shows only that PR's change.

  1. feat(sandbox): sandbox and snapshot lifecycle for partial-rollout checkpoints #4220 (pthombre/partial-ckpt-sandbox-core): the sandbox session checkpointer, the release protocol, the snapshot index, the OpenSandbox lease, and /sandbox_access
  2. feat(checkpoint): process-level evidence for resources-owned sandbox checkpoints, their release, and lease expiry #4221 (pthombre/partial-ckpt-sandbox-resources): this PR
  3. feat(checkpoint): ask a long-running agent harness to park when a checkpoint opens #4222 (pthombre/partial-ckpt-sandbox-agent): the park request for long-running agent harnesses, with process-level evidence
  4. feat(sandbox): sandbox owner base for resources servers, with SWE-bench on it #4576 (pthombre/partial-ckpt-sandbox-swebench): the sandbox owner base, with the SWE-bench resources server on it
  5. feat(checkpoint): harness driver for sandboxed agents that pauses them at checkpoints, with OpenCode on it #4274 (pthombre/partial-ckpt-sandbox-opencode): the harness driver, with the OpenCode agent on it
  6. fix(checkpoint): leave the calls a checkpoint abandoned out of the capture ledger #4451 (pthombre/partial-ckpt-sandbox-capture): calls a checkpoint abandoned stay out of the capture ledger

Issue

No tracking issue; see #4220.

Validation

Run in the r3Run nemo-rl+Gym container on Slurm against this head, on ananthsub/partial-ckpt-fault-tests 4daebf2e4 (jobs 1253288 and 1253398):

  • NEMO_GYM_CHECKPOINT_E2E=1 pytest tests/e2e/checkpoint: 61 passed, 13 skipped (the real-model and scale cases), including the 9 sandbox scenario cases above.
  • tests/unit_tests/test_checkpoint_*.py: 791 passed, including test_checkpoint_sandbox_sequences.py.
  • The sandbox suite 211 passed and the OpenSandbox provider suite 145 passed.
  • ruff check and ruff format --check (ruff 0.9.9) clean on the changed files. Every commit carries Signed-off-by.

Rollout evidence

The scenarios above are the rollout evidence for the mechanism: real Gym processes, a checkpoint mid-episode, every process killed, a restore into fresh processes, and the replacement attempt finishing with the expected reward. The OpenSandbox code path the fake service stands in for ran live on cell-5; see the rollout evidence in #4220.

Compatibility

Test code only; no server changes behavior.

🤖 Generated with Claude Code

@copy-pr-bot

copy-pr-bot Bot commented Oct 8, 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

This comment has been minimized.

@pthombre
pthombre force-pushed the pthombre/partial-ckpt-sandbox-resources branch from 3ab0e49 to 8c08946 Compare October 11, 2026 04:43
@pthombre
pthombre force-pushed the pthombre/partial-ckpt-sandbox-resources branch from 8c08946 to 97fe118 Compare October 12, 2026 21:53
@pthombre
pthombre force-pushed the pthombre/partial-ckpt-sandbox-resources branch 2 times, most recently from 7ac7ed0 to 9aa96c1 Compare October 13, 2026 16:24
@pthombre
pthombre force-pushed the pthombre/partial-ckpt-sandbox-resources branch from 9aa96c1 to de90aec Compare October 13, 2026 16:27
@pthombre
pthombre marked this pull request as ready for review October 13, 2026 16:44
@pthombre
pthombre requested review from a team as code owners October 13, 2026 16:44
…checkpoints and their release

A fake sandbox backend in the shape of OpenSandbox's management API, with explicit snapshots that go Creating
then Ready and outlive a Gym crash; a resources server whose sessions each own a sandbox in it and that
releases the snapshots of dropped checkpoints; and the e2e scenarios: the restore matters, a sandbox that moved
on after the checkpoint is rebuilt from its snapshot so the replayed call lands once, a retire stops the
sandbox, a snapshot that fails fails the commit and the episode continues in its sandbox after the resume, a
release deletes only the snapshots of checkpoints the controller dropped (and everything once the run is
complete), a restarted process deletes the snapshots of a checkpoint the crashed one committed but never
published, and a release is refused while a checkpoint is open. The fake backend expires a sandbox whose lease
lapses, as OpenSandbox does, and the fake provider renews the sandboxes it created on the lease the OpenSandbox
provider uses; a scenario shows a crashed process's sandbox renewed while the process lives and expiring
within one TTL of the crash with no call from anyone, while its snapshot still restores. The resources server
resolves its provider through a named sandbox block, as a production server's `sandbox_provider` does, and the
deployment sets `checkpoint.state_dir` beside the suite's work directory, so the index survives a Gym crash.

A seeded random-sequence test checks the checkpointer's invariants under injected backend faults, including
snapshots that never become ready, failed snapshot deletes and releases of random kept sets across crashes that
share the index: every snapshot on the backend is in the index, every kept checkpoint restores, and once faults
stop a release leaves exactly the kept checkpoints' snapshots.

Signed-off-by: Pranav Prashant Thombre <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cmunley1

Copy link
Copy Markdown
Contributor

/ok to test 20485ac

@cmunley1

Copy link
Copy Markdown
Contributor

/review

@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team November 13, 2026 01:28

@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 three validation risks: subprocesses can import components from an inherited checkout, an index-cleanup assertion races background work, and the randomized test accepts unexpected failures as injected faults.

I reviewed all seven changed files and their directly affected checkpoint, lifecycle, import, and test contracts. These findings affect the test harness and its evidence; this PR changes no production server behavior. I didn't execute tests. The suggested changes and acceptance checks below are source-based and need verification before adoption.

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

"""The repository first, then whatever the environment already had, so a server imports this checkout's
packages even where another Gym checkout is installed."""
inherited = os.environ.get("PYTHONPATH", "")
return os.pathsep.join([str(REPO), inherited]) if inherited else str(REPO)

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.

RISK — Pin component imports as well as the initial package import.

With PYTHONPATH=/older/Gym, this helper initially places the reviewed repository first. However, importing nemo_gym invokes _augment_sys_path(), whose editable-install branch moves this repository behind inherited entries. The multiworker launcher then imports component packages by name, so workers can load the older Simple Agent. The single-worker policy server also imports a sibling by package name. Previously, the harness removed that inherited checkout from PYTHONPATH. The suite can now exercise mixed revisions or fail on an incompatible sibling instead of testing this head.

Could you also pin REPO first in NEMO_GYM_EXTRA_ROOTS, which the resolver preserves ahead of inherited paths? Add this entry to the subprocess environment mappings in _start() and both backend launches, retaining the new PYTHONPATH handling:

"NEMO_GYM_EXTRA_ROOTS": os.pathsep.join(
    part for part in (str(REPO), os.environ.get("NEMO_GYM_EXTRA_ROOTS", "")) if part
),

Preserve unrelated inherited dependencies and extra roots; only the reviewed checkout must win component-name collisions.

Proposed acceptance checks: launch through the harness with an inherited directory containing a distinguishable older component and an unrelated helper. Assert that nemo_gym, responses_api_agents.simple_agent.app, and responses_api_models.vllm_model.tar_audio resolve under REPO, while the helper remains importable. Retain the empty-PYTHONPATH case and run the existing two-worker test_native_episode_continues_from_its_last_boundary_after_a_crash cases, preserving reward 1.0 and message counts [2, 4, 4]. These checks weren't executed.

[kept] = second
assert response.json()["reward"] == 1.0
assert verified == {kept}
assert not any((deployment.work_dir / "gym-state").rglob("*/snapshots/*/*")), "the index is empty"

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.

RISK — Wait for the index cleanup, not just the backend deletion.

The preceding poll can observe an empty snapshot service while this assertion still sees an index file. _delete_snapshot() deletes the remote snapshot first, then awaits asyncio.to_thread(index.unmark, ...). The fake backend exposes the deletion before that thread finishes. A delayed unmark therefore makes this test fail despite correct release behavior; release explicitly permits background cleanup.

Could you add this wait immediately after the empty-service poll at line 1249?

await wait_until(
    lambda: not any((deployment.work_dir / "gym-state").rglob("*/snapshots/*/*"))
)

The invariant is eventual deletion of both the backend snapshots and their index files, not simultaneous visibility. Keep the assertions that dropping c1 retains only c2, verification alone retains c2, and the rollout receives reward 1.0.

Proposed acceptance check: delay index unmarking after a successful backend delete. The scenario should wait and pass once the file disappears, but time out if it never disappears. Retain verified == {kept} before the final release. This is source reasoning, not an executed result.

expected_files = (
{s: list(files) for s, files in committed_files[index].items()} if fresh.session_ids else {}
)
except (SandboxCheckpointError, RuntimeError) as error:

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.

RISK — Distinguish injected faults from unexpected failures.

This catch accepts every RuntimeError, including every SandboxCheckpointError, without checking whether the chaos provider caused it. If export() unexpectedly raises RuntimeError("unexpected") on every call, each export is logged as an acceptable fault, committed stays empty, and the final restore loop has nothing to check. The test can pass despite export being completely broken, even with fault_rate == 0. The inner restore catch similarly accepts unexplained restore failures.

Could you give injected failures a dedicated type and accept only that type, directly or through the exception cause? For example, add:

class ChaosFault(RuntimeError):
    pass


def is_chaos_fault(error: BaseException | None) -> bool:
    while error is not None:
        if isinstance(error, ChaosFault):
            return True
        error = error.__cause__
    return False

Raise ChaosFault instead of RuntimeError in ChaosProvider._maybe_fail(). Change the inner catch to except SandboxCheckpointError as error and the outer catch to except (SandboxCheckpointError, ChaosFault) as error; start both handlers with:

if not is_chaos_fault(error):
    raise

The inspected snapshot wrappers and fork wrapper preserve causes. This keeps expected injected create, snapshot-readiness, and close failures acceptable while making unexplained contract failures fail the test. Keep the existing rollback, live-session, snapshot-index, and byte-equal restore assertions after accepted faults.

Proposed acceptance checks: with faults disabled, an unexpected RuntimeError from export and an unexplained SandboxCheckpointError from restore must fail the sequence test. Direct ChaosFault from create and wrapped ChaosFault from snapshot/fork failure must remain accepted and still reach the invariant checks. No tests were executed.

This branch was previously deployed

1 inactive deployment
public — 20485ac8 Deployed Nov 13, 2026 by copy-pr-bot[bot] via release / finalize / notify #12199
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:sandbox Sandbox providers, isolation, and sandbox runtime contracts ci CI, automation, test queue, or workflow infrastructure work complexity:high Cross-component or shared-contract change with a large review surface needs-review PR is ready for code review and waiting on a reviewer 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.

4 participants