Moving rollout checkpointing out of the controller: 1,974 lines left, 2,856 arrived โ€” where the extra 882 come from

NVIDIA-NeMo/RL #5011, part 1 of 11 in the partial-checkpointing stack. All permalinks pin the PR head 7171e5d; removed code is linked at the base d3d22f1.

Before
Saving and restoring rollouts lived inside the single controller, a 6,688-line class, next to its Gym-only branches.
This PR
Moves that code into two new packages, with the same behavior. The controller drops to 4,714 lines. Source grows by about 850 lines and tests by about 510.
Status
Cuts proposed, not in the PR. The review found no bugs. The cuts below are review asks (C3, C5โ€“C10). Nothing here has been run.

Two pages on this PR, one question each. This one: how much the PR adds and what can go.

The move itself is careful. Each of the 27 methods that left single_controller.py was compared with its new home, and the differences are renames. The extra lines are not in the moved code. They are in what the move added around it: eight new files, each with its own license, docstring and imports; two Protocol classes with only one real implementation; a 99-line test helper that rebuilds the controller's setup; and a design doc that lists private methods.

What stayed the same

sameLock order around a save, the optimizer-commit window, and restore order (replay โ†’ ledger โ†’ spare prompts โ†’ loader place).
sameOn-disk checkpoint keys (gym_instance_id, gym_attempt) and schema version, so old checkpoints restore.
sameTelemetry keys, including gym_restarted_episodes and the gym_unavailable reason.
sameChecks that two commits drop: setup or the Gym adapter already makes each one on the same checkpoint.
sameTests: every removed test moved or went with a duplicate check. 1,233 changed CPU tests pass; the Ray-cluster and triton ones were not run.

Lines per new file, and what each review comment removes

left the controller file header: license, docstring, imports code removed by a review comment (about) 100 px = 400 lines source single_controller.py โˆ’1,974 โ€ฆ/snapshots.py 897 โ€ฆ/restore.py 784 โ€ฆ/checkpointing/nemo_gym.py 556โˆ’6 C5 โ€ฆ/checkpointing/interfaces.py 201 โ€ฆ/state.py 181 โ€ฆ/inventory.py 161 two __init__.py files 76 rollout_recovery.py (net) +34gym โ†’ environment renames tests and docs test_gym_environment_checkpoint 1,054โˆ’10 C7 test_checkpoint_dispatch_races โˆ’836 netโˆ’22 more ยท C8 _rollout_checkpoints.py (new) 99โˆ’27 C3 design doc (new) 241โˆ’25 C6, โˆ’30 C9 New source files: 2,856 lines, of which 450 are file headers. 2,856 โˆ’ 1,974 = 882 more source lines than before. The 1,054-line test file is mostly moved: 27 of its 29 tests came from test_checkpoint_dispatch_races.py.
So what. The move is right and the review found no bugs. The size is the issue: a move that keeps behavior the same still adds about 850 source and 510 test lines, and the next 10 PRs build on this shape. The comments trim about 130 lines: the copied setup code in the test helper (C3), a pass-through method (C5), the private-method table in the doc (C6), a dead test (C7), duplicate test builders (C8), the doc's history of the refactor and its list of future refactors (C9), and a module list in a package docstring that is already out of date (C10). One is about clarity, not size. C11: the restore docstrings say "the rollout state" without naming the four parts restored, and setup restores the TQ rows separately.

C3 โ€” _rollout_checkpoints.py:32 C5 โ€” nemo_gym.py:131 C6 โ€” design doc:72 C7 โ€” gym checkpoint test:984 C8 โ€” races test:294 C9 โ€” design doc:14 C10 โ€” rollout_checkpointing/__init__.py:15 C11 โ€” restore.py:15