Skip to content

fix(checkpoint): keep the calls a restored turn carried over under forest training - #5147

Merged
terrykong merged 3 commits into
mainfrom
amahishi/forest-continued-attempts
Nov 13, 2026
Merged

terrykong merged 3 commits into
mainfrom
amahishi/forest-continued-attempts

Conversation

@macandro96

@macandro96 macandro96 commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do ?

Fixes turn-level rollout recovery under token_capture.forest_training. Before this PR, every restored episode that had already made a model call was quietly regenerated from its prompt instead of continued.

Issues

Found while testing generation-prefix recovery with forest training (#4506, review threads C26/C56).

The problem

Turn-level recovery (#4500) continues a restored episode as its next attempt, <rollout_id>-a<N>. The calls the earlier attempt made are kept and stay staged under that attempt's key (Gym stamps each carried row with source_capture_key). A continued receipt therefore mixes keys:

capture_key: <rollout>-a1
manifest:    <rollout>/call0      (made before the checkpoint)
             <rollout>-a1/call1   (made after the restore)

Forest training's ownership checks (#4124, #4200) landed before turn recovery and require every row to be staged under the current attempt's key. Every continued episode with a call from before the checkpoint therefore failed with:

ValueError: Forest recovery has foreign staging ownership:
  gate_id='…_g0_ae01163…-a1', staging_key='…_g0_ae01163…/0d99f6ff…'

generate_for_finalization treats that as a data failure. It counted rollout/data_retry_total/ValueError and regenerated the episode from its prompt, without logging why. Training data stayed correct, but turn recovery (and prefix recovery, #4506) saved no work under forest training.

Changes

File Change
rollout_recovery.py _owned_staging_key(owner, call_id, source_capture_key): the one key a manifest call must be staged under. A call with no source_capture_key stamp must be under the receipt's own attempt. A carried call must be under exactly the attempt its stamp names, which must be an earlier attempt of the same rollout (the rule Gym's rebuild._staging_owner applies). Used by the ledger's _attempt_staging_keys, which runs at seal time and decides which rows cleanup claims.
rollout_reassembler_actor.py, rollout_reassembler.py The other three forest ownership checks use it: finalizer request (capture_receipts), selected-call planning (_plan_selected_calls) and logical-row finalization (_finalize_logical_rows).
rollout_manager.py Both data-retry branches print retrying prompt idx=… after deterministic failure n/max (<Error>: …), matching the existing "skipping prompt" line.

Rows of another rollout or a later attempt are still refused, and so is a row under an earlier attempt's key without the stamp a restore adds.

Testing

  • New unit tests (gym lane):
    • test_rollout_recovery.py: a ledger restore of a continued forest attempt keeps the pre-checkpoint call; rows from a later attempt, another rollout, or an earlier attempt without a stamp are refused.
    • test_selected_forest_boundaries.py: forest finalization through the reassembler actor trains a call staged by the earlier attempt and a call staged after the restore exactly once; a row of another rollout or an unstamped earlier row is refused.
    • Both acceptance tests fail on main with the errors above; the two unstamped cases fail if any earlier attempt's key is accepted without its stamp.
  • Existing tests: the forest and recovery files (test_selected_forest_boundaries.py, test_rollout_recovery.py, test_forest_dispatch.py, test_logical_owner_finalization.py), 241 passed; test_rollout_redispatch.py, test_rollout_generation_failures.py, 89 passed.
  • Functional, grpo_async_gym_single_controller_turn_recovery.sh locally:
    • with ++token_capture.forest_training=true loss_fn.token_level_loss=true loss_fn.sequence_level_importance_ratios=false grpo.calculate_advantages_on_gpu=false: fails on main ("restored Gym episode never completed", 1 data retry); passes with this PR (256 s, no data retry);
    • without forest training: passes (255 s).

🤖 Generated with Claude Code

@copy-pr-bot

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

macandro96 added a commit that referenced this pull request Nov 10, 2026
…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]>
@macandro96 macandro96 added the CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) label Nov 10, 2026
macandro96 added a commit that referenced this pull request Nov 10, 2026
…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]>

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

@aroshanghias-nvd can you help review?

macandro96 added a commit that referenced this pull request Nov 10, 2026
…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]>

@aroshanghias-nvd aroshanghias-nvd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed 44f1b433. The ownership rule matches Gym’s reconstruction semantics, and all four forest validation points use it consistently. No blocking issues found.

Locally, 409 affected CPU tests passed. Two additional tests covering a connected chain across one and two restores also passed, preserving one training row and counting each generated token once. Suggest adding those as permanent regressions; nonblocking. I haven’t independently rerun the live functional test.

@macandro96

Copy link
Copy Markdown
Contributor Author

/ok to test 33434dc

@copy-pr-bot

copy-pr-bot Bot commented Nov 12, 2026

Copy link
Copy Markdown

/ok to test 33434dc

@macandro96, there was an error processing your request: E2

See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/2/

@macandro96

Copy link
Copy Markdown
Contributor Author

/ok to test 44f1b43

@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 tracking this down. The fix is right: all four Forest ownership checks now follow Gym's rule, and the new retry log line makes data retries visible. We found no bugs. There are three comments, two about tests and one about the copied Gym rule:

  1. (C1) No test reaches the actor's capture_receipts change on the accept side.
  2. (C2) The later_attempt case tests the rollout-id check, not the new attempt check, and no test covers a second restore.
  3. (C4) The ownership rule is copied from Gym. Call Gym's function instead, so the two cannot drift.

Each test fix was run against the head and against a copy of the code with that check broken. The C4 change returns the same result as the current code on 480 cases.

Before merge: the branch is 14 commits behind main, and "Check if PR branch is up to date" fails (limit 10), so please update the branch. The CI test lanes are green.

Generated by Claude Code

Comment thread nemo_rl/experience/rollout_recovery.py Resolved
macandro96 and others added 3 commits November 12, 2026 15:52
…rest training

Turn-level recovery (#4500) continues a restored episode as its next
attempt (<rollout_id>-a<N>) and keeps the calls the earlier attempt made,
still staged under that attempt's key. Forest training's ownership checks
(#4124, #4200) predate this and required every manifest row to be staged
under the current attempt's key. So every continued episode that had made
a model call before the checkpoint failed with "Forest recovery has
foreign staging ownership"; the rollout manager counted a data retry and
regenerated the episode from its prompt without logging why. Training
stayed correct, but turn (and prefix) recovery saved nothing under
forest training.

Accept a row staged under the current attempt or an earlier attempt of
the same rollout, the rule Gym's rebuild already applies through each
carried row's source_capture_key, at all four Forest ownership checks:
the recovery ledger, the finalizer request, selected-call planning and
logical-row finalization. Rows of another rollout or a later attempt are
still refused.

Also print each data retry with its error, so a prompt that is silently
regenerated shows why in the log.

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

Mirror Gym's rebuild instead of accepting any earlier attempt's key: a
manifest call without source_capture_key must be staged under the
receipt's own attempt, and a carried call must be staged under exactly
the attempt its stamp names, which must be an earlier attempt of the same
rollout. The recovery ledger checks this at seal time, before the rebuild
does, and decides which rows cleanup claims, so it now claims only rows a
restore explicitly carried over.

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

Address the first review of #5147:
- C1: the continued-attempt test also reads the request's
  capture_receipts, which cleanup uses and finalize() never reaches, so
  reverting the reassembler actor's ownership check now fails a test.
- C2: the continued Forest state builds its carried owner from its own
  ledger, so the later-attempt case reaches the attempt check instead of
  the rollout-id check, and a second restore (-a2 carrying calls from
  attempt 0 and -a1) is covered.
- C4: _owned_staging_key calls Gym's rebuild._staging_owner instead of
  restating it, so RL cannot drift from the rule Gym's rebuild applies.
  The old and new rule agree on 120 owner, stamp and call-id cases.

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 cbcd08f

@macandro96
macandro96 requested a review from terrykong November 12, 2026 23:57
@terrykong
terrykong enabled auto-merge (squash) November 13, 2026 00:36
@terrykong
terrykong merged commit c33a104 into main Nov 13, 2026
93 of 95 checks passed
@terrykong
terrykong deleted the amahishi/forest-continued-attempts branch November 13, 2026 02:37
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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants