Skip to content

feat(checkpoint): support typed Gym environment servers in turn/prefix recovery - #5340

Merged
terrykong merged 7 commits into
mainfrom
amahishi/gym-typed-env-checkpointing
Dec 4, 2026
Merged

terrykong merged 7 commits into
mainfrom
amahishi/gym-typed-env-checkpointing

Conversation

@macandro96

@macandro96 macandro96 commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor
  • I, the PR author, have personally reviewed every line of this PR.

What and why

Turn- and prefix-level rollout recovery used to work only when every Gym environment server was the legacy_agent relay. Recipes with a typed server (for example string_match's single_agent_turn_legacy) had to swap it back to legacy_agent or fall back to sibling recovery. The pinned Gym already checkpoints typed servers, so this PR lets RL use them:

  • Stop refusing typed servers. RL no longer rejects them at setup or when it discovers checkpoint participants. An episode a typed server exports counts as owned by it.
  • Resume a restored episode as the same task. Gym resumes an episode only for the task it started with, and RL gave every re-send a new task index, so Gym refused every continuation and RL quietly restarted it. RL now records each attempt's task index in the recovery ledger and re-sends a continued episode under it. This bumps the ledger schema to 10. Older checkpoints, including main's schema 9, still load.
  • Refuse servers that queue episodes. A server with max_concurrent_episodes set can hold a request in a queue the checkpoint cannot see, so every snapshot would time out. Turn/prefix recovery now refuses those setups up front.

The L1 functional test grpo_router_replay_prefix_recovery_single_controller_1n2g.sh no longer swaps string_match to legacy_agent, so it now covers a typed server end to end.

Issues

None.

Convergence / perf / functionality proof

  • Functional: grpo_router_replay_prefix_recovery_single_controller_1n2g.sh with the typed string_match server passes; Gym accepted all 4 restored episodes (0 of 4 before the task-index fix). Run before the rebase onto current main.
  • Unit tests cover the refusals, the ledger field and schema loading, and that the rollout manager sends and records each restored row's task index.

Needs upstream changes

None. The Gym version this needs (9e2e5d0ad) is already pinned on main.

PR commands and CI
  • CI label, exactly one:
    • CI:Lfast: the default for most PRs. Runs a fast test subset.
    • CI:L1: dependency or container changes (pyproject.toml, uv.lock, Dockerfile) or broad core changes. Builds a new image and runs unit and functional tests.
    • CI:docs: docs-only changes. Runs doc tests only.
  • /ok to test <full-commit-sha>: start CI for that commit. Post again after each push.
  • /nightly-ci test-case=<test>: run NVIDIA's nightly CI for the PR head; eligible teams only.
  • /review: automated review comments. Add mode=strict for a stricter review, reset=true for a fresh full review.
  • /resolve-conflict: Autobot merges main into this PR and resolves the conflicts. PRs from forks must allow edits by maintainers.
  • Locally: /review-pr-team <pr-number> for a team review before you ask for human review.
  • Contributor guidelines

🤖 Generated with Claude Code

@copy-pr-bot

copy-pr-bot Bot commented Nov 20, 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 macandro96 changed the title feat(checkpoint): support typed Gym environment servers in turn and prefix recovery feat(checkpoint): support typed Gym environment servers in turn/prefix recovery Nov 20, 2026
@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 20, 2026

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

  • Nit: "(the default for agents and resources servers)" in docs/guides/single-controller.md, single_controller_utils/config.py and both example YAMLs should also list environment servers, since they now reach this check.
  • I am wondering whether we should report your e2e result for partial rollout ckpting here.

Comment thread nemo_rl/experience/rollout_recovery.py Resolved
@github-actions github-actions Bot added the Documentation Improvements or additions to documentation label Nov 25, 2026
@macandro96
macandro96 force-pushed the amahishi/gym-typed-env-checkpointing branch from 040da6c to 4697dd6 Compare November 25, 2026 21:57
@macandro96

Copy link
Copy Markdown
Contributor Author

/ok to test 4697dd6

zyzhou5
zyzhou5 previously approved these changes Nov 25, 2026
@terrykong terrykong removed the Documentation Improvements or additions to documentation label Nov 28, 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.

Thanks @macandro96 — replacing the blanket refusal with one owner per episode is simpler than what was there, and the schema 9 bump keeps old checkpoints loading. We checked the Gym side at the pin: typed servers decode the <id>-a<N> restored ids, the task digest ignores every _ng_* key so keeping _ng_task_index is enough, and restart-only typed servers still go through allow_restart_only_gym_servers. The queue guard (37e1738) and the older-schema comment fix (51f84b3) look good.

  1. (C2) Add a unit test for the task-index wiring in the finalization dispatch.

Visual explainer: https://terrykong.github.io/gh-pages-poc/terryk/pr-5340-gym-server-roles.html
Visual explainer: https://terrykong.github.io/gh-pages-poc/terryk/pr-5340-typed-servers-resume.html

nemo-rl-review: kind=expert harness=claude-code/2.1.332 model=claude-opus-5-5 effort=medium review-pr-team=v3 reviewed=d421014

Comment thread nemo_rl/experience/rollout_manager.py Resolved
macandro96 and others added 7 commits December 3, 2026 16:35
Turn and prefix recovery refused every Gym environment server except the
legacy_agent relay, twice: at setup (_reject_typed_environment_servers)
and at checkpoint discovery (environment-kind participants). Configs had
to swap typed servers such as string_match's single_agent_turn_legacy
back to legacy_agent, or fall back to sibling recovery.

Gym already checkpoints these servers: each typed environment server is
an "environment" checkpoint participant that owns the episodes it runs,
and the agent sessions it opens for them are not the agent's own /run
episodes. Gym also decodes the restored-attempt rollout id <id>-a<N> for
both flat and materialized rows, so the setup guard's premise no longer
holds.

Remove both refusals and teach the commit summary that an environment
server's exported episodes are owned, so their agent sessions are no
longer reported as unowned live episodes. An episode claimed by more than
one participant of any kind still fails the commit. Restart-only servers
stay behind the existing allow_restart_only_gym_servers startup check.

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

A typed Gym environment server fingerprints each episode's task when it
starts and resumes a restored episode only for that task. A row without
its own task ID takes its Gym task ID from _ng_task_index, and RL gave
every rollout dispatch a fresh one, including the redispatch of a
restored group. Gym therefore saw each continued attempt as a different
task, refused it, and RL restarted it from its prompt: turn and prefix
recovery through a typed environment server silently became
restart-from-task.

Record each attempt's task index in the rollout-recovery ledger when it
is dispatched, persist it (schema 10; older schemas load without it), and
re-send an attempt that continues environment state under the index it
was first sent with. Every other row of the dispatch shares one fresh
index, so a restarted attempt never reuses keys the attempt it replaces
may have left in Gym. The ledger refuses a continued attempt whose index
changes.

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

Turn and prefix recovery now support typed Gym environment servers, so
drop the override that swapped string_match's single_agent_turn_legacy
server for legacy_agent. The test now exercises an environment-server
checkpoint participant: each restored episode resumes from the
environment server's saved boundary and its generation prefix.

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

With max_concurrent_episodes set, a Gym environment server queues a request
beyond the limit before it claims checkpoint state, so prepare does not report
it. The parked episodes keep their slots, so it cannot start, and every
snapshot times out waiting for its reply until the run aborts. Refuse the
setup instead, for typed servers and the legacy_agent relay alike.

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

Older checkpoints could only hold legacy_agent episodes, and Gym checks the
task only for episodes an environment server exported itself, so those
continuations resume rather than start over.

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

Environment servers now reach the restart-only startup check, and
BaseEnvironmentServer also defaults to restart_only.

Signed-off-by: Anish Mahishi <[email protected]>
…ow's task index

Runs generate_for_finalization on a restored turn group through the Gym
rollout impl: the continued sibling goes out and is recorded under its
original task index, the restarted one under a fresh index.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
@macandro96
macandro96 force-pushed the amahishi/gym-typed-env-checkpointing branch from 4697dd6 to 8933c5a Compare December 4, 2026 00:41
@svcnvidia-nemo-ci svcnvidia-nemo-ci added complexity:medium Moderate change. Set by Autobot PR classify (skills/pr-classify) convergence-risk:high Likely to change training results. Set by Autobot PR classify (skills/pr-classify) proof:convergence Needs convergence proof (W&B runs). Set by Autobot PR classify (skills/pr-classify) proof:functionality Needs proof that it works. Set by Autobot PR classify (skills/pr-classify) labels Dec 4, 2026
@macandro96

Copy link
Copy Markdown
Contributor Author

/ok to test 8933c5a

@terrykong
terrykong enabled auto-merge (squash) December 4, 2026 01:13
@terrykong
terrykong merged commit cbae833 into main Dec 4, 2026
114 of 117 checks passed
@terrykong
terrykong deleted the amahishi/gym-typed-env-checkpointing branch December 4, 2026 02:57
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) complexity:medium Moderate change. Set by Autobot PR classify (skills/pr-classify) convergence-risk:high Likely to change training results. Set by Autobot PR classify (skills/pr-classify) proof:convergence Needs convergence proof (W&B runs). Set by Autobot PR classify (skills/pr-classify) proof:functionality Needs proof that it works. Set by Autobot PR classify (skills/pr-classify)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants