Skip to content

feat(data): collate stamps task_source; datasets declarable on resources servers - #2717

Merged
kajalj22 merged 4 commits into
mainfrom
data-prep/rs-datasets-collate
Aug 26, 2026
Merged

kajalj22 merged 4 commits into
mainfrom
data-prep/rs-datasets-collate

Conversation

@adil-a

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

Copy link
Copy Markdown
Contributor

Problem

Today a dataset can only be declared inside an agent's config block, and gym dataset collate writes that agent's name into every prepared row. Three concrete failures:

  1. The data is welded to one agent. Which agent runs a dataset is decided by which config block the datasets: list sits in, and then frozen into every row of the output.
  2. Two declarations of the same file corrupt the output. When two config blocks declare the same jsonl_fpath, the second one's prepared file overwrites the first's. All rows end up labeled with the second declarer. This happens silently. Real case in this repo: the swe_agents_val/swe_agents_train alias configs.
  3. Swapping the verifier requires re-wiring agents. The dataset belongs to whatever agent declares it, so pointing the same data at a different resources server means editing agent configs.

Change

1. Datasets can now be declared inside a resources server's block.

# Before — the dataset belongs to whichever AGENT declares it:
math_with_judge_simple_agent:
  responses_api_agents:
    simple_agent:
      resources_server: {name: math_with_judge}
      datasets: [{name: train, jsonl_fpath: ...}]

# After — the dataset belongs to the RESOURCES SERVER that verifies it:
math_with_judge:
  resources_servers:
    math_with_judge:
      datasets: [{name: train, jsonl_fpath: ...}]

Where a datasets: list is allowed to live, enforced when the config loads:

datasets: declared inside… Result
a resources server's block Allowed. This is the new recommended home: the resources server defines what the rows mean and how they are scored.
an agent's block, where the agent's config has no resources_server: line (tau2, osworld, the SWE harnesses — these agents score their own results in-process; there is no separate resources server) Allowed. The agent genuinely owns this data.
an agent's block, where the agent's config does have a resources_server: {name: X} line Still works, unchanged and silently. (The deprecation warning for this case ships with the config-migration PR, not here — warning now would make every un-migrated in-repo config warn about a move the migration performs anyway. Once configs are migrated, the warning's only remaining audience is out-of-repo configs.)
a model server's block Hard error.

2. Collate labels every prepared row with task_source = the name of the block that declared its dataset.

A prepared row, before:

{"responses_create_params": {"...": "..."}, "question": "...", "expected_answer": "...",
 "agent_ref": {"type": "responses_api_agents", "name": "math_with_judge_simple_agent"}}

After — the agent name is gone; the declaring block's name is the only label:

{"responses_create_params": {"...": "..."}, "question": "...", "expected_answer": "...",
 "task_source": "math_with_judge"}

At run time, #2713's resolver turns task_source back into an agent by reading the current config. Collated output carries no agent_ref at all — the agent is a run-time choice, never part of the data. Two compatibility rules make this safe:

Case Behavior
An old collated file (rows with agent_ref, no task_source) is fed to a run Works unchanged — the resolver honors legacy rows, with one DeprecationWarning per run counting them
A source row arrives at collate still carrying a legacy agent_ref The field is stripped from the output (one warning per file) — routing for a declared dataset comes from the declaration, and passing the stale field through would leak the old coupling into the clean format

The version rule that follows: new collated files require a Gym with the resolver (this release) at training time. Old files work everywhere, forever (until the separately-gated cleanup PR). A CI contract test pins the processed format — every collated row has task_source + responses_create_params and never agent_ref — so format drift cannot land silently.

3. Fix: declaring the same source file twice no longer corrupts the output.

Background: collate works in two steps. For each datasets: entry it first writes an intermediate "prepared" file next to the source data (example.jsonl → example_prepare.jsonl), containing that dataset's rows with the routing label added. Then it concatenates all the prepared files into the final output.

The prepared file's name came only from the source filename. So when two config blocks declare the same source file — real configs do this: swe_agents_val and swe_agents_train both declare one example.jsonl, and jailbreak's five policy agents share one too — both declarations wrote to the same prepared file, and the second write deleted the first. The final output then contained the rows twice, both copies labeled with the second declarer. The first declarer's correctly-labeled rows were silently gone.

# Before: agent_a and agent_b both declare example.jsonl
#   → one prepared file, written twice; the final output has 2 copies of the rows,
#     BOTH labeled agent_b. No warning.

# After: each declaration writes its own prepared file
example_prepare.jsonl          ← agent_a's rows, labeled agent_a
example_prepare.agent_b.jsonl  ← agent_b's rows, labeled agent_b
#   → the final output has 2 copies, each labeled by the block that declared it

4. gym eval reverify uses task_source to find the verifier. When a row carries task_source naming a resources server, reverify sends the row straight there — it no longer needs to look the agent name up first. Two silent behaviors also become loud: (a) when the config has no agent blocks and exactly one resources server, reverify sends every row there no matter what agent name the row carries — it still does, but now prints a warning saying so, because this mode also hides typos and stale names; (b) a row whose agent name is unknown used to crash with a bare KeyError — it now gets an error stating the row's agent name, its task_source, and the list of known agents.

What does NOT change

We re-ran the full pipeline (load configs → collate → build the run's input rows → send each row to its agent, with the network call stubbed out) on every runnable config in this repo — 225 of them — on the code before and after this PR, and compared the outputs:

  • Which agent every row goes to, and the run's input rows: identical.
  • The content of all 323 prepared/collated output files: identical. (Compared with the two label fields removed from each row first, so only real content changes would show. None did — every file differs only by the added task_source label.)
  • The only new files are the four swe_agents alias outputs that the old code was silently deleting (problem 2).
  • No repo configs are moved in this PR, and no warnings fire for existing configs. Every existing agent-block declaration keeps working exactly as today. The mechanical migration of the ~271 config files — and the deprecation warning for un-migrated agent-block declarations — is the next PR in the stack.

Tests

284 passed across the collate/rollout/reverify suites. New tests pin every rule above: each row of both tables, the per-declaration file separation, and reverify's task_source routing and loud fallback.

Where agent_ref is headed

To be explicit: agent_ref in data files ends with this stack. This PR stops writing it into prepared/collated files entirely:

Stage agent_ref in data files
Today Required — the only routing mechanism
This PR Never written by collate; stripped (with a warning) from incoming source rows. Old collated files keep working via the resolver's legacy-row support, with a deprecation warning
Next PR (data migration) Stripped from all committed source datasets in the repo
Later, gated (residual cleanup) The legacy-row routing path is removed once major trainer integrations embed current Gym; --agent's routing meaning retires in favor of #1583's asset selector

It survives permanently in exactly one place: run outputs (rollout results, materialized inputs), where Gym computes and records which agent actually ran each row — provenance, not routing.

Stack

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

🤖 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_reverification.py Resolved
Comment thread nemo_gym/train_data_utils.py Resolved
@adil-a
adil-a force-pushed the data-prep/rs-datasets-collate branch from 87daca3 to a2aa069 Compare August 25, 2026 18:37
@adil-a adil-a added data and removed data labels Aug 26, 2026
@adil-a
adil-a force-pushed the data-prep/rs-datasets-collate branch from a2aa069 to b5b4c6e Compare August 26, 2026 02:20
@adil-a

adil-a commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test b5b4c6e

@adil-a

adil-a commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 2ffcbf0

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

Review feedback on #2717:

1. /verify routed rows with _rs_for_row (task_source authoritative), but
   reverified results retained only agent_ref, and aggregation grouped by
   agent and posted to the agent's configured resources server - so a
   remapped row could be verified by one server and aggregated by
   another. Reverified results now retain task_source, the aggregation
   projection carries it, and aggregation routes each group with the SAME
   _rs_for_row resolver (grouped per (agent, resources server)).

2. The per-declaration prepared-file fallback ({stem}_prepare.{instance})
   collided when ONE instance declared the same jsonl_fpath repeatedly:
   every declaration after the first picked the same name and overwrote
   its predecessor. Candidates are now tried until unused - bare stem,
   instance-qualified, instance+dataset-qualified, then numbered - so
   the existing names stay byte-identical and repeats within an instance
   get distinct files. Tests cover 3x same path in one instance and 4x
   with identical dataset names.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
@adil-a
adil-a force-pushed the data-prep/rs-datasets-collate branch from 350ed9c to 4f649fa Compare August 26, 2026 18:42
@adil-a

adil-a commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 4f649fa

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

Review feedback on #2717:

1. /verify routed rows with _rs_for_row (task_source authoritative), but
   reverified results retained only agent_ref, and aggregation grouped by
   agent and posted to the agent's configured resources server - so a
   remapped row could be verified by one server and aggregated by
   another. Reverified results now retain task_source, the aggregation
   projection carries it, and aggregation routes each group with the SAME
   _rs_for_row resolver (grouped per (agent, resources server)).

2. The per-declaration prepared-file fallback ({stem}_prepare.{instance})
   collided when ONE instance declared the same jsonl_fpath repeatedly:
   every declaration after the first picked the same name and overwrote
   its predecessor. Candidates are now tried until unused - bare stem,
   instance-qualified, instance+dataset-qualified, then numbered - so
   the existing names stay byte-identical and repeats within an instance
   get distinct files. Tests cover 3x same path in one instance and 4x
   with identical dataset names.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
@adil-a
adil-a force-pushed the data-prep/rs-datasets-collate branch from 4f649fa to 4d23c17 Compare August 26, 2026 19:32
@adil-a

adil-a commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 4d23c17

@adil-a

adil-a commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test e5ca6fc

@adil-a

adil-a commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 8b5cf38

kajalj22
kajalj22 previously approved these changes Aug 26, 2026
@adil-a

adil-a commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 0fd5971

adil-a and others added 4 commits August 26, 2026 14:15
…ces servers

Producer side of the dataset-agent decoupling (consumers shipped in the
previous PR):

- Datasets may be declared on resources server blocks (the decoupled home: the
  RS owns the task schema and verifier). Data prep now reads datasets from any
  declaring instance — RS or agent. Model servers with datasets are a hard
  error. Agent-block declarations where the agent has a resources_server edge
  get a deprecation warning; self-contained agents (no RS edge) are exempt,
  they are the legitimate declaring instance.

- Collate stamps task_source = the declaring instance name onto every prepared
  row, per declaration. The legacy agent_ref is dual-stamped for one
  deprecation cycle: the declaring instance itself when it is an agent
  (byte-identical to today), else the unique agent referencing the declaring
  RS; ambiguous cases stamp task_source only and resolve at dispatch.

- Per-declaration prepared files: two instances declaring the same jsonl_fpath
  previously had the second silently truncate the first, leaving all rows with
  the last declarer's stamp. Each declaration now writes its own file
  (collision-suffixed with the instance name).

- Reverify routes by task_source when a row carries one (the declaring RS is
  authoritative; no agent indirection); the resources-only single-RS fallback
  now warns loudly instead of silently absorbing stale agent names, and
  unmapped rows fail with a clear error instead of a bare KeyError.

- agents_by_resources_server() extracted to global_config and shared by the
  dispatch resolver and collate.

Replay verification over all 225 runnable config closures: zero routing or
materialized-input changes; zero prepared-row content changes (stamp-only
diffs on all 323 prepared/collated files); the only new files are the four
swe_agents alias declarations that were previously silently truncated.

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

Warning about agent-block dataset declarations before the in-repo configs are
migrated would make every collate run warn about a move the migration PR
performs anyway. Both declaration homes are equally supported until then; the
warning ships together with the migrated configs, where its only remaining
audience is out-of-repo configs.

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

Processed datasets carry no agent identity: the dual-stamped legacy agent_ref
is removed from collate output (the agent is a run-time choice, resolved from
config at dispatch). Rows arriving with a legacy agent_ref get it stripped,
with one DeprecationWarning per file. Consequences for consumers: old collated
files keep working via the resolver's legacy path (deprecated separately); new
collated files require a Gym version with the resolver at training time —
trainer integrations coordinate their embedded-Gym bump with this release.

Adds the processed-format contract test: every collated row has task_source
and responses_create_params, and never agent_ref, so format drift cannot land
silently.

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

Review feedback on #2717:

1. /verify routed rows with _rs_for_row (task_source authoritative), but
   reverified results retained only agent_ref, and aggregation grouped by
   agent and posted to the agent's configured resources server - so a
   remapped row could be verified by one server and aggregated by
   another. Reverified results now retain task_source, the aggregation
   projection carries it, and aggregation routes each group with the SAME
   _rs_for_row resolver (grouped per (agent, resources server)).

2. The per-declaration prepared-file fallback ({stem}_prepare.{instance})
   collided when ONE instance declared the same jsonl_fpath repeatedly:
   every declaration after the first picked the same name and overwrote
   its predecessor. Candidates are now tried until unused - bare stem,
   instance-qualified, instance+dataset-qualified, then numbered - so
   the existing names stay byte-identical and repeats within an instance
   get distinct files. Tests cover 3x same path in one instance and 4x
   with identical dataset names.

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 5f75693

# for /verify (_rs_for_row: task_source authoritative, agent_ref via config edges as the
# fallback). Routing aggregation independently by the agent's configured server allowed a
# remapped row to be verified by one server and aggregated by another.
agent_results: Dict[Tuple[str, str], List[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.

The rows are now split by (agent_name, rs_name), but _fetch_agent_metrics() returns only agent_ref, and the export loop still keys metrics as {agent_name}/{metric}.

If one runtime agent handles tasks from two resources servers, both groups produce the same keys. The second dict.update() overwrites the first, and the JSON entries cannot identify which verifier produced either result.

this topology isn't explicitly disallowed, so we should support this edge case by carrying the rs_name into agent_entry and including it in the exported results

if ts is not None:
block = global_config_dict.get(ts)
if isinstance(block, (dict, DictConfig)) and "resources_servers" in block:
return str(ts)

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.

_guard_reverify_mode() still checks only the servers reached through the agent-to-resources-server mapping.

For example, a row can carry task_source=rs_x and be routed through an agent whose configured edge points to rs_y; verification calls rs_x, while preflight checks only rs_y. An unsupported rs_x can then run without --force or the unsafe_ output prefix.

Please derive the preflight server set from the actual rows with this same resolver. we should test where the task source and the selected agent's configured server disagree

This branch was previously deployed

1 inactive deployment
public — 5f75693c Deployed Aug 26, 2026 by copy-pr-bot[bot] via release / finalize / notify #2042
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