Skip to content

fix(data): collate validates task_data from any cwd; a data-only dir no longer shadows the server dir - #5325

Merged
athitten merged 7 commits into
mainfrom
qiaochuz/nvb-6900465-collate-schema-dir-shadow
Nov 19, 2026
Merged

athitten merged 7 commits into
mainfrom
qiaochuz/nvb-6900465-collate-schema-dir-shadow

Conversation

@qiaochuz-nv

@qiaochuz-nv qiaochuz-nv commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

gym dataset collate --mode example_validation now rejects a row that violates the owning server's task_data.py schema from any cwd. Before, running collate from a cwd outside the checkout (a project directory, the QA runner's scratch workspace) collated the row and exited 0 without a word, because the schema lookup resolved to the data-only directory collate had just created for its own sidecars.

Fixes NVBug 6900465.

Cause

_collate_samples_single_type writes <stem>_prepare.jsonl next to the cwd-relative jsonl_fpath and creates that directory (<cwd>/resources_servers/<server>/data/) right before it looks the schema up. find_server_dir (nemo_gym/task_data.py) resolved resources_servers/<server> with validator=Path.is_dir, and the component search roots put the cwd before the install root, so the freshly created output directory won, load_task_data_schema found no task_data.py in it and returned None, and _task_data_validator_for skipped validation silently. The same lookup serves _dataset_metrics_hook_for. Both the resolver and the mkdir-before-lookup order date from #2795, which introduced collate validation.

Update (2026-11-18): since #5997 (4e3f503549, merged 2026-11-17) collate writes the prepared file and the metrics sidecar into the run's output directory, so it no longer creates that directory itself. The shadow still happens wherever such a directory exists: left behind by an earlier collate run (the ls below shows one), or a dataset kept under resources_servers/<server>/data/ in the project directory. The resolver fix and the warning are unchanged; the two external-cwd tests now pass output_dir, which #5997 made a required argument, and the docstrings describe the mechanism as it stands.

The NVBug's other defect (the owning resources server of an agent-declared dataset was looked up in the in-scope-filtered instance list) was fixed on main by #3674 (_schema_lookup_configs); the matrix below confirms it, so this PR does not touch it.

Fix

  • find_server_dir accepts a candidate only when it holds a server source marker: requirements.txt or pyproject.toml (the rule nemo_gym/cli/env.py::_resolve_server_dir already applies), or the module being looked up (task_data.py, dataset_metrics.py) so a plugin server that ships only a schema still resolves. Every built-in resources_servers/, responses_api_agents/ and environment_servers/ directory carries at least one marker, so built-in lookups are unchanged; a directory holding only Gym's output can no longer shadow them.

  • _task_data_validator_for and _dataset_metrics_hook_for warn when a schema home resolves to no server directory at all (previously a silent None), so the gate cannot switch off without a trace again. The shared hint names the implementation the instance resolves to and the search-root remedy (a dangling resources_server reference never reaches this warning). Servers without a task_data.py are still skipped silently, as documented.

  • Docs (225a46c84): fern/versions/latest/pages/data/prepare-validate.mdx said collate "adds the agent_ref field to each row"; since feat(data): collate stamps task_source; datasets declarable on resources servers #2717 collate stamps task_source and strips a deprecated agent_ref, so the sentence now says that and mentions the task_data.py check; step 5 of the "steps" list says the same. Found while checking this PR against the page.

  • Review follow-up (15dde46a3, @yaoyu-33): the warning hint named the resources_server reference as the thing to check, which cannot be the cause when the warning fires; it now names the implementation (one helper for both warnings). The docs no longer promise a warning for a stripped agent_ref (it is a DeprecationWarning, hidden by Python's default filters). Tests pin every entry of SERVER_DIR_MARKERS by name (a cwd directory holding only that file resolves; a marker that is a directory does not) and the documented silent skip of a found server without task_data.py; removing any one marker from the tuple now fails at least one test.

Rejected alternatives: validating only on the looked-up module (task_data.py) would make a server that ships a schema but, by mistake, under another name indistinguishable from a shadow; resolving write targets differently was out of scope here (_resolve_under_cwd_or_install is documented as read-only); #5997 has since moved the prepared file and the metrics sidecar into the run's output directory.

Before the fix

Gym f70bf75c3 (main). The mcqa example dataset with grading_mode: "strict_single_leter_boxed" (typo) on row 0 and its example_metrics.json removed; from an empty directory outside the checkout:

cd "$(mktemp -d)"   # env.yaml with placeholder policy_* keys
gym dataset collate --resources-server mcqa --model-type openai_model --mode example_validation --output-dir ./collated; echo "exit=$?"
View your final data!
- example: .../collated/example.jsonl

####################################################################################################
#
# Finished!
#
####################################################################################################
exit=0
$ ls resources_servers/mcqa      # the directory collate created and then mistook for the server
data

The typo row is in collated/example.jsonl. Same result for an undeclared bogus_task_field on every row of example_single_tool_call (agent-declared) and for a missing required expected_count in example_session_state_mgmt (resources-server-declared, --config .../example_session_state_mgmt_nooa.yaml). From the checkout root all three fail correctly, which is the #3674 state.

After the fix

Gym 61e01f8bf (this branch; the log below was captured at its pre-rebase form 6a0a5f286 on main 5911d628c, the logic is unchanged since), same command from the same external directory:

  File ".../nemo_gym/train_data_utils.py", line 1325, in _collate_samples_single_type
    raise ValueError(summary)
ValueError: resources_servers/mcqa/data/example.jsonl: 1/5 rows failed task_data validation against the `mcqa` schema.
  row 0: 1 validation error for TaskData; grading_mode;   Input should be 'strict_single_letter_boxed', 'lenient_boxed' or 'lenient_answer_colon' [type=literal_error, input_value='strict_single_leter_boxed', input_type=str]
exit=1
ValueError: resources_servers/example_single_tool_call/data/example.jsonl: 0/5 rows failed task_data validation against the `example_single_tool_call` schema.
  keys not declared by the schema (typo, or missing schema field?): bogus_task_field (5 rows)
ValueError: resources_servers/example_session_state_mgmt/data/example_nooa_tasks.jsonl: 1/5 rows failed task_data validation against the `example_session_state_mgmt` schema.

Full matrix (exit codes), four datasets × {checkout root, external cwd}: before 1 0 / 1 0 / 1 0 / 1 0, after 1 1 / 1 1 / 1 1 / 1 1.

Validation

  • QA testcase dataset_collate (local lane, no model): the three existing cases pass before and after; two new negative controls (schema-violating row in an agent-declared and in a resources-server-declared dataset, collated from the scratch workspace cwd) fail on main f70bf75c3 (3/5: both controls report "collate exited 0 on a schema-violating row (validation skipped)") and pass on this branch (5/5). They land in nmfw_tests after the merge.
  • pytest tests/unit_tests/test_task_data.py tests/unit_tests/test_train_data_utils.py tests/unit_tests/test_indic_ifeval.py: 506 passed at 15dde46a3 on main 283147705 (15 new: shadow dir under cwd for a resources server and for an agent, schema-only plugin dir, missing server, unresolvable schema home warns, external-cwd collate rejects a violating row and passes a clean one, each of the four markers alone resolves a cwd server dir, a marker that is a directory does not; one existing test, test_agent_without_rs_reference_and_no_schema_is_skipped, now builds a real marker-bearing server dir instead of an empty directory that shadowed the built-in tau2, and asserts the skip is silent). The repo sweep TestRepoDataMatchesSchemas still passes, so the committed example data stays clean under the restored gate.
  • pre-commit run --all-files: passed.
  • Docs: python tests/unit_tests/test_fern_docs_links.py 29 OK; npm run check in fern/ passed.
  • Rollout evidence: N/A, collate is a file-to-file transform; no server or model is involved.

Compatibility

Collate runs from outside the checkout that used to exit 0 on schema-violating rows now fail in example_validation mode and print the per-file report in train_preparation mode, as the task_data_validation option already documents. A user's own server directory needs one of requirements.txt, pyproject.toml, task_data.py or dataset_metrics.py to be found by the data tooling; every built-in server has one.

🤖 Generated with Claude Code

@qiaochuz-nv qiaochuz-nv added bug Something isn't working QA_fix Fix implemented by a QA team member area:data Datasets, preparation, task formats, and materialization needs-review PR is ready for code review and waiting on a reviewer complexity:low Localized change in one scope with a small, straightforward review surface labels Oct 29, 2026
@copy-pr-bot

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

@qiaochuz-nv
qiaochuz-nv requested a review from yaoyu-33 October 29, 2026 17:53
@qiaochuz-nv

Copy link
Copy Markdown
Contributor Author

/ok to test 70b2ebb

@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

LGTM — no concerns found. Reviewed all five changed files and traced component-search precedence, schema ownership, validation modes, metrics-hook loading, and collation routing. The external-cwd regression cases distinguish rejected invalid rows from accepted valid rows while retaining schema-only plugin support.

Static inspection only; tests were not executed. All three delegated inspections terminated; two returned no report payload, so their resolver and schema/metrics topics were independently inspected by the root reviewer.

Note: formal approval is not available for this request, so this review is posted as a comment only.

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

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

@yaoyu-33 yaoyu-33 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.

Thanks for the careful write-up and the before/after matrix. The fix is correct and minimal. find_server_dir now skips a directory that holds only collate's own output, so from any cwd the lookup lands on the real server directory and the task_data.py gate runs again. The environment_servers schema lookup in _schema_home_for goes through the same resolver, so it gets the fix too.

What we checked on 70b2ebb9e5:

  • Real CLI repro: ran gym dataset collate --resources-server mcqa --mode example_validation from an empty directory outside the checkout, with a misspelled grading_mode on one row. On this head it exits 1 with the schema error. On main it exits 0 and the bad row is collated.
  • Tests: tests/unit_tests/test_task_data.py and test_train_data_utils.py pass at this head (474 passed). Against main's task_data.py and train_data_utils.py, the new shadow, warning, and external-cwd negative tests fail, so they are real regression tests.
  • Built-in servers: every built-in directory under resources_servers/, responses_api_agents/ and environment_servers/ has at least one of the markers, so built-in lookups are unchanged.

The three inline notes are small (warning hint text, one docs sentence, test coverage of the marker list). None of them blocks merging.

Possible follow-up, not for this PR: the <stem>_metrics.json drift check has the same from-any-cwd gap. It reads only the cwd-relative sidecar (train_data_utils.py#L981, #L873). So from an external cwd, the committed example_metrics.json under the install root is never compared, and a fresh sidecar is written instead. Reading the sidecar through _resolve_under_cwd_or_install, while still writing it to the cwd, would close that gap.

Comment thread nemo_gym/train_data_utils.py Resolved
Comment thread tests/unit_tests/test_task_data.py Resolved
@yaoyu-33

Copy link
Copy Markdown
Contributor

This is ready to approve except for one thing: #5189 moved nemo_gym/config_types.py and nemo_gym/global_config.py into nemo_gym/config/, and the branch now conflicts with main in tests/unit_tests/test_train_data_utils.py (the config_types import line this PR extends). Could you merge main and import ResourcesServerInstanceConfig from nemo_gym.config.config_types there? The new from nemo_gym.global_config import GlobalConfigDictParser in test_task_data.py still resolves through the moved-path alias, but nemo_gym.config.global_config is the new home. I'll approve once the branch merges cleanly.

@qiaochuz-nv

Copy link
Copy Markdown
Contributor Author

/ok to test 15dde46

qiaochuz-nv added a commit that referenced this pull request Oct 30, 2026
…erver-dir marker

The "no server directory" warning told users to check the resources_server
reference, which cannot be the cause when it fires: a dangling reference never
reaches it (_schema_home_for returns None first). The validator and the
metrics-hook warnings now share one hint that names the implementation the
instance resolves to and the search-root remedy.

prepare-validate.mdx no longer promises a warning when a deprecated agent_ref
is stripped (it is a DeprecationWarning, hidden by Python's default filters),
and step 5 says rows are stamped with task_source rather than agent references.

Tests: a cwd directory holding only one marker resolves, for each of the four
markers spelled out; a marker that is a directory does not count; a found
server without task_data.py is skipped without any warning.

Found in review of #5325 by yaoyu-33.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: qiaochuz <[email protected]>
@qiaochuz-nv
qiaochuz-nv force-pushed the qiaochuz/nvb-6900465-collate-schema-dir-shadow branch from 70b2ebb to 15dde46 Compare October 30, 2026 15:50
@nemo-automation-bot
nemo-automation-bot Bot requested review from a team October 30, 2026 15:51
@qiaochuz-nv

Copy link
Copy Markdown
Contributor Author

/ok to test ca65432

@qiaochuz-nv

Copy link
Copy Markdown
Contributor Author

Merged main (79f501a, resolving the config_types import conflict in tests/unit_tests/test_train_data_utils.py on the new path) and moved the remaining import this PR added to its new home: ResourcesServerInstanceConfig now comes from nemo_gym.config.config_types, and the external-cwd collate test in test_task_data.py imports GlobalConfigDictParser from nemo_gym.config.global_config (ca65432). No old-path import is left in the files this PR touches; 506 passed locally after the merge, and GitHub now reports the branch as mergeable.

🤖 Addressed by Claude Code

@qiaochuz-nv

Copy link
Copy Markdown
Contributor Author

/ok to test 45c76ab

Conflict in tests/unit_tests/data/test_task_data.py: both sides appended tests
at the end of the file. Kept the PR's TestFindServerDirRejectsOutputOnlyDirs
and TestExternalCwdThroughTheProcessor and main's
test_rl_stream_index_is_not_part_of_task_schema (#6091).

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: qiaochuz <[email protected]>
@qiaochuz-nv

Copy link
Copy Markdown
Contributor Author

/ok to test c02f3fb

yaoyu-33
yaoyu-33 previously approved these changes Nov 18, 2026

@yaoyu-33 yaoyu-33 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.

LGTM. Re-reviewed the latest head; the previous comments are addressed. All 549 task-data and dataset-preparation tests passed, including external-cwd validation.

@yaoyu-33 yaoyu-33 added ready-to-merge PR is approved, current, and waiting for final CI or merge and removed needs-review PR is ready for code review and waiting on a reviewer labels Nov 18, 2026
@athitten
athitten added this pull request to the merge queue Nov 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/44431912731

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 19, 2026
@athitten

Copy link
Copy Markdown
Contributor

/ok to test 2530b86

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the risk:high Autobot PR risk: high label Nov 19, 2026
…be the shadow after #5997

#5997 made output_dir a required keyword of _collate_samples_single_type and
moved the prepared file into the run's output directory, so collate no longer
creates <cwd>/<base_folder>/<server>/data/ itself. The two external-cwd tests
now pass output_dir like their siblings, and the resolver's docstring and the
test docstrings say where such a directory still comes from: an earlier
collate run, or a dataset kept under resources_servers/<server>/data/.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: qiaochuz <[email protected]>
@qiaochuz-nv

Copy link
Copy Markdown
Contributor Author

/ok to test 489e290

@athitten
athitten added this pull request to the merge queue Nov 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/44589813756

Merged via the queue into main with commit 813fbdb Nov 19, 2026
124 of 127 checks passed
@athitten
athitten deleted the qiaochuz/nvb-6900465-collate-schema-dir-shadow branch November 19, 2026 18:51
@qiaochuz-nv

Copy link
Copy Markdown
Contributor Author

Retrospective QA-fix tracking issue: #6589

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 bug Something isn't working complexity:low Localized change in one scope with a small, straightforward review surface QA_fix Fix implemented by a QA team member ready-to-merge PR is approved, current, and waiting for final CI or merge risk:high Autobot PR risk: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants