Skip to content

feat(rollout): task_source resolution and run-level fan-out - #2713

Merged
kajalj22 merged 8 commits into
mainfrom
data-prep/task-source-resolver
Aug 26, 2026
Merged

kajalj22 merged 8 commits into
mainfrom
data-prep/task-source-resolver

Conversation

@adil-a

@adil-a adil-a commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Every dataset row must name the exact agent instance that runs it (agent_ref.name), baked in at data prep. Consequences:

  1. Swapping agents means regenerating data. Rename an agent or try a different harness → re-stamp every row.
  2. Comparing N agents on the same tasks means duplicating data. genrm_compare commits the same example.jsonl twice, jailbreak_detection five times — once per agent alias, differing only in the stamp.
  3. Stale stamps rot. swe_agents_val/swe_agents_train are alias configs that exist only so old stamped rows still resolve.

Change

1. Rows can carry task_source instead of agent_ref.

task_source = the name of the config instance that declared the row's dataset. It is a fact about the data. The agent is computed from it at dispatch time.

# Before — physical agent baked in:
{"responses_create_params": {...}, "agent_ref": {"name": "math_with_judge_simple_agent"}}
# After — stable across agent renames and harness swaps:
{"responses_create_params": {...}, "task_source": "math_with_judge"}

2. How a row finds its agent — first hit wins:

Step Rule Example
1 agent_map entry for either name the row carries — its agent_ref.name or its task_source (agent name wins) +agent_map={math_with_judge: math_with_judge_swe_agent} re-routes rows stamped task_source: math_with_judge. Values must be agent instance names; mapping to anything else fails validation.
2 Row has agent_ref → use it unchanged legacy datasets: identical behavior to today
3 task_source names an agent instance → route to it task_source: tau2_agent → tau2_agent (self-contained envs verify in-process and declare their own datasets)
4 task_source names a resources server → route to the one agent whose config points at it task_source: math_with_judge → math_with_judge_simple_agent, found via the resources_server: {name: math_with_judge} line already in its config
5 Anything else → error before any dispatch unknown name → "did you mean …"; 2+ candidate agents → "pass +agent_map={math_with_judge: <agent>}"

The resolved agent_ref is written into materialized inputs before dispatch, so drivers that read row["agent_ref"] from materialized rows (e.g. gdpval's orchestrator) see exactly what they see today.

3. New fan_out config: run the same rows under N agents in one run.

# Before: commit the same example.jsonl once per agent alias (genrm: 2 copies, jailbreak: 5).
# After: one file, one flag:
gym eval run --no-serve -i tasks.jsonl \
    '+fan_out={genrm_compare_resources_server: [genrm_simple_agent, genrm_simple_agent_reasoning_off]}'

Fan-out happens at run preprocessing, not at collate. Data on disk stays one row per task; the per-agent copies exist only inside the run:

collated file (reusable, agent-free):   1 row: {task_data, task_source: shared_rs}
run preprocessing (+fan_out):           2 in-memory copies, each stamped with its target:
                                          {..., agent_ref: {name: agent_a}, _ng_rollout_index: 0}
                                          {..., agent_ref: {name: agent_b}, _ng_rollout_index: 1}
materialized inputs (run-scoped):       those 2 stamped copies, written to disk
dispatch / outputs:                     each copy POSTs to its own agent; outputs carry its agent_ref

So no artifact ever holds per-agent copies distinguished only by task_source — the copy and its agent stamp are created in the same step. Outputs group per agent for metrics exactly as today. Fan-out keys match the name the data carries (its agent_ref.name or task_source); targets are final and are not re-mapped by agent_map.

4. agent_map and dict-form num_repeats key on the routing name a row carries — whichever it is.

Rows used to always carry an agent name, so these dicts keyed on agent names. Rows may now carry task_source instead, and the dicts match that too:

# Row {"task_source": "math_with_judge"} — both of these match it:
+agent_map='{math_with_judge: some_agent}'
+num_repeats='{math_with_judge: 32, _default: 1}'
# Fan-out targets are agent names; repeats apply per target:
+fan_out='{shared_rs: [agent_a, agent_b]}' +num_repeats='{agent_a: 32, agent_b: 1}'

What does NOT change

  • Rows with agent_ref: byte-identical behavior (resolution step 2 short-circuits). Verified by replaying preprocessing + dispatch over all 220 runnable config closures in the repo: identical materialized inputs and routes.
  • Nothing writes task_source yet. This PR is the consumer; the collate-side producer is the next PR in the stack.

Tests

119 passed. New contract tests pin: RS→agent inversion, self-contained direct routing, unknown/zero/ambiguous/non-agent errors, legacy-row precedence, dual-stamped-row agent_map matching, fan-out expansion + per-agent repeats + end-to-end dispatch to distinct agents + interaction with agent_map, task_source-keyed agent_map/num_repeats. Live-model smoke rollouts on the fan-out pattern (genrm_compare) are planned before the stack merges, per the repo's real-rollout policy.

Reward profiling under fan-out

gym eval profile groups its per-row report by task index. Fan-out copies of a task share a task index, so a fanned run's profile pooled every agent's rollouts into one row per task. Fixed in this PR: when a task's materialized inputs span more than one agent, the profiler groups per (task, agent) — each harness gets its own profile row (stamped with agent_ref), its own rollout counts, and its own sample. The completion summary counts the same way, so one agent's missing rollouts can't hide behind another's completed ones.

Runs where every task has one agent — everything that exists today, including the aggregate-metrics path behind the committed metrics sidecars — keep the exact per-task grouping: verified by re-running gym eval profile on a pre-change artifact and comparing output bytes (identical), plus a contract test pinning that single-agent profile rows gain no new fields.

Stack

PR 2 of the dataset↔agent decoupling stack (RFC: gym-dataset-preparation, Open Question 1). Base: #2710.

🤖 Generated with Claude Code

@copy-pr-bot

copy-pr-bot Bot commented Aug 24, 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.

Comment thread nemo_gym/rollout_collection.py Resolved
Comment thread nemo_gym/rollout_collection.py Resolved
Comment thread nemo_gym/rollout_collection.py Resolved
We provide this function as a lower level interface for running rollout collection.
"""
server_client = self.setup_server_client(head_server_config)
self.resolve_task_sources(examples, server_client.global_config_dict)

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.

Direct run_examples callers receive task_source resolution here, but they do not receive agent_map, fan_out, or num_repeats, which are applied only by _preprocess_rows_from_config.

NeMo RL calls this lower-level API: https://github.com/NVIDIA-NeMo/RL/blob/a8d4c4e66964c2b4fb01eecb82c1d84c02fc94d6/nemo_rl/environments/nemo_gym.py#L688-L690

so we need a public preprocessing entry point for such callers

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added in 3aa2fec: public RolloutCollectionHelper.preprocess_examples(examples, *, agent_map=None, fan_out=None, num_repeats=1, num_repeats_add_seed=False, global_config_dict=None). It applies the run-level knobs to caller-held rows with the same validation as the CLI path, does not mutate the inputs, and optionally resolves task_sources (or leaves that to run_examples, which keeps doing it on dispatch). run_examples' docstring now points callers at it. Happy to follow up with a NeMo RL-side change to adopt it.

@adil-a adil-a added data and removed data labels Aug 26, 2026
@adil-a
adil-a force-pushed the data-prep/task-source-resolver branch from 9ac2e47 to 3aa2fec Compare August 26, 2026 02:20
@adil-a

adil-a commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 3aa2fec

@adil-a

adil-a commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test d3e5d4e

@adil-a
adil-a force-pushed the data-prep/task-source-resolver branch from 3aa2fec to d3e5d4e Compare August 26, 2026 06:20
marta-sd pushed a commit that referenced this pull request Aug 26, 2026
…cess API

Review feedback on #2713:

1. fan_out misconfiguration failed silently: an empty target list dropped
   every matching row (zero rollouts collected), and duplicate targets ran
   the row twice under one agent. Both now fail at config validation with
   actionable messages.

2. agent_map={source: agent} + num_repeats={source: k} did not compose:
   after the re-route, repeats were looked up only by the dispatched agent
   name, so the source-keyed entry was missed (error, or silent _default).
   num_repeats keys now match either side of a re-route - the dispatched
   agent (fan_out/agent_map target) or the row's original routing key
   (agent_ref.name / task_source as written in the data) - with the
   dispatched agent winning when both have entries. The missing-key error
   names both candidates; source-keyed entries no longer trip the typo
   warning.

3. Direct run_examples callers (e.g. NeMo RL drives dispatch through it)
   got task_source resolution but no agent_map/fan_out/num_repeats, which
   lived only inside the file-reading preprocessing. New public
   RolloutCollectionHelper.preprocess_examples(examples, ...) applies the
   run-level knobs to caller-held rows (same validation as the CLI path,
   inputs not mutated, optional task_source resolution), and
   run_examples's docstring points at it.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
@marta-sd
marta-sd force-pushed the data-prep/task-source-resolver branch from d3e5d4e to 5cda9ac Compare August 26, 2026 10:08
adil-a added a commit that referenced this pull request Aug 26, 2026
…cess API

Review feedback on #2713:

1. fan_out misconfiguration failed silently: an empty target list dropped
   every matching row (zero rollouts collected), and duplicate targets ran
   the row twice under one agent. Both now fail at config validation with
   actionable messages.

2. agent_map={source: agent} + num_repeats={source: k} did not compose:
   after the re-route, repeats were looked up only by the dispatched agent
   name, so the source-keyed entry was missed (error, or silent _default).
   num_repeats keys now match either side of a re-route - the dispatched
   agent (fan_out/agent_map target) or the row's original routing key
   (agent_ref.name / task_source as written in the data) - with the
   dispatched agent winning when both have entries. The missing-key error
   names both candidates; source-keyed entries no longer trip the typo
   warning.

3. Direct run_examples callers (e.g. NeMo RL drives dispatch through it)
   got task_source resolution but no agent_map/fan_out/num_repeats, which
   lived only inside the file-reading preprocessing. New public
   RolloutCollectionHelper.preprocess_examples(examples, ...) applies the
   run-level knobs to caller-held rows (same validation as the CLI path,
   inputs not mutated, optional task_source resolution), and
   run_examples's docstring points at it.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
@adil-a
adil-a force-pushed the data-prep/task-source-resolver branch from e2b495b to 3edb28a Compare August 26, 2026 19:31
@adil-a

adil-a commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 3edb28a

adil-a added a commit that referenced this pull request Aug 26, 2026
…cess API

Review feedback on #2713:

1. fan_out misconfiguration failed silently: an empty target list dropped
   every matching row (zero rollouts collected), and duplicate targets ran
   the row twice under one agent. Both now fail at config validation with
   actionable messages.

2. agent_map={source: agent} + num_repeats={source: k} did not compose:
   after the re-route, repeats were looked up only by the dispatched agent
   name, so the source-keyed entry was missed (error, or silent _default).
   num_repeats keys now match either side of a re-route - the dispatched
   agent (fan_out/agent_map target) or the row's original routing key
   (agent_ref.name / task_source as written in the data) - with the
   dispatched agent winning when both have entries. The missing-key error
   names both candidates; source-keyed entries no longer trip the typo
   warning.

3. Direct run_examples callers (e.g. NeMo RL drives dispatch through it)
   got task_source resolution but no agent_map/fan_out/num_repeats, which
   lived only inside the file-reading preprocessing. New public
   RolloutCollectionHelper.preprocess_examples(examples, ...) applies the
   run-level knobs to caller-held rows (same validation as the CLI path,
   inputs not mutated, optional task_source resolution), and
   run_examples's docstring points at it.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
@adil-a
adil-a force-pushed the data-prep/task-source-resolver branch from 3edb28a to 511de16 Compare August 26, 2026 20:06
@adil-a

adil-a commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 511de16

@adil-a

adil-a commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 5f42941

@adil-a

adil-a commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test adeebb2

kajalj22
kajalj22 previously approved these changes Aug 26, 2026
adil-a and others added 8 commits August 26, 2026 14:09
Rows may now carry task_source — the name of the config instance that declared
their dataset — instead of a physical agent_ref. Resolution to an agent happens
at dispatch preparation, against the merged running config:

- instance is an agent (self-contained environment) -> route to it directly
- instance is a resources server -> route to the unique agent whose
  resources_server.name edge references it (inversion of the edge every agent
  config already declares); 0 or 2+ candidates is a hard pre-dispatch error,
  with +agent_map named as the disambiguator
- unknown or non-routable instance -> hard error with did-you-mean

Resolved agent_refs are stamped into materialized inputs (run-scoped artifacts;
custom drivers read them there) before anything is dispatched. Rows that already
carry agent_ref are untouched, so legacy datasets and materialized artifacts
behave identically.

Also adds fan_out: run each matching row once per listed agent (cross-product),
keyed by agent_ref.name or task_source, composing with per-agent num_repeats.
This replaces the committed-data pattern of duplicating rows per agent alias
(genrm_compare, jailbreak_detection). agent_map and num_repeats dict keys now
also match task_source values.

No observable change for existing data: routing-equivalence replay over all 220
runnable config closures shows byte-identical materialized inputs and routes.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
…re agents

Two edge gaps in the task_source resolver:

1. Derived artifacts carry BOTH task_source and a resolved agent_ref; agent_map
   lookup only checked the agent name, so a task_source-keyed entry silently
   failed to match such rows. Lookup now checks both names (agent name wins).

2. _validate_agent_names accepted any top-level config key, so routing to a
   non-agent instance (e.g. agent_map to a resources server name) passed
   validation and died at runtime with a 404 on /run. Validation now requires
   the target to be an agent instance and says so in the error.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
Pins that fanned copies POST to their distinct agent servers end-to-end
(through run_examples), and that fan_out keys match the data-side name with
targets final over a competing agent_map rewrite.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
The guard that resolves task_source rows before the materialized-inputs write
was untested (it is dormant until collate produces task_source-only rows).
Pins that materialized rows carry the resolved agent_ref alongside task_source.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
…_ref

Rows carrying agent_ref with no task_source are the legacy routing path (old
collated/prepped artifacts). They keep working unchanged; each run now emits
one DeprecationWarning with the row count, pointing at re-collation or
+agent_map. The path itself is removed only after the deprecation cycle, gated
on trainer integrations embedding current Gym.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
Outputs stamped agent_ref but dropped task_source, losing which environment
produced each rollout (surfaced by live smoke: outputs had task_source=None).
Provenance now carries both.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
Fan-out dispatches the same task to several agents, and those dispatch
copies share a task index. The reward profiler grouped rollouts by task
index alone, so a fanned run's per-row profile pooled every agent's
rollouts into one row per task - the per-harness reward/length split was
only recoverable by hand from the stamps.

Now, when any task's materialized inputs span more than one agent, the
profiler groups per (task, agent): each harness keeps its own profile row
(stamped with agent_ref, like the agent-level metrics), its own rollout
counts, and its own sample. The completion summary counts per (task,
agent) the same way, so one agent's missing rollouts cannot hide behind
another's completed ones.

Runs where every task has a single agent - everything that exists today,
including the aggregate-metrics path behind the committed metrics
sidecars - keep the plain per-task grouping and byte-identical output
(verified by re-running gym eval profile on a pre-change artifact and
comparing bytes).

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
…cess API

Review feedback on #2713:

1. fan_out misconfiguration failed silently: an empty target list dropped
   every matching row (zero rollouts collected), and duplicate targets ran
   the row twice under one agent. Both now fail at config validation with
   actionable messages.

2. agent_map={source: agent} + num_repeats={source: k} did not compose:
   after the re-route, repeats were looked up only by the dispatched agent
   name, so the source-keyed entry was missed (error, or silent _default).
   num_repeats keys now match either side of a re-route - the dispatched
   agent (fan_out/agent_map target) or the row's original routing key
   (agent_ref.name / task_source as written in the data) - with the
   dispatched agent winning when both have entries. The missing-key error
   names both candidates; source-keyed entries no longer trip the typo
   warning.

3. Direct run_examples callers (e.g. NeMo RL drives dispatch through it)
   got task_source resolution but no agent_map/fan_out/num_repeats, which
   lived only inside the file-reading preprocessing. New public
   RolloutCollectionHelper.preprocess_examples(examples, ...) applies the
   run-level knobs to caller-held rows (same validation as the CLI path,
   inputs not mutated, optional task_source resolution), and
   run_examples's docstring points at it.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
@adil-a

adil-a commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 1aa089c

This branch was previously deployed

1 inactive deployment
public — 1aa089c0 Deployed Aug 26, 2026 by copy-pr-bot[bot] via release / finalize / notify #2035
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants