Skip to content

feat(orchestrator): take rollout checkpoint restore points off the publish barrier - #4829

Open
hallerite wants to merge 6 commits into
mainfrom
feat/rollout-ckpt-off-barrier
Open

hallerite wants to merge 6 commits into
mainfrom
feat/rollout-ckpt-off-barrier

Conversation

@hallerite

@hallerite hallerite commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

Summary

With ckpt.rollouts, a rollout checkpoint used to save every running rollout at the weight-publish barrier. All of that happened at the barrier: every env worker snapshotted its rollouts and held them, the orchestrator cut the open work, and then released them. The trainer waited in its broadcast, and inference was idle, until the slowest env worker pool replica answered.

On a production run with about 10k rollouts in flight:

  • The save took 1m39s.
  • With one slow replica out of 33, it took 8m55s. Training stalled for as long, and the replica still did not release its rollouts.
  • Writing the checkpoint's 170–340 GiB of training arrays then held the sink lock for another 1–2 min. That stalled collection.

This PR leaves only the cut on the barrier. The restore points are taken afterwards, while training and inference go on.

How it works

  1. The barrier only cuts. At the publish barrier of v{N}, the hook records the open work at one instant, as before: sink, queued results, cut batch, groups, in-flight episodes and progress. Each in-flight episode now carries its dispatch_id.
    • The hook pins every training array the cut references, on the env worker pool's sample server, then returns. The broadcast, training, inference and dispatch go on.
    • With the sink still locked, the orchestrator forks the writer of the open work once the hook has returned, then unlocks. The fork is off the barrier, but still sees the cut, since the episodes change only once the sink takes results again.
  2. Restore points come after the cut. Each replica gets the request_ids of the in-flight runs it holds. A worker saves each listed rollout with Rollout.save(hold=True) and releases it right after, so a rollout stops only while its own memory checkpoint is taken. A recent periodic checkpoint saves a snapshot.
    • At most 250 saves run per worker.
    • A rollout that is still booting, or in setup, is retried every 10 s.
  3. The next barrier is the deadline. The barrier of v{N+1} sends close_save to every replica still saving. It waits for their confirmation, bounded at 10 s, before inference receives v{N+1}.
    • A worker starts no memory checkpoint after the close. It drops any checkpoint whose capture started after the close, comparing against its own clock (Checkpoint.time.start).
    • So every token a restore point holds was sampled with v{N} or older. That is the policy a resumed run serves.
    • A replica that does not confirm the close gives the checkpoint none of its restore points.
    • Nobody waits for the snapshots themselves.
  4. Arrays are pinned instead of persisted under the sink lock. The orchestrator previously held the sink lock while it wrote the arrays.
    • With the in-memory store, a pin keeps references to the immutable blobs, so a DELETE from the trainer or the sink frees nothing until the pin is released. The RolloutStore hardlinks the files under pinned/<name>/ instead.
    • The arrays are written as of the cut (/persist with pin), then unpinned. The checkpoint contents are unchanged.
    • A pin expires after 30 min if its orchestrator dies.
  5. Completion. The checkpoint completes once the replicas have answered (or the reply budget after the close has run out), the arrays are written and the writer has exited. The orchestrator writes rollouts/restores.pkl (dispatch_id → RestoreRef), then progress.pt last. A resume picks the newest complete checkpoint, as before. Checkpoints written before this change load unchanged.

Requested checkpoints keep today's order. A checkpoint that a pause or checkpoint request asks for still snapshots and holds every running rollout, then cuts, then releases, while the trainer waits. A stopped run saves everything it saves today. The arrays are pinned there too, so the hook no longer waits for the cut batch's arrays to be written.

Coverage is observable

The checkpoint log gets a coverage line, and ckpt/rollouts/* gets these metrics:

Metric Meaning
listed rollouts in flight at the cut
restored restore points taken for them
missed/finished finished before their memory checkpoint
missed/deadline capture did not start before the close
missed/not_ready still booting or in setup at the close
missed/no_reply replica did not confirm the close or did not answer
missed/unsaveable cannot take a memory checkpoint, or the snapshot failed
time/barrier seconds the barrier spent on the checkpoint
time/window seconds the save was open

A high missed/deadline count means the save does not fit into one step.

Semantics to know

  • Restore points may hold v{N} tokens, not just v{N-1}. This is consistent: the resumed run serves v{N}, and the trainer at step N has trained on every batch up to N.
  • Coverage is lower than with the old barrier save:
    • A rollout that finishes between the cut and its own snapshot restarts on resume. The old hold prevented this.
    • A rollout whose capture has not started by the next barrier also restarts.
    • Production saves took 1.6–12.7 min against about 4.7 min per step, so at the slow end the deadline will cut coverage. The metrics above show by how much.
  • One checkpoint at a time. A checkpoint that is due while the previous one is still completing waits for it at its barrier. The previous save closed at the barrier before, so normally only seconds of replies and writing remain. With ckpt.interval = 1 and a hung replica, the wait can reach rollouts_save_timeout + 600 s, which is today's worst case.
  • Pinned arrays stay in memory until they are written. That is about 1–2 min, and it includes the cut batch after the trainer has freed it.
  • The close adds one round trip to the first barrier after a checkpoint, bounded at 10 s.
  • A control request closes the save for a checkpoint that is still completing. If the request arrives while arrays are being pinned, the save closes as soon as its window opens. The request is marked saved when the checkpoint completes.
  • A listed restore must still represent a single trace after capture. If another trace started during the save, the worker gives back the snapshot and the episode starts over on resume.
  • File-backed sample replacement, deletion and moves share a cross-process lock. A cancelled worker can discard its samples even while the replica sample server is scoring them.
  • PayloadServer.replace now drops the blob's last persisted file. Without this, a sample credited after an earlier checkpoint persisted it would be linked stale into the next checkpoint.

Risks and follow-ups

  • feat: pause episodes instead of cancelling on overload #4807 (pause instead of cancel on overload): if paused episodes leave dispatcher.inflight, a rollout checkpoint's cut does not list them. Their groups then never complete after a resume. The same holds with today's barrier save.
  • feat: checkpoint whole multi-agent episodes #4810 (checkpoint whole multi-agent episodes): it also rewrites the worker's save. The listed save here works per episode (single trace for now), so episode_restore_point fits into _try_save: hold the episode's rollouts, save them, release them.
  • Follow-up, not built: extend the save past the next barrier, accepting a restore point only if every sampled token it holds is labeled v{N} or older (node weight_versions). Engines that report no labels cannot use this.

Validation

Unit tests (CPU):

  • Regression coverage for a pause during pinning, a second trace appearing during capture, and a worker delete racing sample replacement.
  • tests/unit/orchestrator/test_rollout_ckpt.py:
    • the barrier returns after the cut and before any snapshot;
    • the next barrier closes the save;
    • a save every replica answered completes before the next barrier;
    • a requested checkpoint holds every rollout until the cut;
    • teardown closes the last save;
    • pinned arrays survive deletes and keep their state of the cut;
    • a forked writer plus later restore points complete a checkpoint that resumes with them.
  • tests/unit/env/test_env_worker_save.py:
    • a listed save holds each rollout only for its own save;
    • transient skips are retried until the close;
    • a run that ends finished first;
    • a capture that started after the close is disowned;
    • runs waiting for their turn at the close start none.
  • tests/unit/orchestrator/test_env_replicas.py: runs are routed to their replica; a replica that answered needs no close; an unconfirmed replica's restore points are dropped and land in late_restores.
  • tests/unit/transports/test_payload.py: RolloutStore pins survive deletes and the cleanup of trained steps.

End to end: a local reverse-text run (subprocess runtime, so every in-flight rollout restarts on resume), with ckpt.interval = 4 and ckpt.rollouts, before and after this change. See the barrier times below.

Setup:

  • one node, the reverse-text tiny config, 12 steps of 5–20 s;
  • barrier time is the watcher's pending-hook time, measured with a temporary log line that is not part of this PR;
  • no local runtime takes memory snapshots, so an injected sleep in Rollout.save stands in for one.
Code Snapshot stand-in Barrier at checkpoint steps 4 / 8 Barrier after (close) Checkpoint complete
main none 18 / 25 ms — in the hook
main 5 s 5.03 / 5.03 s — in the hook
this PR 5 s 10 / 8 ms nothing left to close 5 s after the cut
this PR 30 s (longer than a step) 18 / 9 ms 5 / 6 ms save open 22.9 / 20.0 s, complete 7–10 s after the close

A resume from the async checkpoint of step 8 (--resume.step 8) restored the 7 in-queue episodes the checkpoint saved, re-ran its 15 in-flight rollouts, and went on to step 12.

Live checkpoint and resume

Ran Qwen3-0.6B with vLLM and Prime memory snapshots on two Nebius H200s (Slurm job 17295). The test controlled when two real captures started using their observed engine weight labels. Step 2 published five restore references, all with token versions at or below v2. The first probe's saved prefix included 12 v2 tokens. The other probe captured 7 v3 tokens after the save window closed and was excluded from the checkpoint.

A fresh trainer loaded step 2. The first probe's restored token IDs and version spans matched the saved prefix exactly, and its first new response came from v2. The second probe started over with a new trace ID and sampled from v2. The fork reached step 4.

All 58 focused checkpoint, env worker, replica, and payload tests passed. A separate-process check also verified that scoring cannot resurrect a sample discarded by an env worker.

Checkpoint interval

With restore points off the barrier, a rollout checkpoint no longer stalls the trainer, so ckpt.interval can come down (for example from 50 to 20-25 steps) to bound the steps a crash replays. Pair it with the trainer's async_save and watch the new ckpt/rollouts/missed/* metrics for snapshot load.

🤖 Generated with Claude Code


Note

High Risk
Changes core rollout checkpoint timing, distributed save/close protocol across env replicas, and training-array pinning—errors can lose restore points or stall barriers under slow replicas.

Overview
Rollout checkpoints no longer block the weight publish barrier on every env snapshot. At step N, the barrier only records open work, pins referenced training arrays, and forks the open-work writer; the hook returns while training and inference continue. In-flight rollouts are snapshotted afterward via per-replica listed saves (save_id, request_ids, close_save), each rollout held only for its own capture, with retries for booting/setup rollouts and a cap of 250 concurrent saves per worker.

The next publish barrier (v{N+1}) closes the save window (10s confirm budget) so no restore point can include tokens from newer weights; checkpoints finish with restores.pkl plus progress.pt after arrays are persisted and unpinned.

Training array persistence adds env-worker pin/unpin (/pin, /unpin, optional pin on /persist) so blobs survive trainer/sink deletes until the checkpoint is written, without holding the sink lock for large persists. RolloutStore uses file locks and pin directories; credited blobs no longer clobber earlier linked checkpoint files.

Pause/checkpoint-requested steps still use the old hold-all-then-cut path while the trainer waits. Docs/config text and ckpt/rollouts/* coverage metrics describe the new cut/deadline semantics and missed-restore categories.

Reviewed by Cursor Bugbot for commit 27edee8. Bugbot is set up for automated code reviews on this repo. Configure here.

…blish barrier

A rollout checkpoint saved every running rollout at the weight-publish barrier:
the trainer waited in its broadcast and inference idled until the slowest env
worker pool replica had snapshotted and held its rollouts. The training arrays
were then written while the sink lock was held, which stalled collection.

The barrier now only cuts the open work and pins the training arrays it
references on the sample servers, then returns. With the sink still locked the
orchestrator forks the writer of the open work. Each rollout in flight at the
cut then takes its memory checkpoint, held only while its own is taken, and a
rollout that is booting or in setup is tried again. The next publish barrier
closes the save before inference gets the new weights: a worker starts no
memory checkpoint after it confirmed the close and drops any that started
later, so every token a restore point holds was sampled with the checkpointed
step's weights or older. The arrays are written from their pins and unpinned,
the restore points go to rollouts/restores.pkl, and progress.pt completes the
checkpoint last.

A checkpoint that a pause or checkpoint request asks for keeps the old order:
every running rollout is snapshotted and held, then the open work is cut, then
the rollouts are released.

The checkpoint stats and log report the coverage of the restore points: the
rollouts in flight at the cut, the restore points taken, the ones missed by
why (finished first, deadline, not ready, no reply, unsaveable) and the time
the save was open.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@wiz-prime-intellect

wiz-prime-intellect Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Wiz Scan Summary

Scanner Findings
Vulnerability Finding Vulnerabilities -
Data Finding Sensitive Data -
Secret Finding Secrets -
IaC Misconfiguration IaC Misconfigurations -
SAST Finding SAST Findings 2 Low
Software Management Finding Software Management Findings -
Total 2 Low

View scan details in Wiz

To detect these findings earlier in the dev lifecycle, try the Wiz Code extension for VS Code, JetBrains, or Visual Studio.

@hallerite
hallerite marked this pull request as ready for review November 29, 2026 11:17

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread src/prime_rl/orchestrator/ckpt.py Resolved
Comment thread src/prime_rl/env/worker.py Resolved
Comment thread src/prime_rl/transports/payload.py Resolved
Comment thread src/prime_rl/env/worker.py Resolved
hallerite and others added 3 commits November 29, 2026 11:39
…store files

The barrier clears the step's rollouts directory and carries the restore files
of resumed episodes not dispatched yet before the arrays are written, which
created it before. Linking into a missing directory failed, so each of those
episodes lost its restore point and started over after the next checkpoint.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The client sends each request from its own task, so a close can reach a worker
before the save it closes. The worker ignored that close and the save then ran
open, able to take memory checkpoints after the next policy arrived. A worker
now remembers the recent closes of saves it has not received, and such a save
opens closed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A rollout store credited a blob by truncating and rewriting its file, the inode
a checkpoint pin and an earlier checkpoint link. A group scored after the cut
then overwrote the bytes the checkpoint was to write. The store now writes the
credited blob to a new file and renames it over the old name, under a lock
that its deletes and moves to a trained step also take, so a freed blob stays
freed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit e8323be. Configure here.

Comment thread src/prime_rl/transports/payload.py Resolved
Comment thread docs/training.md
The orchestrator then saves step N when the trainer publishes the weights of N, before inference applies them. The checkpoint holds the pipeline of that moment, so a resumed run ships the batches that the first run would have shipped.
The orchestrator then cuts step N when the trainer publishes the weights of N, before inference applies them. The checkpoint holds the pipeline of that moment, so a resumed run ships the batches that the first run would have shipped.

The cut takes well under a second, and then training and inference go on:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

would not put stuff like "action x takes y amount of time" in the docs

Comment thread docs/training.md

1. At the publish barrier of N, the orchestrator records the open work at one instant. It pins the training arrays that the open work references on the env workers that keep them, so neither the trainer nor the orchestrator frees them before they are written.
2. While training goes on, the arrays are written to the checkpoint and then unpinned. Each rollout that was running at the cut takes its memory checkpoint. It stops only while its own snapshot is taken.
3. The publish barrier of N + 1 closes the save. No memory checkpoint starts after that, so every token that a restore point holds was sampled with the weights of N or older. A resumed run serves the weights of N.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

so we stop checkpointing here instead of blocking? imo we should be blocking, should prioritize getting the ckpt complete

Comment on lines +88 to +90
SAVES_IN_FLIGHT = 250
"""Memory checkpoints a listed save takes at once. The ones waiting for their turn start
none after the save closes."""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

what is this for?

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants