Skip to content

feat(environment): pass the rollout index to resources seeds - #4652

Open
yaoyu-33 wants to merge 5 commits into
NVIDIA-NeMo:mainfrom
yaoyu-33:feat/seed-rollout-index
Open

yaoyu-33 wants to merge 5 commits into
NVIDIA-NeMo:mainfrom
yaoyu-33:feat/seed-rollout-index

Conversation

@yaoyu-33

@yaoyu-33 yaoyu-33 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Gives a resources server's /seed_session the rollout (repeat) index, so state keyed by repeat no longer has to be parsed out of the rollout ID.

A resources server that keeps state per repeat of a task, for example deliverables persisted under task_<id>/repeat_<n>/ so later stages can judge them without rerunning the policy, needs to know at seed time which repeat it is serving. Today it can't learn that reliably:

  • task_data is stripped of every _ng_* key (task_materialization.py:47), so _ng_rollout_index is gone.
  • EpisodeId holds only rollout_id and attempt. It has to round-trip through capture keys (EpisodeId.from_capture_key), and those don't encode the repeat, so the repeat can't be added there.
  • The only remaining option is parsing "<task_index>-<rollout_index>" out of rollout_id. That works for collector-generated IDs, but with an explicit _ng_rollout_id it either fails (a UUID) or picks the wrong repeat (batch-7 → repeat 7). Meanwhile verify reads _ng_rollout_index, so the seed and the reader of the same state disagree.

This came up while reviewing GDPVal's decoupling in #4178 (thread). There, putting the repeat on EpisodeId was tried and reverted for the capture-key reason above.

Change

The collector's _ng_rollout_index now travels next to the identity instead of inside it:

  • BaseEpisodeRequest.rollout_index: int | None (ge=0, default None).
  • ResourcesSeedSessionRequest.rollout_index: int | None (ge=0, default None).
  • The collector (_episode_request_body) and the single_agent_turn_legacy adapter fill it from the row.
  • single_agent_turn and nemo_user_sim forward it to /seed_session.

EpisodeId, capture keys and checkpoint identity are unchanged.

flowchart LR
    row["dataset row<br/>_ng_rollout_id: batch-7<br/>_ng_rollout_index: 2"]

    subgraph before["Before"]
        direction TB
        b_ep["episode request<br/>episode_id: {rollout_id: batch-7}<br/>task_input: no _ng_* keys"]
        b_seed["/seed_session<br/>episode_id + task_data"]
        b_rs["resources server<br/>parses repeat from 'batch-7' → 7 ✗"]
        b_ver["/verify<br/>reads _ng_rollout_index → 2"]
        b_ep --> b_seed --> b_rs
        b_rs -. "writes repeat_7, reads repeat_2" .- b_ver
    end

    subgraph after["After"]
        direction TB
        a_ep["episode request<br/>episode_id: {rollout_id: batch-7}<br/><b>rollout_index: 2</b>"]
        a_seed["/seed_session<br/>episode_id + task_data<br/><b>rollout_index: 2</b>"]
        a_rs["resources server<br/>uses rollout_index → 2 ✓"]
        a_ep --> a_seed --> a_rs
    end

    row --> b_ep
    row --> a_ep
Loading
sequenceDiagram
    participant C as Rollout collection
    participant E as Environment server<br/>(single_agent_turn / legacy / nemo_user_sim)
    participant R as Resources server
    C->>E: episode request {episode_id, task, rollout_index}
    Note over C,E: legacy flat rows: the adapter reads _ng_rollout_index itself
    E->>R: POST /seed_session {resources_session_id, episode_id, task_id, task_data, rollout_index}
    R-->>E: seed response (state keyed by task_id + rollout_index)
Loading

What the number means: it is exactly the row's _ng_rollout_index. The collector numbers each task's rollouts across every agent a row fans out to, so with two agents and num_repeats=4 the second agent's rollouts are 4–7. The numbers are stable for a materialized input. It is never parsed from episode_id.rollout_id. The field keeps the existing name, as genrm_compare, atif_reverification and others already use bare rollout_index for this key.

An Environment Server's /verify body still carries neither _ng_* keys nor this field, so a server that keys state by rollout number stores it with the session at seed time. The "Environment Server sessions" bullet in resources-server-apis.mdx now says so.

No resources server reads the field yet, so behavior is unchanged. Tracking: #4178. GDPVal there can switch its seed from the rollout-ID parse to body.rollout_index. Its in-session verify already uses the repeat stored at seed time, and its sessionless reuse reads _ng_rollout_index, so both then come from the same collector field. Ideally this lands just before or together with that switch.

Validation

All runs on macOS, Python 3.13, in a fresh uv venv for this branch (--extra dev --extra ray --extra sandbox):

  • pytest tests/unit_tests/{test_episode_types,test_rollout_collection,test_base_resources_server,test_task_materialization,test_session_contract_repo,test_checkpoint_resources,test_server_utils}.py: 799 passed.
  • Environment servers, each run separately: single_agent_turn 47, single_agent_turn_legacy 20, legacy_agent 5 and nemo_user_sim 28 passed. nemo_user_sim ran in a venv with the pinned nemo-usersim.
  • Resources servers that seed through ResourcesSeedSessionRequest or a union with it: example_single_tool_call 5, nullable_tool_args 4, swebench_pro 96, terminal_bench_2_1/tests/test_sessions.py 58 and nemo_user_sim 36 passed.
  • pre-commit run --files <changed files>: passed.
  • Each new test fails when its source line is reverted, checked one mutation at a time:
    • the collector line, including a truthiness check that would drop index 0;
    • the legacy adapter line;
    • the single_agent_turn and nemo_user_sim forwarding lines;
    • the ge=0 bound;
    • the null omission in the seed body.
  • I also ran a multi-agent review with a devil's-advocate pass over each finding. It found no blockers. This revision applies its notes.

Rollouts

N/A. This is wire plumbing for an optional field that no environment reads yet. Verifier inputs, rewards and existing seed behavior are unchanged.

Compatibility

  • The field is optional on both models, so the change is additive when every server runs this nemo_gym. Both models are extra="forbid", so a receiver on an older nemo_gym rejects the key when it is present.
  • The collector sends rollout_index only when the row has _ng_rollout_index, and collector rows always do. A newer collector therefore needs an Environment Server at this version.
  • The seed body leaves out a None index, so seeds without one still reach an older Resources Server unchanged.
  • Both fields are strict ints (True and "2" are rejected), matching how other _ng_rollout_index readers validate it. Collector rows always carry ints.
  • Seed handlers typed as a union with ResourcesSeedSessionRequest (swebench_pro, terminal_bench_2_1, interactive_browser) still resolve the same member with the field absent, null or set. This was checked with TypeAdapter.

🤖 Generated with Claude Code

A resources server that keys state by repeat (for example deliverables
persisted per repeat) has no reliable way to learn the repeat at seed time:
task_data carries no `_ng_*` keys and EpisodeId holds only the rollout ID and
attempt, so servers parse the repeat out of the rollout ID, which breaks for
explicit `_ng_rollout_id` values.

Carry the collector's `_ng_rollout_index` as an optional `rollout_index` on
BaseEpisodeRequest and ResourcesSeedSessionRequest, filled by the collector and
the legacy single-agent-turn adapter and forwarded by the single-agent-turn and
UserSim environment servers. EpisodeId is unchanged, so capture keys and
checkpoint identity keep round-tripping.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Oct 15, 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.

@yaoyu-33
yaoyu-33 marked this pull request as ready for review October 15, 2026 20:17
…known one off the wire

- Describe rollout_index as the row's `_ng_rollout_index`, numbered per task
  across fan-out agents and never parsed from the rollout ID, and say that an
  Environment Server's /verify does not carry it.
- Make both fields strict ints, like the other `_ng_rollout_index` readers.
- Omit a None rollout_index from the seed body, so a Resources Server built
  before the field still accepts seeds that carry no index.
- Document the field in the Environment Server sessions bullet.
- Test the UserSim seed forwarding and the omitted null.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@ananthsub ananthsub mentioned this pull request Oct 15, 2026
7 tasks
@yaoyu-33

Copy link
Copy Markdown
Contributor Author

A few questions that came up about this change:

  1. Is it for efficiency? No, it's for correctness. GDPVal persists deliverables per repeat and reloads them later. Today the seed guesses the repeat from rollout_id, which is wrong for explicit IDs and lets rollouts overwrite each other's files.
  2. Is it leakage? No. The index only reaches the resources server; the agent's seed and the model's input never include it, and legacy seeds already send it as _ng_rollout_index. A server should only use it as a storage key and never expose it to the model.
  3. How is it different from attempt? rollout_index says which of the N samples this is, and each repeat counts as its own scored sample in eval metrics (mean over repeats, pass@k). attempt counts retries of one sample after a failure (0, 1, 2…), and retries are not counted: only the final attempt is scored. For example, sample 1 retried runs as (rollout_index=1, attempt=0) then (rollout_index=1, attempt=1) and contributes one score.

@yaoyu-33 yaoyu-33 added area:env-infra Shared environment framework, lifecycle, registry, scaffolding, and validation complexity:high Cross-component or shared-contract change with a large review surface feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer labels Oct 16, 2026
@github-actions github-actions Bot added the sla:triage-overdue Review assignment is over the one-business-day SLA label Oct 16, 2026
yaoyu-33 and others added 2 commits October 22, 2026 03:33
…out-index

Signed-off-by: yaoyu-33 <[email protected]>

# Conflicts:
#	tests/unit_tests/test_rollout_collection.py
…out-index

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>

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

area:env-infra Shared environment framework, lifecycle, registry, scaffolding, and validation complexity:high Cross-component or shared-contract change with a large review surface feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer sla:triage-overdue Review assignment is over the one-business-day SLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant