Repository navigation
feat(checkpoint): process-level evidence for resources-owned sandbox checkpoints, their release, and lease expiry - #4221
Conversation
4cdad0c to
83a4981
Compare
83a4981 to
9c0a2c7
Compare
5079259 to
ccb0e07
Compare
ccb0e07 to
3ab0e49
Compare
This comment has been minimized.
This comment has been minimized.
3ab0e49 to
8c08946
Compare
8c08946 to
97fe118
Compare
7ac7ed0 to
9aa96c1
Compare
9aa96c1 to
de90aec
Compare
a510ed9 to
33962e3
Compare
33962e3 to
aacbc7f
Compare
aacbc7f to
7eaa73a
Compare
7eaa73a to
2ba3f39
Compare
…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]>
2ba3f39 to
20485ac
Compare
|
/ok to test 20485ac |
|
/review |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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 FalseRaise 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):
raiseThe 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.
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
releasecall 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.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 asappend notes oneandread notes. A snapshot is a copy made asynchronously (Creating, thenReady) and kept until deleted, whatever its sandbox does afterwards, and creating a sandbox withsnapshot_idstarts 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.sandbox_notes_server/fake_sandbox_provider.py, registered asfake_remote) that talks to that service and renews the sandboxes it creates on the same lease the OpenSandbox provider uses.sandbox_notes_server) that resolves its provider through a named sandbox block, as the SWE-bench server does. Each session owns a sandbox. Theappend_notetool 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 toSandboxSessionCheckpointer: 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, andrelease_external_statedeletes the snapshots of checkpoints the controller dropped.sandboxtopology in the e2e deployment: the legacy/runrelay over Simple Agent and the notes server, withcheckpoint.state_dirin the suite's work directory so the index survives a crash, and thefake_remotesandbox block (sandbox_leaseadds a lease). Two fixes to the suite's harness come with it: spawned servers keep the inheritedPYTHONPATHafter 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).release([])empties the service and the index.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 thisA sandbox that moved on after the checkpoint
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 BWhere 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.pthombre/partial-ckpt-sandbox-core): the sandbox session checkpointer, thereleaseprotocol, the snapshot index, the OpenSandbox lease, and/sandbox_accesspthombre/partial-ckpt-sandbox-resources): this PRpthombre/partial-ckpt-sandbox-agent): the park request for long-running agent harnesses, with process-level evidencepthombre/partial-ckpt-sandbox-swebench): the sandbox owner base, with the SWE-bench resources server on itpthombre/partial-ckpt-sandbox-opencode): the harness driver, with the OpenCode agent on itpthombre/partial-ckpt-sandbox-capture): calls a checkpoint abandoned stay out of the capture ledgerIssue
No tracking issue; see #4220.
Validation
Run in the r3Run nemo-rl+Gym container on Slurm against this head, on
ananthsub/partial-ckpt-fault-tests4daebf2e4(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, includingtest_checkpoint_sandbox_sequences.py.ruff checkandruff format --check(ruff 0.9.9) clean on the changed files. Every commit carriesSigned-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