Skip to content

test(checkpoint): add Workplace prefix-recovery parity - #4507

Merged
terrykong merged 15 commits into
mainfrom
amahishi/ckpt-v2-prefix-recovery
Nov 12, 2026
Merged

terrykong merged 15 commits into
mainfrom
amahishi/ckpt-v2-prefix-recovery

Conversation

@macandro96

@macandro96 macandro96 commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do ?

Adds an end-to-end parity test for generation-prefix recovery: an uninterrupted run and a hard-killed, prefix-restored run of the same Workplace workload must train on identical data.

Stacked on #4506. The base branch is amahishi/ckpt-v2-prefix-recovery-pr1, so this diff shows only this PR's 15 commits. It is test code only. The functional test itself moved here from #4506 (review comment C28), so #4506 changes no functional-test files.

Issues

How it works

flowchart LR
    B[Reference run<br/>uninterrupted] --> P[Parity compare]
    P1[Phase 1<br/>checkpoint with active prefixes] -->|SIGKILL| P2[Phase 2<br/>restore prefixes, generate tails]
    P2 --> P
Loading
  • Workload: Qwen3-1.7B, 1 train step by default, four Workplace prompts × 2 generations, on Gym main's workplace_assistant_simple_agent. Each episode makes a named calendar_create_event call, then closes by listing 1..N (N = 150/250/350/450) at natural length, so prompt groups finish far apart. Gym sees tool_choice: auto on every turn, so both calls are cuttable; a policy-call proxy in the test hook (the one refactor(checkpoint): move rollout checkpointing out of the single controller #5011 uses for the turn test) sends every post-tool call to vLLM with tool_choice: none. One prompt expects a different duration, so rewards are not constant. top_p=1e-6 makes the regenerated tail comparable token-for-token; training applies the same top_p, so the policy-gradient term is 0. The test checks rollout and training-data parity, not learning.
  • Selection: phase 1 is killed only once a snapshot holds a recoverable prefix in every prompt group, and Gym cut every active call in it. The trainer's save line for that snapshot must report zero failed and zero skipped cuts; otherwise a call that quietly regenerated after the restore would pass unnoticed.
  • Restore checks: each cut returns to its Gym owner as attempt + 1, restores its exact prefix digest, completes once with a non-empty tail whose prefix + tail add up to its logged total, and its trained row ends with exactly that many generated tokens starting with the restored prefix. The call is found by counting back from the row's end, so tokens the trainer masks inside it (top-p -inf logprobs, fix(grpo): drop top-k/top-p -inf from token_mask #4154) cannot shift where it starts. No restored prefix key is still live in any batch the trainer consumed.
  • Parity checks run on the trainer's own async_rl.log_full_train_data dump from all three runs:
    • every row matches the reference exactly (token ids, masks, input length, reward, sample mask; advantages within tolerance);
    • one verified exception: a restored row whose phase-1 prefix already diverged from the reference before the cut. vLLM sampling is not batch-invariant, so phase 1 can take the other side of a near-tie, and recovery must then continue phase 1's tokens. Such a row must start with exactly the restored tokens (the restore log's prefix_ids_sha256), match token-for-token up to its closing call, and keep its reward and sample mask. At most one restored row may be set aside this way, and at least one must match the reference outright;
    • vLLM generation logprobs over token-matched rows: bit-identical fraction ≥ 0.98 and max |diff| ≤ 0.5. Main's sampler replay (feat(loss): add sampler replay for top-k/top-p training incl score centering #5006) needs logprobs_mode: processed_logprobs with top_p, and after a top_p=1e-6 filter every sampled token's logprob is 0, so this check is now trivially 1.0; the token-level checks above carry the parity.
  • Retired-row check: the restored calls' chunk rows must still be live at phase 2's first training step and gone after the next snapshot's flush (feat(checkpoint): recover active vLLM generation prefixes #4506 deletes a finished call's chunk rows at the next snapshot). Phase 2 trains one step past the reference so that snapshot runs while the run is alive; only the reference's steps are compared, and grpo.max_num_steps is excluded from the rollout fingerprint.

Changes

Commit What it does
test(checkpoint): add the prefix-recovery functional test The end-to-end test, moved here from #4506.
test(checkpoint): add Workplace prefix-recovery parity Reference + two-phase recovery harness and the row-level parity comparison.
test(checkpoint): strengthen Workplace prefix-recovery parity Multi-cut Workplace workload.
test(checkpoint): read the renamed generation-cut keys in prefix-recovery parity Reads the generation-cut fields under NeMo Gym's wire names.
test(checkpoint): load the shared snapshot helpers in the parity unit test Puts tests/functional on sys.path before the unit test loads the snapshot helper.
test(checkpoint): address review of generation-prefix recovery parity Parity reads the trainer's train_data_step*.jsonl dump; removed the ordering/correlation report, the metric comparison and redundant checks; JSON readers, the restore-log parser, and the calendar sentinel count are shared with the turn-recovery test.
test(checkpoint): run prefix-recovery parity on Gym main's Workplace agent Drops the Gym checkpoint test agent, which Gym main no longer has, for the policy-call proxy, and uses tool_choice: auto so Gym does not skip the cuts.
test(checkpoint): select only prefix-recovery snapshots that cut every active call The selection gate above, with a unit test.
test(checkpoint): lower the prefix-recovery logprob floor to 98% bit-identical On this workload (~9.3k generated tokens) four runs scored 98.89–99.13% with every exact gate passing; three fell below the old 99% floor across three different progress-read implementations. The max-
test(checkpoint): find a restored call by counting back from its row's end The boundary check above. It used to start the call at the row's last unmasked run, which a masked token inside the call moved, failing a correct restore.
test(checkpoint): run the prefix-recovery parity test with processed logprobs vllm_cfg.logprobs_mode=processed_logprobs, which main's sampler replay (#5006) requires with top_p; the test failed at startup without it.
test(checkpoint): check restored prefix rows are deleted by the next snapshot The retired-row check above.
test(checkpoint): run the prefix-recovery test in fast CI and share its readers Adds the test to L1_Functional_Tests_SingleController_3.sh (as run_test fast; the next review round moves it to full tier); the turn and prefix scripts share one SC_GYM_RECOVERY_TEST_EVENTS variable, and the turn script imports its ledger and calendar readers from _gym_recovery_snapshot_helpers.
test(checkpoint): read forest training's row IDs in prefix-recovery parity Accepts a forest-training row ID (<group>_g<i>_s0), still one trained row per rollout, and fails clearly on a later segment.
test(checkpoint): address fourth review of generation-prefix recovery parity At most one restored row may be set aside (C16). One row index and one cut check (_check_cuts), same checks and messages (C19). The Workplace row builder is inlined into the prefix script (C20; same test data). Unused snapshot-selection fields are dropped (C21). The test runs at full tier, not in fast lanes, until a CI-GPU pass rate is shown (C25).

Lines vs #4506: unit tests +680, functional tests +1560 / −80.

Testing

  • Unit: tests/unit/environments/test_gym_prefix_recovery_parity.py 34 passed.
  • tests/functional/grpo_async_gym_single_controller_prefix_recovery.sh passes locally on this head (1 node, 470 s): 8 restored prefixes (139–156 tokens), every row matches the reference, 0 rows needed the pre-cut exception; the restored calls' 16 chunk rows were live at the first training step and 0 remained after the next flush.
  • tests/functional/grpo_async_gym_single_controller_turn_recovery.sh passes locally on this head (260 s) with the shared readers.
  • After rebasing onto main (with feat(checkpoint): recover active vLLM generation prefixes #4506): the prefix test passes again (477 s): 8 restored prefixes, every row matches, 0 rows needed the pre-cut exception.
  • With ++token_capture.forest_training=true and fix(checkpoint): keep the calls a restored turn carried over under forest training #5147 applied: the prefix test passes (455 s). All 8 restored episodes seal as their next attempt, and all 8 trained rows match, one through the pre-cut exception. Without fix(checkpoint): keep the calls a restored turn carried over under forest training #5147 the restored episodes are regenerated (see fix(checkpoint): keep the calls a restored turn carried over under forest training #5147).
  • Earlier runs, before processed_logprobs, measured the generation-logprob check for real: 99.11% bit-identical over 9,312 tokens, max |diff| 0.212 with flat_logprobs: true; 99.10%, max |diff| 0.162 without.
  • An earlier run hit the pre-cut case: phase 1 sampled <tool_call> instead of 1 as a closing turn's first token. The restored prefix hash matched phase 1's tokens. That run's data passes with the exception (1 row set aside) and fails without it.
  • On this head (4a9c6ea4e): the prefix test passes locally (8 restored prefixes, every row matches, 0 rows set aside, no retries).
  • CI: the prefix-recovery test runs at full tier (run_test in L1_Functional_Tests_SingleController_3.sh, so this PR is labeled CI:L1), not in fast lanes, until a pass rate from runs on the CI GPU is posted (C25). The L1 job time will be posted once it runs.

🤖 Generated with Claude Code

@copy-pr-bot

copy-pr-bot Bot commented Oct 5, 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 commented Oct 6, 2026

Copy link
Copy Markdown

✅ Submodule Fast-Forward Check Results

Check based on commit: 082e927 (PR #4507 from amahishi/ckpt-v2-prefix-recovery)

✅ Submodules that are properly updated:

Gym: ✅ PR branch is ahead of main branch (fast-forward)

All submodule changes look good! ✨

@macandro96
macandro96 force-pushed the amahishi/ckpt-v2-prefix-recovery branch from 082e927 to 1a6de5c Compare October 7, 2026 04:02
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

✅ Submodule Fast-Forward Check Results

Check based on commit: 1a6de5c (PR #4507 from amahishi/ckpt-v2-prefix-recovery)

✅ Submodules that are properly updated:

Gym: ✅ PR branch is ahead of main branch (fast-forward)

All submodule changes look good! ✨

@macandro96
macandro96 force-pushed the amahishi/ckpt-v2-prefix-recovery branch from 1a6de5c to cc5d8bc Compare October 11, 2026 23:59
@github-actions

Copy link
Copy Markdown

✅ Submodule Fast-Forward Check Results

Check based on commit: cc5d8bc (PR #4507 from amahishi/ckpt-v2-prefix-recovery)

✅ Submodules that are properly updated:

Gym: ✅ PR branch is ahead of main branch (fast-forward)

All submodule changes look good! ✨

@github-actions

Copy link
Copy Markdown

✅ Submodule Fast-Forward Check Results

Check based on commit: deb0e14 (PR #4507 from amahishi/ckpt-v2-prefix-recovery)

✅ Submodules that are properly updated:

Gym: ✅ PR branch is ahead of main branch (fast-forward)

All submodule changes look good! ✨

1 similar comment
@github-actions

Copy link
Copy Markdown

✅ Submodule Fast-Forward Check Results

Check based on commit: deb0e14 (PR #4507 from amahishi/ckpt-v2-prefix-recovery)

✅ Submodules that are properly updated:

Gym: ✅ PR branch is ahead of main branch (fast-forward)

All submodule changes look good! ✨

@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.

Thanks for this. It adds the token-level parity against an uninterrupted run that was asked for on #4500 (discussion) and #4266 (discussion), which is the right check for prefix recovery.

Two comments are about what the test proves:

  • restored rows are excused too widely, so a changed tool result or turn-1 token passes (parity L516);
  • top_p=0.000001 keeps rewards out of the gradient (script L194).

Size. About 1,040 of the 2,098 added lines can go without weakening a check:

What Source lines Unit-test lines
Use the built-in log_full_train_data dump instead of the recorder (hook L57) ~125 ~28
Ordering / timeline / Kendall-tau code (parity L691) ~215 ~127
Hand-rolled Spearman / Pearson / percentiles (parity L548) ~125 ~70
Restored-row excusal (parity L516) ~70 ~115
Small repeated checks, fallbacks and copied helpers (L346, L367, L285, L304), plus the report printing and script plumbing that only feed the code above ~165 —

A version with the same checks is about 330 source lines plus 260 unit-test lines.

This PR also builds on #4506, whose 25 review comments (including its ~300-line size ask) are still open. Please apply #4506's size asks first, so this PR shrinks on top of a smaller base; the prefix-recovery stack is already over 20k lines.

Gym pin. This test also needs Gym 7a254e8e98 and 994cd12404 (prefix mode and the SimpleAgent _prepare_model_request_for_turn hook) on Gym main. Same ask as the open #4500 thread (discussion).

Small nit: the PR body says "unit 37 passed", but the unit file has 38 cases.

Visual explainer: https://terrykong.github.io/gh-pages-poc/terryk/pr-4507-size-and-reuse.html
Visual explainer: https://terrykong.github.io/gh-pages-poc/terryk/pr-4507-excused-rows.html

Generated by Claude Code

@macandro96

Copy link
Copy Markdown
Contributor Author

Thanks for the review. The inline items are addressed in 8feaa87499; r4305679042 still waits on the CI run.

What the test proves: exact parity for every row, with one verified exception: a restored row whose phase-1 prefix already diverged before the cut. A real run needed it; details are in the excusal thread. The script now says the test checks data parity, not learning.

Size: #4507 is now +1,503 / -125 lines against #4506 (was +2,090 / -73); the parity helper is 578 lines. The extra deletions are the turn-recovery script's copies, now shared. That is still well above your ~590-line estimate. Most of the remainder is the pre-cut check, the trainer-dump loader, and the LoggerConfig fix with its test.

#4506: its review round landed in 6da5c10a99, with replies on all 25 threads.

Gym pin: acknowledged. The stack pins amahishi/rl-gym-turn-recovery-pin (now 4f996d10), which is still not on Gym main; same as the #4500 thread.

Nit: the description will list the current counts (22 parity unit cases).

@macandro96

Copy link
Copy Markdown
Contributor Author

/ok to test 8feaa87

@macandro96 macandro96 added the CI:L1 Run doctests, unit tests, and functional tests label Oct 19, 2026

@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.

Second round on #4507 (stack 6/11), checked at 7f7a7a5. Thanks for fixing C1–C14 from the first round, for the count-back fix in f5b932f with its regression test, and for sharing the readers with the turn-recovery test in 7f7a7a5.

Correctness. (C16) Up to 7 of the 8 restored rows can be set aside and the test still passes, so a run can quietly check very little. Please cap it at one.

Size. The PR is +2,242/−80, all tests. 615 of those lines are the functional test that #4506 moved here unchanged (f09626d there, 8b50c4e here). About 75 lines can go without weakening what the restore check proves, which brings it to ~2,170 (C16 adds about 6 lines back):

  1. (C19) Build the row index once and merge the two cut checks: about −40.
  2. (C20) Inline the jq builder that has one caller: about −23.
  3. (C21) Unused snapshot-selection options and fields: about −13.

No product function can replace the rest. nemo_rl has no reader for train_data_step*.jsonl, the restore and completion lines exist only in logs, and prefix_ids_sha256 is computed inline (prefix_recovery/recovery.py L747-L761).

CI (C15 is still open). The prefix-recovery functional test has never run in CI. On 7f7a7a5, /ok to test ran but no tests did, because the PR had no CI label at the time. CI:Lfast is on now, and 7f7a7a5 moved this test into the fast lane. Please post /ok to test again and link the passing L1_Functional_Tests_SingleController_3 job with its run time. Before it joins the fast lane, please also post a pass rate from at least 15 runs (C25).

DCO. Commit 2bd7591 carries only another person's Signed-off-by line, not yours, so the DCO check fails. Please add your own sign-off.

PR description. These lines are out of date:

  • "No restored prefix key is still live in any batch the trainer consumed": since 9e3ff7a they are live at the first training step and gone after the next snapshot.
  • The Workplace row builder in the "shared with the turn-recovery test" list (C20).

Visual explainers: what the test proves https://terrykong.github.io/gh-pages-poc/terryk/pr-4507-what-it-tests.html, and what can shrink https://terrykong.github.io/gh-pages-poc/terryk/pr-4507-v2-what-can-shrink.html

Generated by Claude Code

@macandro96 macandro96 added CI:L1 Run doctests, unit tests, and functional tests and removed CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) labels Nov 10, 2026
@macandro96
macandro96 force-pushed the amahishi/ckpt-v2-prefix-recovery branch from 0bc9d74 to 4a9c6ea Compare November 10, 2026 21:17

@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.

C26 · 1 action item.

TL;DR — the code side of C20 is done; the PR description still says the jq row builder is shared and the test runs in the fast lane.

Follow-up to C20. Thanks for C16, C19, C21 and C25 too; those threads are closed.

Fixed: 4a9c6ea inlines the rows into grpo_async_gym_single_controller_prefix_recovery.sh and deletes _workplace_calendar_rows.jq.

Still open (PR description only):

  • The "address review of generation-prefix recovery parity" row still lists "the Workplace row builder (_workplace_calendar_rows.jq)" as shared with the turn-recovery test. That file is gone.
  • The "run the prefix-recovery test in fast CI" row says run_test fast, but L1_Functional_Tests_SingleController_3.sh#L81 now runs it at full tier.
  • The commit table has no row for 4a9c6ea (the intro still says 14 commits; there are 15).

AI-1

Edit the PR description: drop the jq builder from the shared list, say the test runs at full tier until a CI-GPU pass rate is posted, and add a row for the new commit. Not a suggestion block: it is the PR description, not a file.

@macandro96

Copy link
Copy Markdown
Contributor Author

Updated the PR description:

  • the "address review of generation-prefix recovery parity" row no longer lists the jq row builder as shared;
  • the "fast CI" row now says the fourth-review commit moves the test to full tier, and the Testing section says it stays there (CI:L1) until a CI-GPU pass rate is posted;
  • added a row for 4a9c6ea, and the intro now says 15 commits.

@macandro96

Copy link
Copy Markdown
Contributor Author

/ok to test 4a9c6ea

Base automatically changed from amahishi/ckpt-v2-prefix-recovery-pr1 to main November 11, 2026 00:02
macandro96 and others added 15 commits November 10, 2026 16:02
The end-to-end test of generation-prefix recovery, moved here from #4506
(C28): Gym's policy proxy holds a long Workplace call mid-decode, a rollout
snapshot cuts it, and after a hard kill the restored call must resume from
its saved prefix and train on the same rows as an uninterrupted run.

Signed-off-by: Anish Mahishi <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Make the parity test exercise many restored prefixes and separate recovery
faults from run-to-run sampling noise:

- Workload: four Workplace prompts per step whose closing turn lists 1..N
  (N = 150/250/350/450) at natural length. Group lengths are far apart, so
  prompt-group readiness order is deterministic. One prompt expects a
  different duration so rewards are not constant. Runs Qwen3-1.7B for 3
  steps.
- Selection/verification: require a recoverable prefix in every Workplace
  prompt group at the crash (Gym refuses dispatches that land during a
  checkpoint, so siblings may start late), and verify each cut returns to
  its Gym owner under attempt+1, restores its exact prefix digest, and
  completes once with its trained generated-token count equal to the
  restored prefix plus the regenerated tail.
- Parity: classify token divergences relative to the restored prefix. A
  divergence inside the prefix is excused as phase-one noise only when the
  trained prefix tokens hash-match what the worker restored, and excused
  rows still require equal rewards and sample masks; a prompt divergence
  always fails. Gate vLLM generation_logprobs in aggregate over token-
  matched rows (bit-identical fraction, Spearman, max abs diff) since they
  are not batch-invariant, and require exact prompt-group readiness order.
  Report Kendall tau for arrival and sealing order, per-rollout timelines,
  and logprob statistics in parity-report.json before the strict checks
  run.
- Hook: timestamp every event and record completion arrival separately
  from the ledger seal.
- Relies on the Gym checkpoint test agent's natural-length closing turn
  (NEMO_GYM_TEST_PREFIX_MIN_TOKENS=0), pinned by the base branch.

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

The prefix-recovery parity harness reads each restored cut from Gym's
checkpoint records and reports it. NeMo Gym now names the staged prefix
prefix_token_count and prefix_digest, so the harness, its report, and
its unit tests use those keys.

Signed-off-by: Ananth Subramaniam <[email protected]>

Signed-off-by: Anish Mahishi <[email protected]>
… test

The prefix-recovery snapshot helper now imports
_gym_recovery_snapshot_helpers as a sibling module. Put tests/functional on
sys.path before loading it by file path, as running it as a script does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
Parity data and gates:
- Compare runs on the trainer's own async_rl.log_full_train_data dump
  (read from the run's exp_NNN directory) instead of a recorder in the
  hook; the hook now only probes live staging keys per train step.
- Require exact parity for every row. The one exception is a restored
  row whose phase-1 prefix already differed from the reference before the
  cut (vLLM sampling is not batch-invariant): it must start with exactly
  the restored tokens (prefix_ids_sha256), match up to its closing call,
  and keep its reward and admission; at least one restored row must match
  outright.
- Gate generation logprobs on bit-identical fraction and max |diff|.
- Default to one train step and say the test checks data, not learning
  (top_p=1e-6 zeroes the policy gradient).

Removed: the ordering/timeline/Kendall report, the hand-rolled
Spearman/Pearson gate and parity-report.json, the metric comparison, the
prefix+tail==total tautology, the duplicate trained-once check, the
unreachable successor Gym-manifest check, the single-cut selection
fallback, and the swallowed Workplace layout errors. The JSON readers and
the restored-prefix log parser are shared in _gym_recovery_snapshot_helpers.
The L1 runner comment now says the test performs three runs.
The Workplace calendar sentinel count lives with the shared readers, and the
Workplace test rows are built by one jq module (_workplace_calendar_rows.jq).

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

Gym main has no checkpoint test agent, so the prefix-recovery parity test
now runs the stock workplace_assistant_simple_agent behind the test hook's
policy proxy, as the turn-recovery test does. With no hold and no
follow-up tool, the proxy sends every call after the tool result with
tool_choice none and leaves its length to the model, which is what the
test agent did for the closing turn.

Gym only cuts a call whose decoding is unconstrained, judged from the
request its agent sends, so the rows leave tool_choice auto instead of
forcing calendar_create_event: a forced tool would keep every turn out of
the cut. The prompt asks for the call, and the snapshot selector already
requires the calendar write to have happened exactly once.

The rows name workplace_assistant_simple_agent, the script drops the test
agent's config_paths override and environment-server removal, and the
hook writes the proxy's events to the prefix test's events file.

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

The snapshot records only the cuts that succeeded, so a snapshot where Gym
failed or skipped an active call's cut still qualified, and that call
quietly regenerated after the restore. Read the trainer's save line for the
snapshot and require zero failed and skipped cuts; a bug that keeps failing
cuts now times out the selection with the counts instead of passing.

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

On Gym main's Workplace agent the workload generates ~9.3k tokens, and four
runs scored 98.89-99.13% bit-identical with every exact token, mask and
reward gate passing; three fell below the old 99% floor across three
different progress-read implementations. The bf16 noise floor is a property
of the smaller workload, not of the restore, so the gate now sits at 98%.
The max-|diff| bound stays at 0.5.

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

The prefix-recovery parity checks located a restored call at the start of
its row's last unmasked segment. When top-k/top-p filtering is on, the
trainer drops positions whose recomputed logprob is -inf from token_mask
(#4154), and the rows these checks read are dumped after that pass, so a
masked token inside the call made the check start the call too late,
miscount its tokens, and fail a correct restore.

A restored call closes its row, so the total_generation_tokens it logs on
completion end the row. _assert_prefix_boundary now counts back from the
row's end, requires the token before the call to be untrained, checks the
completion's prefix + tail = total accounting, and requires the restored
prefix at that position; a dropped or duplicated token moves the position.
It returns where each call starts, which _rows_diverged_before_cut reuses
to compare the reference row at the same position.

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

Main's sampler replay (#5006) refuses top_k/top_p filtering unless vLLM
returns logprobs after the filter, since the trainer now replays it. The
parity test samples with top_p=1e-6 to make regenerated tails comparable
token for token, so it failed at startup. Set
vllm_cfg.logprobs_mode=processed_logprobs, as main's score-centering
functional test does.

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

#4506's third review defers a finished call's chunk-row delete to the next
snapshot, so restored prefix rows are still live when phase two first
trains. Phase two now trains one step past the reference, so the snapshot
after the compared step runs while the run is alive, and the hook records
the live staging keys right after each flush. The parity check requires
the restored rows to be live at the first training step and gone after the
first flush, and compares only the reference's steps.

grpo.max_num_steps is excluded from the rollout fingerprint in both phases,
since only phase two's stopping point changes.

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

Address C28's follow-ups from the third review of generation-prefix
recovery:
- The recovery hook reads one events variable, SC_GYM_RECOVERY_TEST_EVENTS,
  which the turn and prefix scripts both set; the turn-only name and its
  fallback are gone.
- The prefix-recovery test runs in fast CI lanes: three launches on 2 GPUs,
  7-9 minutes locally.
- The turn-recovery script imports ledger_episode_index,
  participant_records, matching_siblings and calendar_sentinel_count from
  _gym_recovery_snapshot_helpers instead of keeping its own copies.

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

Under token_capture.forest_training the trainer names each row
<group>_g<i>_s<segment>, and the parity check rejected them as invalid
sample IDs. Accept the single segment _s0, which still compares one
trained row per rollout, and fail clearly on a later segment.

With #5147 applied, the prefix-recovery test passes under forest
training: 8 restored episodes seal as their next attempt and all 8
trained rows match the uninterrupted run.

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

- C16: fail when more than one restored row is set aside as diverged
  before its cut. Nothing checks that a set-aside row diverged rather than
  restored the wrong tokens, so the cap bounds what a run leaves unchecked.
- C19: build the row index once in compare and pass it to every check, and
  merge the prefix-boundary and divergence checks into _check_cuts, which
  reads the recovery log once. Same checks, order and messages. Drop the
  step-mixing check: JsonDebugWriter writes one file per step.
- C20: inline the Workplace row builder into the prefix script and delete
  _workplace_calendar_rows.jq; the turn-recovery test builds its own rows.
  The generated test data is byte-identical.
- C21: drop min_cuts, the top-level longest-cut fields and the unread
  per-cut resources_manifest and sentinel_event from the snapshot selection.
- C25: run the test at full tier, not in fast lanes. It relies on three
  runs making the same near-greedy choices, and local runs have failed for
  reasons outside recovery, so it waits for a CI-GPU pass rate.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
@terrykong
terrykong force-pushed the amahishi/ckpt-v2-prefix-recovery branch from 4a9c6ea to 8ca22f0 Compare November 11, 2026 00:02
@macandro96

Copy link
Copy Markdown
Contributor Author

/ok to test 8ca22f0

@macandro96
macandro96 removed this pull request from stack #5057 November 12, 2026 15:29
@macandro96
macandro96 added this pull request to stack #5181 November 12, 2026 15:29
@terrykong
terrykong merged commit a46e979 into main Nov 12, 2026
97 checks passed
@terrykong
terrykong deleted the amahishi/ckpt-v2-prefix-recovery branch November 12, 2026 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:L1 Run doctests, unit tests, and functional tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants