Skip to content

refactor(checkpoint): move rollout checkpointing out of the single controller - #5011

Merged
terrykong merged 23 commits into
mainfrom
amahishi/rollout-checkpointer
Nov 6, 2026
Merged

terrykong merged 23 commits into
mainfrom
amahishi/rollout-checkpointer

Conversation

@macandro96

@macandro96 macandro96 commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Moves rollout checkpointing out of SingleControllerActor into one package, nemo_rl/algorithms/rollout_checkpointing/, and moves the Gym checkpoint code behind a small environment checkpoint interface in nemo_rl/environments/checkpointing/. Behavior is unchanged.

Builds on #4500 (Gym turn-level rollout recovery, now merged into main). This is an alternative to #4879: the same goal with concrete classes and no abstract layers.

Why

By the time turn-level recovery with NeMo Gym landed, the controller held about 30 checkpoint and recovery methods (~1,700 lines), and:

  • trainer checkpoints and rollout snapshots each built, validated and saved the same rollout state in their own copy;
  • the controller built the Gym coordinator, retired and forgot Gym episodes, parsed Gym's manifest, and branched on whether Gym was present;
  • the rollout pump kept two copies of its dataloader loop and spare-pool drain, one recording prompt groups in the recovery ledger and one not.

Layout

nemo_rl/algorithms/rollout_checkpointing/
    state.py        RolloutRuntimeState, CapturedRolloutState, ResumeSource,
                    TrainingProgress, RolloutParts
    inventory.py    TQ inventory checks run by both save and restore
    snapshots.py    RolloutSnapshotter: save lock, optimizer-commit window,
                    capture, snapshot pump, publication
    restore.py      RolloutRestorer: restore chain, prompt rehydration, redispatch
    manifest.py     snapshot manifests, anchors, publication, retention
                    (moved from single_controller_utils/rollout_checkpoint.py)

nemo_rl/environments/checkpointing/
    interfaces.py   EnvironmentCheckpoint / EnvironmentSnapshot (Protocols),
                    NoEnvironmentCheckpoint, EnvironmentEpisode
    nemo_gym.py     GymEnvironmentCheckpoint
    __init__.py     build_environment_checkpoint

single_controller.py goes from 6,688 to 4,714 lines. The full design, including every call the controller makes into the package, is in docs/design-docs/single-controller-rollout-checkpointing.md.

Commits

Each commit can be reviewed on its own, and each passes ruff, pyrefly and the unit tests.

  1. refactor(checkpoint): one shared capture for trainer checkpoints and rollout snapshots.
  2. refactor(single-controller): shared rollout state in one RolloutRuntimeState.
  3. refactor(checkpoint): Gym checkpoint code moves behind EnvironmentCheckpoint.
  4. refactor(checkpoint): rollout snapshots move into RolloutSnapshotter.
  5. refactor(checkpoint): the restore chain moves into RolloutRestorer.
  6. refactor(single-controller): one rollout-pump dispatch path, with and without the ledger.
  7. refactor(checkpoint): what the run resumed from is passed as one ResumeSource.
  8. test(checkpoint): drops duplicated checkpoint test scaffolding.
  9. refactor(checkpoint): backend-neutral names in the recovery ledger. On-disk keys (gym_instance_id, gym_attempt) and the schema version are unchanged, so existing checkpoints restore.
  10. docs(checkpoint): the design doc, plus metrics docs updated to name the new methods.
  11. refactor(checkpoint): restore stops repeating the replay checks setup already made on the same checkpoint; removes RolloutSnapshotter._call_dp (unused) and moves bootstrap_fingerprint (test-only) into the tests.
  12. test(checkpoint): one shared builder for the Gym environment checkpoint and its stand-ins in tests, instead of 2–4 copies.
  13. refactor(checkpoint): the Gym coordinator cleans up a failed restore in one place (restore() no longer hand-copies retire_restored()).
  14. refactor(checkpoint): drops three Gym commit checks that cannot fail, because the adapter, the caller or the manifest already make them.

Compatibility

  • Checkpoint format, schema versions, telemetry keys (including the gym_unavailable reason) and log lines are unchanged.
  • Covers everything feat(checkpoint): add Gym turn-level rollout recovery #4500 added: the Gym task index, an always-written spare-prompt pool (required from schema 5), the inventory check before and after restart normalization, the forest-training metadata checks, and deferred checkpoint finalize.

Testing

  • Rollout-checkpointing unit tests (tests/unit/single_controller, plus the recovery, rollout-manager and Gym checkpoint tests): 2,096 passed in the default lane and 97 in the Gym lane on the final commit, rebased on main after feat(checkpoint): add Gym turn-level rollout recovery #4500 merged.
  • Broader sweep of tests/unit/single_controller, tests/unit/experience, tests/unit/environments (run before commits 11–14): 3,189 passed in the default lane and 623 in the Gym lane (--nemo-gym-only). The only failures come from the test container and are in code this PR does not touch: a reward-model Ray worker venv that won't start, and two Gym tests that start real vLLM workers.
  • New: tests/unit/environments/test_gym_environment_checkpoint.py tests the Gym checkpoint directly. Tests that build a controller without __init__ attach the snapshotter and restorer through tests/unit/single_controller/_rollout_checkpoints.py.

Size

Against main: source +3,403 / −2,553 (net +850), tests +2,072 / −1,562 (net +510), docs +246 / −4.

🤖 Generated with Claude Code

@copy-pr-bot

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

@github-actions github-actions Bot added the Documentation Improvements or additions to documentation label Nov 1, 2026
@macandro96
macandro96 force-pushed the amahishi/rollout-checkpointer branch from eb3468c to 1da4782 Compare November 1, 2026 04:05
@macandro96
macandro96 force-pushed the amahishi/rollout-checkpointer branch from 1da4782 to 199cdf5 Compare November 2, 2026 19:18
Base automatically changed from amahishi/gym-turn-recovery-pr1 to main November 2, 2026 20:50
@macandro96
macandro96 added this pull request to stack #5031 November 2, 2026 22:23
@macandro96
macandro96 removed this pull request from stack #5031 November 2, 2026 22:49
@macandro96
macandro96 added this pull request to stack #5032 November 2, 2026 22:50
@macandro96
macandro96 force-pushed the amahishi/rollout-checkpointer branch from 199cdf5 to 7171e5d Compare November 2, 2026 22:56
@macandro96
macandro96 requested a review from terrykong November 2, 2026 23:12
@macandro96 macandro96 added the CI:L1 Run doctests, unit tests, and functional tests label Nov 2, 2026
@macandro96
macandro96 removed this pull request from stack #5032 November 3, 2026 23:39
@macandro96
macandro96 added this pull request to stack #5057 November 3, 2026 23:39

@terrykong terrykong left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This PR conflicts with main and needs a rebase before it can merge.

Thanks for the careful move. The 27+ methods that left single_controller.py match their base versions apart from renames: lock order, restore order, the no-ledger pump path and the on-disk keys all line up. The two "drop checks" commits (c1cdd3c, 7171e5d) only remove checks that setup or the adapter already make. The 16 changed test files pass on CPU (1,233 passed, no failures from this PR; the Ray-cluster and triton tests were not run). single_controller.py goes from 6,688 to 4,714 lines.

Size: for a move that keeps behavior the same, the PR still adds about 850 source lines and 510 test lines net. The growth is in the new layers (the 181-line state.py, the two Protocols, headers and imports for the 8 new files, the 99-line test helper), not in the moved code. The size comments below (C3, C5, C6, C7, C8, C9, C10) trim about 130 lines. Later PRs in the stack build on whatever shape lands here, so please keep each one close to the smallest change that does the job.

  1. (C3) Move the rollout-checkpointing wiring in __init__ into one actor method so the test helper calls it instead of copying it (~25–30 test lines).
  2. (C5) Nit: merge validate_cut into check_against_cut (~6 lines).
  3. (C6) Drop the design doc's call table and member table (~25 lines).
  4. (C7) Delete a test that now only checks a bare return None (~10 lines).
  5. (C8) Inline two one-call test helpers (~20–25 lines).
  6. (C9) Cut the refactor history and the future-work list from the design doc; keep it to the classes, layout and how to extend it (~30 lines).
  7. (C10) Nit: delete the package __init__.py docstring that only lists modules and already misses manifest.py (~8 lines).
  8. (C11) Nit: name what restore actually restores instead of "the rollout state" (replay index, recovery ledger, spare prompts, turn-level environment rollouts; not the TQ rows).

No action needed: commit ca9d89e changes two failure-path details. Cleanup of a failed Gym restore now catches Exception instead of BaseException, and the retire step's operation name changes from "restore_retire" to "retire". Both are harmless; the description's "behavior unchanged" could mention them.

Visual explainer: https://terrykong.github.io/gh-pages-poc/terryk/pr-5011-size-and-reuse.html
Visual explainer: https://terrykong.github.io/gh-pages-poc/terryk/pr-5011-how-it-fits.html

Generated by Claude Code

macandro96 and others added 12 commits November 5, 2026 10:22
…nd rollout snapshots

The full trainer checkpoint and the rollout snapshot each built the replay
metadata, validated the replay and staging inventories, built, serialized
and hashed the recovery ledger, saved TQ and wrote the same sidecar files,
in two copies. Both now call _capture_rollout_state(cut, path, kind) under
their exclusive cut and write sidecars through _write_controller_sidecars.

The kind keeps the real differences:
- a trainer checkpoint saves TQ only with checkpointing.save_data_plane,
  refuses rows a streamed step still owns, saves replay metadata only for a
  sampler that restores buffered groups, and the ledger only while dispatch
  records prompt groups;
- a rollout snapshot always saves all three and re-indexes training-owned
  rows into the persisted cut.

Behavior is unchanged. Two details move within the exclusive cut: the
trainer checkpoint reads the dataloader state and spare pool after
init_tmp_checkpoint rather than before it, and rollout snapshots write
sidecars with the MSC-aware save helpers trainer checkpoints already used
(torch.save for local paths, as before).

single_controller.py: +127 / -183. Tests: one call site renamed.
Unit: 2048 passed (default lane), 98 passed (Gym lane), as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
…RuntimeState

The spare-prompt pool, the per-step shortfall, whether the sampler stamps
target steps, and the retained finalizer metrics and rewards were five
separate controller attributes that the pumps change, checkpoints save and
restore fills. They now live in one RolloutRuntimeState the controller owns
as self._rollout_runtime, so the checkpoint code extracted next can read and
fill one object instead of five controller fields.

Behavior is unchanged: every access is renamed, and a field that was
reassigned (restore's shortfall and finalizer dicts, the train pump's
shortfall rebuild) is now reassigned on the shared object. The per-field
comments move onto the dataclass.

Test fixtures that build the controller with object.__new__ create a
RolloutRuntimeState only where a test reaches these fields (22 fixtures),
and drop the lines that reset a field to its default. The pump tests'
_init_pump_ledgers helper creates one when its controller has none.

single_controller.py: +103 / -69. Tests: +120 / -79.
Unit: 2048 passed (default lane, all of tests/unit/single_controller plus
the rollout-recovery, rollout-manager and Gym-checkpoint suites), 98 passed
(Gym lane), as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
…checkpoint interface

The controller built the Gym checkpoint coordinator, owned Gym's dispatch
gate, retired and forgot Gym episodes, drained on-wire replies, validated
the Gym manifest against the TQ cut, parsed gym_checkpoint.json on restore,
and branched on whether a Gym coordinator existed. All of it moves behind
EnvironmentCheckpoint:

- nemo_rl/environments/checkpointing/interfaces.py: the backend-neutral
  contract (check_startup, snapshot, restored, is_unavailable,
  holds_rollout_state) and NoEnvironmentCheckpoint for backends that keep
  no rollout state;
- nemo_rl/environments/checkpointing/nemo_gym.py: GymEnvironmentCheckpoint,
  wrapping the existing coordinator, adapter and checkpoint format;
- nemo_rl/environments/checkpointing/__init__.py: picks the backend once,
  from rollout_recovery.turn_checkpointing_enabled, as before.

The controller now pauses, snapshots, validates and restores the
environment only through that interface.

Behavior is unchanged, including telemetry: the snapshot outcome reason for
a briefly unreachable environment keeps its old name, gym_unavailable, so
existing dashboards keep working. Error and warning texts that named Gym in
the controller now come from the Gym module.

Tests that exercised only the Gym checkpoint, through a bare controller,
move to tests/unit/environments/test_gym_environment_checkpoint.py and
build GymEnvironmentCheckpoint directly. New builder tests cover the
backend choice, the dispatch gate installed on the rollout manager, and
the staging partition the Gym checkpoint lists.

Source: +867 / -530. Tests: +1203 / -980.
Unit: 2050 passed (default lane; 2048 as before plus the 2 builder tests),
98 passed (Gym lane). ruff and pyrefly clean.

Co-authored-by: Terry Kong <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
…ting package

The controller held the save lock shared by trainer checkpoints and rollout
snapshots, the optimizer-commit window snapshots skip, the snapshot pump,
the TQ capture and sidecar writer, outcome telemetry and warnings, and
eight fields of snapshot state. All of it moves into a package:

  nemo_rl/algorithms/rollout_checkpointing/
      state.py      runtime and captured state, TrainingProgress, and
                    RolloutParts: the controller parts it reads
      inventory.py  TQ inventory checks, which restore (still in the
                    controller) runs too
      snapshots.py  RolloutSnapshotter: save lock, optimizer-commit
                    window, capture, snapshot pump and publication
      manifest.py   snapshot manifests, anchors, publication and
                    retention (moved from single_controller_utils/
                    rollout_checkpoint.py)

The controller builds RolloutParts once and calls the snapshotter:
- run() and stop_requested in _run_pumps;
- begin_optimizer_commit(drain_snapshot=...) and end_optimizer_commit()
  where the train pump opened and closed the window;
- trainer_checkpoint() in place of the save lock, around a trainer
  checkpoint's save and around a deferred save's publish;
- trainer_checkpoint_published() where the controller woke the snapshot
  pump once a trainer checkpoint was published, which it still does only
  when the environment holds rollout state;
- capture() and write_controller_sidecars() in _save_checkpoint_impl.
capture() also records the trainer checkpoint's TQ mutation version, which
_save_checkpoint_impl used to do.

The snapshotter reads training counters through a read_progress callback,
never controller fields. save_snapshot names its two phases:
_resolve_anchor (bootstrap or step_<N> anchor, or a skip when it is not
durable yet) and _publish (sidecars, config and manifest, then the atomic
commit under retention). manifest.py imports MasterConfig for annotations
only, because single_controller_utils, whose setup imports it, would
otherwise import it back.

Behavior is unchanged: the window, lock and wakeup open and close at the
same points, telemetry keys and log lines are the same, and the anchor
phase reads the training counters once where the old code read them
several times with no await in between.

Tests reach the moved state through controller._rollout_snapshots.
Controllers built without __init__ get one from
tests/unit/single_controller/_rollout_checkpoints.py, and tests that swap
the environment checkpoint rebuild it, as __init__ would.

Source: +1355 / -920 (single_controller.py 6232 -> 5403 lines; package
1932 lines including the 676-line manifest module that moved in).
Tests: +250 / -102.
Unit: 2050 passed (default lane), 98 passed (Gym lane), as before.
ruff and pyrefly clean; each new module imports on its own.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
Replay-buffer restore, recovery-ledger restore (including the environment
restore scope), spare-prompt restore, prompt rehydration, the sampler
cursor check, restore metrics and the redispatch of restored groups move
from the controller into RolloutRestorer in
nemo_rl/algorithms/rollout_checkpointing/restore.py.

It is built from the same RolloutParts as the snapshotter; the two halves
share only those read-only inputs and never call each other. The controller
now calls:
- restore() once in _run_pumps, after the weight sync, in place of the
  five-call chain. It fills the shared RolloutRuntimeState directly and
  takes one replay-capacity permit per restored group, at the same point
  as before; it returns whether restore queued groups only ledger-recorded
  dispatch can launch, and the controller then turns that dispatch on;
- redispatch_restored(launch, admit) from the rollout pump, passing its
  launch and sampler-admission callbacks.

The restore-only controller fields are gone; the restorer gets the
resumed checkpoint's path, kind, TQ metadata and load timings from setup,
and owns the queue of replay groups to regenerate. Reading and verifying
the recovery-ledger sidecar is a plain function, read_recovery_sidecar.
Method names drop the controller's _maybe_ prefixes.

Behavior is unchanged. The only reordering: ledger dispatch is now turned
on when restore() returns rather than inside it, and no restore step reads
it.

Tests drive restore through controller._rollout_restorer; tests that
build the controller without __init__ attach it from the controller's
parts, carrying the restore inputs.

Source: +868 / -733 (single_controller.py 5403 -> 4716 lines;
restore.py 820 lines). Tests: +178 / -53.
Unit: 2050 passed (default lane), 98 passed (Gym lane), as before.
ruff and pyrefly clean.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
…h path

The rollout pump kept two copies of the dataloader loop and of the
end-of-run spare-pool drain, one recording each prompt group in the
recovery ledger and one not, and branched on _rollout_recovery_enabled in
seven places across the pump, the drain, the stale-group abort and the
finalizer's drop path.

Each now exists once. Three small helpers make the difference in one place:
- _dispatch_reservation(kind) holds a data-plane mutation cut, counted as
  kind, only with ledger dispatch; otherwise it takes no mutation slot and
  yields None;
- _reserve_prompt_group / _discard_prompt_group record in the ledger under
  that cut, or do nothing without one (the rollout manager then mints the
  group ID, as before);
- _admit_step admits a step through the sampler: the ledger's transactional
  admission with ledger dispatch, the sampler's own admit() otherwise.

Ledger dispatch is unchanged: the same mutation kinds over the same
statements, with no await moved inside a cut. Without it, three small
differences, none of which changes what is trained:
- the end-of-run drain now marks the sampler as stamping target steps when
  it stamps, as the dataloader loop always did; the flag only gates
  diverting batches into the spare pool, and the drain runs after the last
  epoch;
- a dropped prompt's replacement borrows from a later step before the
  "substituting a spare prompt" log line rather than after it, so the
  line names the step the spare commits to, as it did with the ledger;
- a prompt with no spare left credits its step short just before, rather
  than just after, releasing its replay-capacity permit; nothing awaits
  in between.

New test: unrecorded dispatch takes no mutation slot and records nothing.

single_controller.py: +123 / -128 (4716 -> 4711 lines). Tests: +49.
Unit: 2051 passed (default lane; 2050 as before plus the new test),
98 passed (Gym lane). ruff and pyrefly clean.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
RolloutRestorer took the resumed checkpoint as four separate
arguments: its path, whether it is a rollout snapshot, its native TQ
metadata and setup's load timings. They always travel together and only
restore reads them, so they become one frozen ResumeSource whose defaults
describe a fresh run.

Behavior is unchanged.

Tests set controller._resume = ResumeSource(...) instead of four
controller fields, and the test helper reads that one value instead of
a table of field names with fresh-run fallbacks.

Source: +41 / -44. Tests: +115 / -105; roughly line-neutral because a
ResumeSource call wraps over more lines than the assignments it replaces.
Unit: 2051 passed (default lane), 98 passed (Gym lane). ruff and pyrefly
clean.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
- One test helper attaches rollout checkpointing to a controller made
  without __init__. bare_rollout_snapshotter() is gone; its four callers
  use attach_rollout_checkpointing(controller), which already tolerates
  missing parts, and now also a rollout-manager stand-in without a ledger.
- The four staging-inventory tests call validate_rollout_recovery_inventory
  through one _validate_staging helper instead of each building a bare
  controller, a ledger and an event loop. Their assertions are unchanged.

The two Gym-phase tests that look alike are kept: one drives the phase
directly and is the only check that Gym's dispatch gate reopens after a
committing step stops it; the other runs a whole snapshot save and checks
its result, that nothing is published, and that an earlier commit does
not stop it.

Tests: +53 / -124 (-71). No test removed.
Unit: 2051 passed (default lane), 98 passed (Gym lane). ruff and pyrefly
clean.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
The recovery ledger and the rollout manager still named the environment's
rollouts after Gym, and the ledger imported its episode type from the Gym
adapter. They now use neutral names:
- the ledger's queries and updates are environment_inventory,
  environment_retirements / mark_environment_retired,
  environment_forgets / mark_environment_forgotten and
  environment_episodes_still_held; prepare_for_restart takes
  continued_attempts;
- attempt records carry environment_instance_id, environment_attempt and
  holds_environment_state, and a group's environment_episode() returns an
  EnvironmentEpisode;
- EnvironmentEpisode lives in environments/checkpointing/interfaces.py,
  and the Gym adapter's GymCheckpointEpisode is an alias of it;
- the rollout manager's checkpoint-owner argument is
  environment_instance_id; the Gym rollout implementation keeps its own
  gym_instance_id.

The on-disk ledger keys keep their names (gym_instance_id, gym_attempt)
and the schema version is unchanged, so existing checkpoints restore.
Telemetry keeps the gym_unavailable reason.

Behavior is unchanged. The environment interface stays a Protocol; the
abstract-class conversion that came with these renames in #4879 is not
taken.

Source: +253 / -199. Tests: +150 / -133.
Unit: 2051 passed (default lane), 98 passed (Gym lane); the 29 forest
dispatch tests pass in the Gym lane. ruff and pyrefly
clean.

Co-authored-by: Terry Kong <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
Add docs/design-docs/single-controller-rollout-checkpointing.md: why
rollout checkpointing left the controller, the package layout, every call
the controller makes into RolloutSnapshotter and RolloutRestorer, the
shared runtime state, the save and restore sequences, dispatch with and
without the recovery ledger, the environment checkpoint interface, rules
for new code, where the tests live, and the open items.

docs/observability/metrics.md named the controller methods that built the
rollout checkpoint and recovery metrics; it now names the
RolloutSnapshotter and RolloutRestorer methods that build them.

Add the page to the design-docs toctree in docs/index.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
…d code

Setup loads the native TQ checkpoint from the same path the restorer later
reads, before the restorer runs, on both the driver and the in-actor
(Mooncake) route. It already rejects a legacy replay_buffer.pt, warns when
there is no replay metadata, and requires a non-empty manifest digest and
a non-negative group count. RolloutRestorer repeated those checks; it now
keeps only what setup cannot see: that the replay metadata file it loads
holds as many groups as the TQ checkpoint recorded.

Also removed:
- RolloutSnapshotter._call_dp, which nothing called;
- manifest.bootstrap_fingerprint, which only tests called; it is now a
  helper in test_rollout_checkpoint.py.

Tests: the restore-side legacy-file and missing-digest tests covered only
the removed copies. The legacy check already has a setup test; the digest
and group-count checks get one (four cases), which they lacked.

Source: +8 / -45. Tests: +35 / -48.
Unit: 2053 passed (default lane), 98 passed (Gym lane). ruff and pyrefly
clean.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
…helper

Four helpers were copied across the Gym checkpoint tests:
- a staging-key lister that returns nothing (3 copies);
- a rollout-manager stand-in that pauses request deadlines (2 copies);
- a GymEnvironmentCheckpoint builder (4 variants);
- a context manager that yields one snapshot's Gym commit (2 copies).

They now live once in tests/unit/environments/gym_checkpoint_fakes.py, next to
the fake Gym actor they wrap, as no_staging_keys, deadline_pausing_manager,
gym_environment_checkpoint and snapshot_commit. A change to
GymEnvironmentCheckpoint's constructor now touches one test helper.

Line-neutral (tests +145 / -148). No test changed what it checks.
Unit: 2053 passed (default lane), 98 passed (Gym lane). ruff clean.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
macandro96 and others added 8 commits November 5, 2026 10:24
The test helper attach_rollout_checkpointing rebuilt RolloutParts,
RolloutSnapshotter and RolloutRestorer field by field: a second copy of
the actor's wiring, whose getattr defaults kept tests passing if the two
drifted apart. SingleControllerActor._build_rollout_checkpointing now
builds and returns both, called from __init__ and from the helper, which
only stands in for parts a bare controller lacks. A part the actor starts
reading now fails these tests instead of passing on a default.

Review comment C3. Unit: the 5 files that use the helper, 416 passed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
GymEnvironmentSnapshot.check_against_cut only forwarded to
GymEnvironmentCheckpoint.validate_cut, handing back the commit and path the
snapshot already holds. The body now lives in check_against_cut and
validate_cut is gone. Its five tests enter gym.snapshot() and call
check_against_cut, the entry point the snapshotter uses.

Review comment C5. Unit: test_gym_environment_checkpoint.py passed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
The design doc's call table named private controller methods, so every
controller refactor had to edit it, and its member table repeated the
EnvironmentCheckpoint docstrings. Both are replaced by pointers to the
snapshotter, restorer and interfaces.py docstrings.

Review comment C6.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
Once the restart-only check left the controller, this test built a bare
controller, discarded it and called NoEnvironmentCheckpoint.check_startup(),
which cannot fail. The builder test still checks that a run without
turn-level recovery gets NoEnvironmentCheckpoint. Dropping the test also
drops the controller import from this environments test.

Review comment C7.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
_controller_for had one caller, which passed only defaults, and
_gym_environment_for wrapped a single gym_environment_checkpoint call at
two sites. Both are inlined.

Review comment C8. Unit: test_checkpoint_dispatch_races.py, 33 passed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
Drops the refactor history and the Open Items list, which go stale once
this merges. The one rule from Open Items that binds a new backend, that
EnvironmentEpisode's row key format is Gym's, moves to The Environment
Interface.

Review comment C9.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
It already missed manifest.py, and each module and the design doc's
Layout section list the same modules. Sibling packages carry none.

Review comment C10.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
"The rollout state" did not say what restore() brings back. The module
docstring now names the replay index, the recovery ledger, the spare-prompt
pool and, at turn level, the environment's rollouts, and notes that setup
restores the TQ rows first.

Review comment C11.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
@macandro96
macandro96 force-pushed the amahishi/rollout-checkpointer branch from 7171e5d to c5c91c8 Compare November 5, 2026 19:21
terrykong
terrykong previously approved these changes Nov 5, 2026
@terrykong

Copy link
Copy Markdown
Collaborator

/ok to test c5c91c8

@terrykong terrykong added CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) and removed CI:L1 Run doctests, unit tests, and functional tests labels Nov 5, 2026
macandro96 added a commit that referenced this pull request Nov 6, 2026
- Check the failed abandon reason end to end in the rollout manager's failed
  dispatch test, and drop the test that only passed reason=cancelled through.
- Restore a recording ledger with _recording_ledger(from_ledger=...) instead
  of repeating the steps, and drop a disabled-trace test that could not fail.
- Assert the exact weight_version of each weights_synced event.

Review comments C8, C9 and C10. C11's line in the test helper is gone: the
helper now calls the actor's _build_rollout_checkpointing.

Unit, on #5011 rebased onto main: 3452 passed (default lane), 95 passed (Gym
lane, on the files this PR touches). ruff and pyrefly clean.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
@terrykong
terrykong enabled stacked auto-merge (squash) November 6, 2026 05:20
…e metrics

test_rollout_checkpoint_mapping_matches_logged_keys collects every rollout
save/restore key by parsing single_controller.py and setup.py for
_log_telemetry_metrics calls. This PR moved that logging into the
rollout_checkpointing package, which logs through _log_metrics, so the test
found no keys and failed in L0_Unit_Tests_Other.

- The test also parses rollout_checkpointing/*.py and accepts _log_metrics.
- ResumeSource.load_metrics is renamed rollout_checkpoint_load_metrics, the
  name setup.py gives the dict, so the test follows setup's restore timings
  (snapshot_resolution_seconds, tq_load_seconds) to where the restorer logs
  them.
- The test also reads the keys an environment backend returns from
  EnvironmentSnapshot.metrics(), which a snapshot merges into its log; Gym's
  gym_parked_seconds and gym_restarted_episodes are still logged and mapped.

Unit, the L0_Unit_Tests_Other selection: 5444 passed. The 6 failures are the
gated Llama flops-counter tests, which need Hugging Face access this machine
lacks; this PR does not touch them. ruff and pyrefly clean.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
@macandro96

Copy link
Copy Markdown
Contributor Author

/ok to test d96aa1e

macandro96 added a commit that referenced this pull request Nov 6, 2026
- Check the failed abandon reason end to end in the rollout manager's failed
  dispatch test, and drop the test that only passed reason=cancelled through.
- Restore a recording ledger with _recording_ledger(from_ledger=...) instead
  of repeating the steps, and drop a disabled-trace test that could not fail.
- Assert the exact weight_version of each weights_synced event.

Review comments C8, C9 and C10. C11's line in the test helper is gone: the
helper now calls the actor's _build_rollout_checkpointing.

Unit, on #5011 rebased onto main: 3452 passed (default lane), 95 passed (Gym
lane, on the files this PR touches). ruff and pyrefly clean.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
@terrykong
terrykong disabled stacked auto-merge November 6, 2026 16:06
@terrykong
terrykong enabled stacked auto-merge (squash) November 6, 2026 18:27
stacked auto-merge was automatically disabled November 6, 2026 18:29

Replaced by a newer auto-merge request

@terrykong
terrykong enabled stacked auto-merge (squash) November 6, 2026 18:29
@terrykong
terrykong merged commit 38a9155 into main Nov 6, 2026
96 checks passed
@terrykong
terrykong deleted the amahishi/rollout-checkpointer branch November 6, 2026 19:36
bg51717 added a commit that referenced this pull request Nov 8, 2026
Main moved rollout checkpointing into nemo_rl/algorithms/rollout_checkpointing
(#5011). Step padding handling of the replay inventory check now lives in
rollout_checkpointing.inventory.validate_replay_inventory, called from the
restorer ("clear") and the snapshotter ("allow"). Forest's estimator check
keeps main's new seq_logprob_error_in_loss rejection.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: bg51717 <[email protected]>
macandro96 added a commit that referenced this pull request Nov 10, 2026
- C26: forest training keeps a restored cut on the rebuilt admission and
  serves it, so a restored prefix is spliced instead of regenerated.
- C27: allow_restart_only_gym_servers applies to target_level prefix too;
  the restart-only refusal names both levels.
- C29: completed-call evidence is kept only while generation cuts are on.
- C30: replace the snapshot fence with a retired-row list. A call's
  terminal write only retires its chunk rows; each snapshot first deletes
  the rows retired before it (flush_obsolete_generation_cut_rows, epoch
  guarded) and waits for the delete, so no clear overlaps the TQ save.
- C31: drop the per-reason uncut counters; each cut that leaves calls
  uncut logs one INFO line with the reasons.
- C32: document what prefix cannot cut or does not support.
- C33: build test workers through _init_token_capture_state instead of a
  hand-copied SimpleNamespace; the mixin calls become plain self calls.
- C34: decide the seed blocker with vLLM's SamplingType.RANDOM_SEED, and
  drop the presence/frequency-penalty blockers the chat route refuses.
- C35: the progress-read patch refuses a vLLM without its hooks and marks
  the wrapped OutputProcessor so a second client cannot wrap it again.
- C36: unit-test the restored-terminal classifier and the serving path's
  prompt, max_tokens and min_tokens for a restored call.
- C37: sort the hosting test imports.
- C38: drop the unreachable prefix-without-turn check.
- C44: test the Megatron prefix refusal through setup and directly.
- C46: type the generation and data-plane handles.
- C47: read the sampled logprob from each flat position's first slot and
  share extract_generation_logprobs with chat_generation_tokens.
- C50: pin, in a vLLM-lane test, that truncate_prompt_tokens applies only
  while the chat is tokenized, before the restore splice.
- C54: a vLLM-lane test pins the release and every private vLLM field the
  progress read and cut checks rely on.

Also fix test_rollout_recovery's mark_group_dispatched call for #5011's
environment_instance_id rename.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) Documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants