Skip to content

fix(data): check collated rows against the server that receives them - #6449

Open
ananthsub wants to merge 1 commit into
ananthsub/env-validate-task-inputfrom
ananthsub/collate-receiver-check
Open

ananthsub wants to merge 1 commit into
ananthsub/env-validate-task-inputfrom
ananthsub/collate-receiver-check

Conversation

@ananthsub

@ananthsub ananthsub commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Stack 5 of 5. #6499 → #6418 → #6447 → #6448 → this PR. Needs #6499 (shared routing), #6418 (the run request report) and #6447 (task input modules).

Before and after

Before (with #6418): collate checks flat rows only against BaseRunRequest, and reports the failures, but does not check task rows at all or the model of the server a flat row goes to. Rows bound for an environment server pass collate and fail at dispatch.

flowchart LR
    B1["Row in the dataset"] --> B2{"Kind of row"}
    B2 -->|"flat row"| B3["Checked only as BaseRunRequest and reported (#6418)"]
    B2 -->|"task row"| B4["Not checked"]
    B3 --> B5["Collation passes the row when it is a valid run request"]
    B4 --> B5
    B5 --> B6["At rollout, the server rejects the row with HTTP 422"]
    classDef bad fill:#fde2e1,stroke:#c0392b,color:#000
    class B4,B6 bad
Loading

After: collate routes each row to the server that receives it, the way rollout collection does, and checks it against that server's request model before any metrics file is written.

flowchart LR
    A1["Row in the dataset"] --> A2["Routed the way rollout collection routes it"]
    A2 --> A3{"Request model of the server that receives it"}
    A3 -->|"rejected"| A4["Reported per file, error mode fails collation before any metrics file is written"]
    A3 -->|"accepted"| A5["At rollout, the server accepts the row"]
    classDef good fill:#dff5e3,stroke:#1e8449,color:#000
    class A2,A3,A4 good
Loading

What happens to concrete rows with #6418 alone and with this PR. The real collate runs under Validation show each case.

Row Receiving server With #6418 alone With this PR
Taskset row whose tools use Chat Completions format single_agent_turn Not checked, HTTP 422 at rollout Rejected at task_input.responses_create_params.tools.0
swe_together row with a bad image_digest or an extra task_input key swe_together Not checked Rejected with the field that fails
Flat row with agent_context: {"user": ...} single_agent_turn_legacy Passes the BaseRunRequest check Rejected with the server's own message
Task row whose taskset has no route none Not checked Rejected: rollout collection refuses it
Valid rows, in every in-repo config any Collated Collated, with identical metrics files

What changed and why

Collate finds each row's receiver with the routing functions from #6499, and loads the receiver's task input module from #6447. The decision for each row:

flowchart TD
    R["Row, after the prompt template, and as a task row when its dataset has a taskset"] --> T{"Task row?"}
    T -->|"yes"| RT{"environment_server_routes entry for its taskset?"}
    RT -->|"no"| X1["Rejected: rollout collection refuses it"]
    RT -->|"yes"| M{"Routed server's task_input.py"}
    M -->|"TaskInput type"| V1["Validate as MaterializedTask[TaskInput]"]
    M -->|"TaskInput = None, a relay"| X2["Rejected: a relay takes no task rows"]
    M -->|"no module"| N1["Counted as not checked"]
    T -->|"no, a flat row"| FM{"environment_routing_mode"}
    FM -->|"taskset"| X3["Rejected: flat rows are refused"]
    FM -->|"legacy, environment_server_name"| ES["Receiving environment server"]
    FM -->|"agent"| AGS{"Agents, as rollout collection picks them: fan_out, else agent_map, else the source's pins and references"}
    AGS -->|"pins that disagree"| X6["Rejected: rollout collection refuses the source"]
    AGS -->|"no single agent in the config"| RR["Validate as BaseRunRequest, counted"]
    AGS -->|"for each agent"| AG{"Environment servers that front the agent"}
    AG -->|"exactly one"| ES
    AG -->|"several"| X4["Rejected: the route is ambiguous"]
    ES --> FS{"Server's task_input.py"}
    FS -->|"sets ACCEPTS_FLAT_ROWS"| V2["Validate as BaseRunRequest, materialize, then validate as TaskInput"]
    FS -->|"typed, without the flag"| X5["Rejected: takes only task rows"]
    FS -->|"relay, or no module"| V3["Validate as BaseRunRequest; without responses_create_params, counted as not checked"]
Loading

A server without task_input.py, such as a third-party server under a search root, is not checked for task rows, the default task_data.py uses, and its flat rows are checked as run requests, which every server that takes flat rows requires. Rows of a dataset without a single agent in the config, such as a resources server whose agent comes from another config at run time, are also checked as run requests.

A flat row goes to every agent that fan_out lists for its task_source, else to the agent_map entry or agent_name, else to the agent task_source_agent resolves. task_source_agent moves out of rollout collection's source resolution into global_config, so rollout collection and collate share it: it applies every agent: pin of the declaring instance, because a collated row does not say which dataset it came from, and pins that disagree are refused. A flat row without responses_create_params that goes to an agent or a relay is counted as not checked, because some agents fill the request in and others refuse the row; it stays out of the metrics.

The check replaces #6418's call site in the metrics pass, so there is still one request check, before any metrics sidecar is written:

flowchart TD
    S["Source row"] --> P["Prepare: prompt template, drop agent_ref, task row for a taskset"]
    P --> C{"Request check against the receiver's model"}
    C -->|"accepted"| MET["Metrics, computed from the source row"]
    C -->|"rejected"| REP["Report: receivers, count, first five reasons"]
    REP --> MODE{"task_data_validation"}
    MODE -->|"error"| RAISE["Raise once after every dataset is read, write no sidecar"]
    MODE -->|"warn"| PRINT["Print the report, leave the row out of metrics"]
    MODE -->|"off"| SILENT["No report, leave the row out of metrics"]
    MET --> SIDE["Metrics sidecar"]
    PRINT --> SIDE
    SILENT --> SIDE
    SIDE --> LOOP["Collate loop: same prepare helpers, task_data.py check, write the prepared rows"]
Loading
  • The check applies the prompt template and turns a taskset's flat row into a task row with the same helpers the collate loop uses to write the row, so the row checked is the row dispatched.
  • Metrics still come from the source rows, so existing metrics sidecars stay valid. A rejected row is left out of the metrics.
  • Each file's report names the servers that receive its rows, counts rejected rows with the first five reasons, and counts rows that could not be fully checked, with the reason. Receiver names and reasons are fixed per configured server or dataset, so the report stays bounded however many rows or tasksets a file holds.
  • environment_server_routes is read once per dataset, and receivers are cached by routed instance name, never by a row's taskset.
  • _schema_home_for picks the routed environment server when several name one agent, so the task_data.py check and the request check use the same server.
  • The environment server authoring page documents task_input.py, and the prepare-and-validate page describes how collate finds each row's receiver.

Issue

None filed. Follows #6418: tracing where collated rows go showed the three gaps in the table.

Validation

pytest -n 16 tests/unit_tests/data tests/unit_tests/environment
pre-commit run --files <changed files>

New tests cover:

  • Task rows: Chat Completions tools rejected by single_agent_turn, swe_together rows with an extra key or a bad digest, a task row routed by its own taskset in an entry without one, a task row with no route, a task row routed to a relay, a server without a task input module, and a prompt-templated taskset row without a source request.
  • Flat rows: a bad agent_context routed to single_agent_turn_legacy, a typed server that takes only task rows, a relay that checks run requests, an agent fronted by two environment servers, taskset routing mode, legacy mode without environment_server_name and an unknown mode, both refused as configs rollout collection rejects, a resources server with no agent in the config, controls such as _ng_skip_token_capture checked before materialization, and a row without responses_create_params.
  • Flat-row routing: an agent_map reroute, its _default and the agent_name shorthand, a fan_out to two agents with each destination checked, a pin on one dataset routing every flat row of its source, and conflicting pins.
  • Wiring: a collation through TrainDataProcessor.run() in example_validation mode fails on rows the routed single_agent_turn server refuses, so the run config reaches the check.
  • Reports and modes: receivers named, reasons capped at five, one receiver entry for many unrouted tasksets, the headline when nothing failed, warn and off, and a task input module that fails to load in each mode.
  • Cost and metrics: routes are read once per dataset, and a valid flat taskset row and a prompt-templated row produce the same metrics as collate without the check.

Each new behavior test fails with #6418 through #6448 alone. The metrics and prompt-template tests guard behavior that must stay the same.

Real collate runs, locally on a workstation, comparing #6418's check alone with this PR:

  • Taskset rows: resources_servers/agentic_if/configs/agentic_if.yaml over 10 rows, 5 with Chat Completions tools, in error mode. fix(data): report rows that fail request validation during collate #6418 alone collates all 10. This PR fails with 5/10 rows rejected at task_input.responses_create_params.tools.0 by agentic_if_environment_server (single_agent_turn).
  • swe_together: benchmarks/swe_together/opencode.yaml over the rows of environment_servers/swe_together/data/example.jsonl. The committed rows pass on both. A copy with a bad image_digest and an extra task_input key passes with fix(data): report rows that fail request validation during collate #6418 alone, and this PR rejects both rows.
  • single_agent_turn_legacy: resources_servers/example_single_tool_call/configs/example_single_tool_call.yaml with one row's agent_context keyed by user. fix(data): report rows that fail request validation during collate #6418 alone passes it, and this PR rejects it with the server's message.
  • Regression check: example_validation collate over every in-repo config that declares a dataset, on main and on the full stack. Each config has the same outcome, configs that fail on both fail with the same error, and every metrics file the two runs wrote is identical. Configs that fail on both fail before validation, on unset environment variables, metrics files that already differ from the committed ones, or the workstation's host name resolving to 127.0.1.1.
  • Cost: 20,000 task rows with 500 routes collate in 0.6 s.

Rollout evidence

N/A. Collate only: what rollout collection dispatches, and how servers validate it, is unchanged.

Compatibility

  • Rows that a server would refuse at dispatch now fail collate in error mode, which example_validation uses. In train_preparation mode, which defaults to warn and is the mode NeMo RL uses, they are printed and left out of the metrics, but still collated.
  • Metrics of accepted rows are unchanged, so existing sidecars stay valid.
  • An environment server outside this repository without task_input.py keeps working, and collate does not check its task rows.

@ananthsub ananthsub added bug Something isn't working area:data Datasets, preparation, task formats, and materialization area:docs Generic documentation without another dominant domain labels Nov 19, 2026
@copy-pr-bot

copy-pr-bot Bot commented Nov 19, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

@svcnvidia-nemo-ci svcnvidia-nemo-ci 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.

SHIP WITH CARE

I found three RISK-level validation defects in the inline comments. The request check can select a different receiver from rollout collection, and the flat-row adapter can accept malformed controls that it previously rejected.

I inspected all 21 changed files and traced the affected preparation, routing and request-model paths. This was a static review; I did not execute tests.

Review generated by codex. This was a full review. Request a full review with /review reset=true.

Comment thread nemo_gym/data/dataset_preparation.py Outdated
if instance_name is not None:
return self._environment_server_receiver(instance_name, task_data_validation=task_data_validation)
try:
agent = resolve_dataset_agent(

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.

RISK: Apply explicit agent rerouting before selecting the receiver.

With a valid flat dataset declared by agent A, a task-only single_agent_turn server fronting A, a legacy_agent relay fronting B, and agent_map={A: B}, this lookup selects A's server and rejects the row. Rollout preprocessing instead applies the map and sends it through B's relay. These settings reach preparation through the evaluation entry point, so this also affects real runs, not only direct helper calls.

Could you resolve the effective flat-row destinations before calling environment_server_for_agent? Use the prepared routing basis, task_source=c.name, because collation strips agent_ref. Match rollout's source-specific map/default precedence, its agent_name normalization, and its fan_out destinations. Validate against every destination that receives a copy. The current single-_Receiver interface needs an adjustment, so I am not proposing an exact patch.

Keep task rows routed exclusively by environment_server_routes, keep explicit environment_routing_mode=legacy routing, and retain the existing ambiguity and unknown-receiver behavior when no override applies.

Proposed acceptance checks, not executed: the A-to-B example must pass error-mode collation and report B's relay. For a resources-server dataset shared by A and B, map its source to B fronted by single_agent_turn_legacy; a row with agent_context={"user":{"values":{}}} must fail B's model. Fan-out to a relay and that adapter must reject the same bad context but accept a valid row. A materialized task must keep its taskset receiver despite those overrides.

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.

Fixed in 7e1c31c.
Collate now resolves a flat row's agents the way rollout collection does, from the row's task_source (collation strips agent_ref): every agent fan_out lists for it, else agent_map[task_source] or agent_map._default, else the source's own agent.
The row is checked against the server that fronts each of those agents, and every one must accept it.
Task rows still route only by environment_server_routes, and environment_routing_mode=legacy is unchanged.
Tests cover the A-to-B reroute to a relay, _default, and a fan-out to a relay and single_agent_turn_legacy that rejects the bad agent_context.

Comment thread nemo_gym/data/dataset_preparation.py Outdated
return self._environment_server_receiver(instance_name, task_data_validation=task_data_validation)
try:
agent = resolve_dataset_agent(
config, c.name, pin=d.agent if isinstance(d, BenchmarkDatasetConfig) else None

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.

RISK: Resolve the source-wide dataset pin used at dispatch.

This uses only d.agent, but flat collated rows identify their declaring instance, not their individual dataset. Dispatch collects pins from all declarations on that instance.

For example, let two agents reference shared_rs, let one benchmark entry on shared_rs pin B, and leave another flat entry unpinned. Dispatch resolves both entries to B. This check instead treats the unpinned entry's receiver as unknown and falls back to BaseRunRequest. If B is fronted by single_agent_turn_legacy, a row with valid responses_create_params and agent_context={"user":{"values":{}}} passes collation but receives HTTP 422 from B's adapter. Conflicting pins are also checked independently here even though dispatch refuses their shared source.

After explicit rerouting is applied, could you use dataset_agent_pins and dispatch's conflict rule against the full run configuration? A unique pin must select the receiver for every unresolved flat row with that source; conflicting pins must produce a routing refusal. Keep the partial-check fallback for a genuinely unresolved resources-only config. The helper extraction is an implementation choice, so no exact patch is proposed.

Proposed acceptance checks, not executed: with the pinned/unpinned setup above, reject the unpinned entry's bad context using B's server constraint. With two different pins, report the source-level conflict. Preserve taskset routing independently of flat-row pins, the existing resources-only malformed-tool rejection, and test_pin_survives_discovery_collate_and_rollout, including its task_source, absent agent_ref, and resolved agent_b assertions.

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.

Fixed in 7e1c31c.
Rollout collection's source resolution moved into task_source_agent in global_config, which both rollout collection and collate call.
It applies every agent: pin of the declaring instance, and raises ConflictingAgentPinsError when they disagree.
Collate reports that conflict as a routing refusal, and keeps the run-request-only fallback when no agent is found.
Tests cover the pinned and unpinned entries on a shared resources server (the unpinned entry's bad context is rejected by agent B's single_agent_turn_legacy) and conflicting pins.
The existing pin round-trip test through discovery, collation and rollout still passes.

BaseRunRequest.model_validate(row)
elif contract.accepts_flat_rows:
# The server materializes a flat row by its task_source, as single_agent_turn_legacy's /run does.
contract.task.validate_python(materialize_task(row, taskset=task_source, task_index=0))

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.

RISK: Validate flat-row controls before materialization removes them.

A flat row routed to single_agent_turn_legacy, with no dataset taskset, now passes the request check with {"responses_create_params":{"input":"q"},"_ng_skip_token_capture":"yes"}. The metrics pass now suppresses the source BaseRunRequest rejection when a request check exists, and materialize_task removes _ng_* fields before this adapter validates them. At runtime, the flat adapter reads and validates that control separately, so it returns HTTP 422. Invalid _ng_model_sampling values escape the same way. Before this change, flat rows were rejected by BaseRunRequest during metrics validation.

Could you validate the flat run-request envelope before converting it? The smallest correction at this line is:

Suggested change
contract.task.validate_python(materialize_task(row, taskset=task_source, task_index=0))
BaseRunRequest.model_validate(row)
contract.task.validate_python(materialize_task(row, taskset=task_source, task_index=0))

This keeps the adapter's additional TaskInput validation while retaining the controls declared by BaseRunRequest. Keep this check in the flat-row branch; task-only custom inputs need not contain responses_create_params.

Proposed acceptance checks, not executed: error-mode collation must reject the string capture flag and _ng_model_sampling={"top_p":0}. Valid requests with capture values true, false, null, or absent must pass, as must valid sampling values. Retain rejection of the wrong agent_context role, acceptance of both flat and canonical task_data shapes, and acceptance of custom task rows without a Responses API request. Please verify the suggested insertion before adopting it.

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.

Fixed in 7e1c31c as suggested: a flat row for a server that takes flat rows is validated as a BaseRunRequest before it is materialized and checked against TaskInput. A parametrized test rejects _ng_skip_token_capture: "yes" and accepts true, false, null and an absent value.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the needs-review PR is ready for code review and waiting on a reviewer label Nov 19, 2026
@yaoyu-33
yaoyu-33 requested a review from agronskiy November 19, 2026 07:08
@ananthsub
ananthsub force-pushed the ananthsub/env-validate-task-input branch from ac754d4 to c49fdee Compare November 19, 2026 18:23
@ananthsub
ananthsub force-pushed the ananthsub/collate-receiver-check branch from afa0e1f to 7e1c31c Compare November 19, 2026 18:23
@nemo-automation-bot
nemo-automation-bot Bot requested review from a team November 19, 2026 18:24
@ananthsub
ananthsub force-pushed the ananthsub/collate-receiver-check branch from 7e1c31c to 1ad4e42 Compare November 19, 2026 18:39
@ananthsub
ananthsub force-pushed the ananthsub/env-validate-task-input branch from c49fdee to d76011e Compare November 19, 2026 19:17
@ananthsub
ananthsub force-pushed the ananthsub/collate-receiver-check branch from 1ad4e42 to 4bc9d79 Compare November 19, 2026 19:17
@ananthsub
ananthsub force-pushed the ananthsub/collate-receiver-check branch from 4bc9d79 to f65387e Compare November 19, 2026 22:34
@ananthsub
ananthsub force-pushed the ananthsub/env-validate-task-input branch from d76011e to 9e05799 Compare November 19, 2026 22:34
Collate checked flat rows only as run requests and never checked task
rows, so taskset rows with Chat Completions tools, swe_together rows
and flat rows sent to single_agent_turn_legacy passed collate and
failed at dispatch.

Collate now finds each row's receiver with the routing helpers rollout
collection uses, and checks the row against that server's task input
module, in the shape the server receives it: after the prompt template,
and after a taskset's flat row becomes a task row. Collation writes the
same shape through the same helpers. A server without the module is
not checked for task rows, and its flat rows are checked as run
requests, as are rows of a dataset without a single agent.

Each report names the receivers, counts rejected rows with the first
five reasons, and counts rows that could not be fully checked, with
fixed names and reasons so it stays bounded. Routes are read once per
dataset. Metrics still come from the source rows, so existing sidecars
stay valid. The environment server authoring page documents
task_input.py.

Signed-off-by: Ananth Subramaniam <[email protected]>
@ananthsub
ananthsub force-pushed the ananthsub/env-validate-task-input branch from 9e05799 to 3e8049f Compare November 19, 2026 22:51
@ananthsub
ananthsub force-pushed the ananthsub/collate-receiver-check branch from f65387e to 33a3761 Compare November 19, 2026 22:51
@github-actions github-actions Bot added the sla:review-overdue Review response is over the one-business-day SLA label Nov 20, 2026
ffrujeri added a commit that referenced this pull request Nov 20, 2026
Environment Servers ship `task_input.py`, exporting the `TaskInput` their episode request validates, so data tooling
can check rows against it without the server's dependencies (#6447 → #6449, which also requires every
Environment Server to ship one). Such a module may import only the standard library, pydantic and resources servers'
`task_data` modules, so the task models move from `task_data.py` into it; `task_data.py` keeps its `TaskData` export
for the task-data tooling, and the server, the simulator and the recipe import from `task_input.py`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Felipe Vieira Frujeri <[email protected]>
ffrujeri added a commit that referenced this pull request Nov 21, 2026
Environment Servers ship `task_input.py`, exporting the `TaskInput` their episode request validates, so data tooling
can check rows against it without the server's dependencies (#6447 → #6449, which also requires every
Environment Server to ship one). Such a module may import only the standard library, pydantic and resources servers'
`task_data` modules, so the task models move from `task_data.py` into it; `task_data.py` keeps its `TaskData` export
for the task-data tooling, and the server, the simulator and the recipe import from `task_input.py`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Felipe Vieira Frujeri <[email protected]>
ffrujeri added a commit that referenced this pull request Nov 21, 2026
Environment Servers ship `task_input.py`, exporting the `TaskInput` their episode request validates, so data tooling
can check rows against it without the server's dependencies (#6447 → #6449, which also requires every
Environment Server to ship one). Such a module may import only the standard library, pydantic and resources servers'
`task_data` modules, so the task models move from `task_data.py` into it; `task_data.py` keeps its `TaskData` export
for the task-data tooling, and the server, the simulator and the recipe import from `task_input.py`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Felipe Vieira Frujeri <[email protected]>
ffrujeri added a commit that referenced this pull request Nov 23, 2026
Environment Servers ship `task_input.py`, exporting the `TaskInput` their episode request validates, so data tooling
can check rows against it without the server's dependencies (#6447 → #6449, which also requires every
Environment Server to ship one). Such a module may import only the standard library, pydantic and resources servers'
`task_data` modules, so the task models move from `task_data.py` into it; `task_data.py` keeps its `TaskData` export
for the task-data tooling, and the server, the simulator and the recipe import from `task_input.py`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Felipe Vieira Frujeri <[email protected]>
ffrujeri added a commit that referenced this pull request Nov 23, 2026
Environment Servers ship `task_input.py`, exporting the `TaskInput` their episode request validates, so data tooling
can check rows against it without the server's dependencies (#6447 → #6449, which also requires every
Environment Server to ship one). Such a module may import only the standard library, pydantic and resources servers'
`task_data` modules, so the task models move from `task_data.py` into it; `task_data.py` keeps its `TaskData` export
for the task-data tooling, and the server, the simulator and the recipe import from `task_input.py`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Felipe Vieira Frujeri <[email protected]>
zhiqi-li pushed a commit to zhiqi-li/Gym that referenced this pull request Nov 23, 2026
…test cases (NVIDIA-NeMo#5534)

* feat(bird_interact): grade BIRD-Interact's management tasks by their test cases

The bird_interact Environment Server refused the management tasks at seed
(105 of Lite's 300, 190 of Full's 600), and the recipe left them out. The
benchmark is the whole task set, so they now run, in both modes
(GYMINT-681).

grading.py grades a management phase as the BIRD-Interact ADK does, in an
independent implementation: on a copy of the episode's database, the
submission runs and its writes stay, then each test case runs with the
ADK's six globals (execute_queries, ex_base, the three rewrites,
pred_query_result), in order, until one raises. The copy is dropped, so a
failed submission leaves the database as it was; a passing phase 1 is
applied for phase 2, as before. Test cases run in the episode's sandbox,
never on the Gym host, on PostgreSQL only (GYMINT-683, GYMINT-684).

The server sends a management phase's test cases with its grade request
and gives the command time for them. prepare.py keeps every task with its
ground truth. The real-PostgreSQL test fixture failed to start with
psycopg2 2.9 (`with connection:` opens a transaction even in autocommit);
it is fixed, because the new tests need it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Felipe Vieira Frujeri <[email protected]>

* fix(bird_interact): isolate agent SQL on PostgreSQL and attribute grading failures correctly

From the review of the BIRD-Interact stack:

- PostgreSQL: agent SQL runs only on copies of the episode's database, as the
  ADK resets its task database before each submission: exploratory queries on
  a working copy, each submission on a fresh copy. A COMMIT in agent SQL no
  longer changes later grades or phase 2.
- PostgreSQL: one deadline for a whole query, enforced by cancelling it, so a
  script of many statements, or one with a COMMIT, cannot outlast it.
- SQLite: agent SQL cannot ATTACH the episode's own file.
- A solution that fails after the submission runs again on the episode's
  database: a submission that broke its state is wrong, as in the ADK, and
  only a solution that fails there too is bad task data.
- A passing phase 1 that cannot be applied fails the command (default test
  case) or the phase (test cases), instead of passing without its changes.
- A numeric too large to round is a failed comparison, as in the ADK, not a
  crash of the runner.
- A sandbox command has time for every script the grader may run.
- A tool call cut off by its deadline masks the sample, in both modes.
- The SQLite wording changes the ADK's texts only, not the task they hold.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Felipe Vieira Frujeri <[email protected]>

* fix(bird_interact): grade a submission against a broken solution as the ADK does

When a task's solution SQL fails even on the episode's own database, the
server failed the whole episode, and the rollout lost the reward of the
phases already passed. The ADK's ex_base returns 0 for such a solution:
the submission is wrong, the agent gets its debug turn, and earlier phases
keep their reward. The server now does the same, and lists each such
error in the rollout's solution_errors.

The benchmark README lists the 24 Lite tasks whose solution SQL fails at
grading (the ADK's DISTINCT removal, invalid SQL, and phase 2 solutions
that need what phase 1's solution creates), and how to run Claude Haiku
5.5 as the simulator.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Felipe Vieira Frujeri <[email protected]>

* fix(bird_interact): show a-Interact agents only the knowledge fields the ADK shows

get_all_knowledge_definitions and get_knowledge_definition returned each
knowledge-base entry whole, with its type and its children's ids, which the
ADK's /knowledge endpoint leaves out (KNOWLEDGE_VISIBLE_FIELDS). They now show
the entry's id, name, description and definition, as a JSON array or object
as the ADK writes it, as the c-Interact instruction already did.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Felipe Vieira Frujeri <[email protected]>

* fix(bird_interact): run agent SQL as a role that is not a superuser, and close the review's grading gaps

From the team review of the stack:

- Agent SQL ran as PostgreSQL's superuser, which could turn on statement
  logging, read the server's log or files, or run programs, and so read the
  solution SQL that grading runs. The image now has bird_agent
  (BIRD_INTERACT_AGENT_ROLE), not a superuser, which owns each template's
  objects (agent_role.sql). grading.py runs the task's setup, the agent's SQL
  and grading as it; only the copies are made by the superuser. Grading each
  task's own solution as its submission gives the same result as before for
  every Lite and Full task but three management tasks whose solution needs a
  superuser (session_replication_role, CREATE ROLE), which the README lists.
- SQL that breaks the driver (a date past year 9999, a huge interval, a NUL,
  pg_terminate_backend) made the command fail, which masked the sample. It is
  now the query's error, as in the ADK.
- A management phase's queries had only a per-statement timeout: they now have
  one deadline each, as default grading has. Its command budget counts up to
  ten queries per test case, and a passing phase that fails to apply fails
  the command, as default grading's does.
- A solution run again alone after the submission broke it ran on the
  episode's database, where a COMMIT in it stayed: it runs on a copy.
- SQLite reads only the last statement's rows, at most the ADK's 10,000, and
  a preview cuts each value at 100 characters, as the ADK does.
- A sandbox replacement no longer holds a server-wide query slot.
- start_postgres says why the server did not start. The real-PostgreSQL
  fixture always stops its server. The example config sets no image, so an
  unset PostgreSQL image is refused at startup.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Felipe Vieira Frujeri <[email protected]>

* docs(bird_interact): say that management phases are graded by their test cases in the environment list

NVIDIA-NeMo#5475's row says the recipe grades query tasks by result comparison; this PR
also grades management phases, by their test cases.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Felipe Vieira Frujeri <[email protected]>

* test(bird_interact): cover the setup failure, the SQLite image fallback and a-Interact's PostgreSQL instructions

Each of these passed with the behavior reverted: a task setup that fails now fails the runner command, an episode
with no configured image starts the SQLite image, and a-Interact's instructions name PostgreSQL on PostgreSQL.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Felipe Vieira Frujeri <[email protected]>

* fix(bird_interact): end the turn at a submission that cannot be graded; report a capped result's count

- A `submit_sql` that an infrastructure failure keeps from being graded returns an error that ends the activation,
  as a graded submission does, so the policy is not called again. The sample is masked, as before.
- `execute` reports a result over the 10,000-row cap as `10000+ rows`, a lower bound, from a `truncated` flag on the
  runner's result.
- Tests for rules that had none: a failing submission is not applied; phase 2 sees phase 1's changes on the same
  sandbox; comments are removed before the ROUND rewrite; a submission over the SQL timeout gets the ADK's timeout
  message; the row cap's count. Each fails with its rule removed.
- The README drops an internal tracker key.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Felipe Vieira Frujeri <[email protected]>

* feat(bird_interact): ship the episode's task input as task_input.py

Environment Servers ship `task_input.py`, exporting the `TaskInput` their episode request validates, so data tooling
can check rows against it without the server's dependencies (NVIDIA-NeMo#6447 → NVIDIA-NeMo#6449, which also requires every
Environment Server to ship one). Such a module may import only the standard library, pydantic and resources servers'
`task_data` modules, so the task models move from `task_data.py` into it; `task_data.py` keeps its `TaskData` export
for the task-data tooling, and the server, the simulator and the recipe import from `task_input.py`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Felipe Vieira Frujeri <[email protected]>

* test(bird_interact): SQL with a NUL or a lone surrogate is the query's error, not a runner crash

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Felipe Vieira Frujeri <[email protected]>

* refactor(bird_interact): keep task_input.py to the row schema

ambiguity_count, needs_custom_test_cases and custom_test_cases decide the episode's budget and grading, and only
app.py uses them, so they move there. task_input.py keeps the models that rows validate against.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Felipe Vieira Frujeri <[email protected]>

* fix(bird_interact): close the shared-state channels to the solution SQL, and apply the review's other fixes

From the review of the management tasks:

- Agent SQL could read the solution SQL, or break later grades, through state that every copy of the episode's
  database shares: a database's comment and settings, which the agent role could change as the owner of
  <db>_template and of each copy, and the role's own settings (ALTER ROLE ... SET). The superuser now owns the
  databases and grants the role CREATE and TEMPORARY on them, and resets the role's settings before it makes each copy
  and before it writes the episode's database. A connection that a test case opens itself is the agent role's.
- A command cut off by the tool call's deadline or the interaction deadline is no longer a sandbox failure: the call
  fails, and a submission cut off so is a failed attempt. Only a SandboxCommandError gets the not-graded reply.
- The rollout keeps a failing test case's exception (test_case_errors), which the agent does not see.
- c-Interact, which has no execute tool, makes no working copy.
- The aggregate metrics count the samples with a solution error, and mask_solution_errors masks them.
- A long preview value is cut from its text, not its repr. "The solution SQL failed". Renames: fresh_copy,
  episode_database, _command_query_budget. README: ten queries for each test case, and two more ADK differences.
- Tests: the re-run of a broken solution is reached (DROP TABLE IF EXISTS); a test case's own connection sees the
  submission's writes; a management submission can create a schema in its copy.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Felipe Vieira Frujeri <[email protected]>

* docs(bird_interact): name task_input.py as the row schema in the config and schemas.py

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Felipe Vieira Frujeri <[email protected]>

---------

Signed-off-by: Felipe Vieira Frujeri <[email protected]>
Co-authored-by: Claude Opus 5.5 <[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:data Datasets, preparation, task formats, and materialization area:docs Generic documentation without another dominant domain bug Something isn't working needs-review PR is ready for code review and waiting on a reviewer risk:high Autobot PR risk: high sla:review-overdue Review response is over the one-business-day SLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants