A Gym server with an episode cap makes every rollout snapshot time out

NVIDIA-NeMo/RL #5340. NeMo-RL links pin the PR head d421014e; Gym links pin 9e2e5d0a, the version RL pins. First raised by another reviewer on the PR; this page backs it with the RL side.

Before
Turn and prefix recovery refused typed Gym servers, so a server's episode cap never met a snapshot. The legacy_agent relay ignores the cap.
This PR
Lets typed servers through, including ones that set max_concurrent_episodes.
Status
Open — not fixed in this PR. Raised in the review as C1, a reply on the existing thread. Shipped Gym benchmarks set the cap (enterpriseops_gym 64, gdpval 32, officeqa_pro 8), so turn recovery on them would abort. The PR's own test uses string_match, which leaves the cap off, so it does not hit this. Found by reading the code; not run.

Three pages on this PR, one question each. This one: why a capped server stalls snapshots, and the proposed guard.

A typed Gym server with max_concurrent_episodes lets that many episodes run; the rest wait for a free slot (the wait). A waiting row is not yet known to Gym's checkpoint: it registers only later, in claim/begin. So at a snapshot Gym saves the running episodes and pauses them, still holding their slots, and says nothing about the waiting row. RL sent that row, so it waits for its answer (_drain_non_exported_candidates) for token_capture.control_timeout_s, 60 s by default (config.py:756). The row cannot start until a paused episode frees its slot, which only happens after the snapshot.

One snapshot on a server with 4 slots and 5 rows

① Gym environment server, max_concurrent_episodes = 4, queue_timeout_seconds = 86400 r0 slot r1 slot r2 slot r3 slot r4 waiting waits for a slot before it registers with the checkpoint At the snapshot: r0–r3 are saved and paused, and keep their slots. r4 is in no list Gym reports. base_environment_server.py:337 (wait) :375 (register) ② RL: r4 was sent but Gym neither saved it nor marked it "restart" → wait for r4's answer deadline = now + control_timeout_s (60 s) … r4 can only move after 86400 s TimeoutError: could not classify every candidate before the drain deadline checkpointing/nemo_gym.py:466 ③ the snapshot fails; the next one meets the same queue (async RL keeps the server full) consecutive_failures: 1 → 2 → 3 (max_consecutive_failures = 3) RuntimeError: periodic rollout checkpoint failed 3 consecutive times → run stops snapshots.py:1321 saved by Gym the problem Numbers are from the shipped enterpriseops_gym config (64 slots there, 4 here to fit), RL's defaults (60 s, 3). If queue_timeout_seconds were under 60 s, the snapshot would pass but each waiting row would fail and use a retry.

Configs that set the cap with a long wait: enterpriseops_gym (64 slots, 86400 s), gdpval (32, 86400 s), officeqa_pro (8, 600 s). Gym requires the wait whenever the cap is set (validate_queue_timeout). The legacy_agent relay never takes a slot (run_legacy), which is why this never showed up before.

What would fix it — proposed, not in the PR

Where the fix lands: RL now, Gym later. In RL, refuse turn/prefix recovery at setup when a typed server sets the cap, in initialize_checkpoint_adapter, where the old typed-server refusal ran. In Gym (an issue, not this PR): a row still waiting for a slot should fail at once with the same retryable "admission closed" error a new row gets (environment.py:105) once a checkpoint starts. Then the RL check can go.

The guard, as pseudocode (proposed, not run)

# Gym actor, once, before the first checkpoint
def initialize_checkpoint_adapter():
    capped = [f"{inst}.{kind}: cap={s.max_concurrent_episodes}, wait={s.queue_timeout_seconds}"
              for inst, entry in gym_config            # every Gym server instance
              for kind, s in entry.environment_servers  # its typed servers
              if s.max_concurrent_episodes is not None]
    if capped:
        raise ValueError(f"turn/prefix recovery cannot snapshot rows waiting for a slot: {capped}")
    adapter = GymCheckpointAdapter(...)
    await adapter.discover()

A unit test: one capped and one uncapped server; only the capped one is named in the error.

The consequence. Turning on turn or prefix recovery for a benchmark that caps its episodes ends the run after three snapshots, mid-training, and the error says nothing about the cap. A setup check turns that into a clear refusal at startup, before any GPU time is spent.

🔴 review comment C1 — reply on gym_checkpoint_adapter.py:190