Skip to content

feat(eval): run_examples records, run-folder shards and gym eval status read the Store - #5443

Merged
AdamRajfer merged 113 commits into
mainfrom
arajfer/run-records-on-store
Nov 4, 2026
Merged

AdamRajfer merged 113 commits into
mainfrom
arajfer/run-records-on-store

Conversation

@AdamRajfer

@AdamRajfer AdamRajfer commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Training frameworks that dispatch through RolloutCollectionHelper.run_examples now get the same records as gym eval run. Each returned result is the collector's own record. A call can also write its rollouts to a run folder as a shard that the Store, the run health check, gym eval aggregate and gym eval status read like an eval run, and that gym eval run can resume. gym eval status reads saved progress from the Store for every run.

This carries Marc Romeyn's three run-records PRs (#5318, #5359, #5360), with his authorship and sign-off, adapted to the failure-handling work now in main (typed RolloutFailureRecord rows, Store-based resume selection, causal failure events). The PR targets main.

What it does

  • Enrichment returns the collector's record. With enrich_results=True, run_examples builds each result with the collector's own outcome builder. A result carries its rollout identity, captured model calls (ng_model_call_capture), ng_trajectory and ng_perf. Under route_failures_to_sidecar, a failed /run comes back as the typed RolloutFailureRecord, with the captures behind its failure evidence kept.
  • Run-folder shards. record_output_dir with record_shard writes each rollout as collection lays out a run. The caller picks the label and Gym owns the file names: rollouts-<shard>.jsonl, a failures sidecar created up front, the rows as materialized inputs, a verified run manifest with every row's attempt reserved before the first request, and the shard's saved progress. Rows without task and rollout indices are refused before an existing shard is replaced. A token identifies the current writer, so a superseded writer can neither append nor overwrite the newer writer's status. Reopening a label replaces the shard, so a replayed step does not duplicate rows.
  • A shard's model calls are its own. A shard dispatches each row under the row's own rollout id (its _ng_rollout_id, or <task>-<rollout>), prefixed with the shard's run id. A row returned by an earlier shard has that shard's prefix replaced, not nested. The capture key is this id plus the usual attempt suffix, so capture_key and the /ng-rollout/<capture key> path keep the form refactor(capture): name capture keys capture_key on the ledger control surface #5248 gave them; only the value is the shard's own. The Store, the manifest, the records and the returned rows use the same id, so a caller reads a capture's key from the returned row. Runs that are not shards (gym eval run, or run_examples with only enrich_results) keep their ids and capture keys unchanged.
  • A recorded shard resumes like a run. The shard's manifest is built with RunManifest.create, the identity function collection uses, from the shard's materialized inputs, the rows as dispatched, the collection defaults and the running server configuration. gym eval run +input_jsonl_fpath=<dir>/rollouts-<shard>_materialized_inputs.jsonl +output_jsonl_fpath=<dir>/rollouts-<shard>.jsonl +resume_from_cache=true then verifies the shard and runs only what it still lacks. As for any run, an operational difference resumes with a drift note and a semantic one is refused by name. A shard whose rollouts are not numbered 0, 1, … in order per task, or whose running configuration names no identity, is still recorded, and a resume refuses it with the reason.
  • Status comes from the Store. Every run, with or without a batch manifest, takes its saved progress from the Store's selected records and failures, including failures_by_kind and model_final_by_kind. The status file is written under the writer's lock and throttled. It is brought up to date at the end, including when the last expected row of a shard is an omitted row the shard does not keep, and when a step after collection fails.
  • gym eval status <run dir | job id> reports completed and remaining rollouts, failures by kind, each exporter's receipt and the live tracking run id.
  • Docs: recording rollout evidence from a training framework (shards, capture keys, resuming a shard), and the gym-eval skill's use of gym eval status.

Review follow-ups in this head

  • Capture keys per shard (Marc): a row fed back into a later shard, or indices numbered again each step, used to share a capture key with the earlier shard, so the later shard's records also carried the earlier shard's model calls. Shard-scoped rollout ids fix this, as described above.
  • Normal resume of a recorded shard (Marc): the shard's manifest used to hash the caller's rows and the recording options, while a resume hashes the source file and the resolved configuration, so the resume was refused. Both now take the same identity, and a test resumes through the eval entry point rather than handing the saved manifest back in.
  • Final shard status after an omitted last row (Giulio): with record_omitted_rollouts off, an omitted last row returned before the status write. With throttling, gym eval status then reported one completed result where two were saved. That path now writes the final status.

Merge order

main, then this PR. Yuhe Zhang's #3881 is based on this branch, #3879 on #3881, and #5504 on #3879; they merge after this PR. Marc's originals stay open for reference and are closed when this PR lands.

Validation

  • Full unit suite at this head: 0 failures (19579 passed, 25 skipped).
  • Focused tests in tests/unit_tests/rollouts/test_rollout_collection.py; each fails without its change:
    • test_a_shard_records_only_the_model_calls_of_its_own_dispatch[returned row fed back] and [indices numbered again]
    • test_a_recorded_shard_resumes_through_the_eval_entry_point
    • TestRunRecordWriter::test_a_shard_without_a_configuration_identity_is_recorded_and_says_it_will_not_resume
    • TestRunRecordWriter::test_shard_status_writes_are_throttled_and_end_current (two scored rows, then an unkept omitted row: two completed, one remaining)
  • Identity test: test_a_run_that_is_not_a_shard_keeps_its_rollout_ids_and_capture_keys passes before and after the shard change, for both gym eval run and run_examples with enrich_results.
  • ruff and the import-layering contract pass.

🤖 Generated with Claude Code

@copy-pr-bot

copy-pr-bot Bot commented Nov 2, 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.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added feature New capabilities, enhancements, or enablement work area:evaluation Evaluation, rollout collection, reward profiling, comparison, and exporters labels Nov 2, 2026
@AdamRajfer
AdamRajfer marked this pull request as ready for review November 2, 2026 15:24
@nemo-automation-bot
nemo-automation-bot Bot requested review from a team November 2, 2026 15:24
@AdamRajfer
AdamRajfer added this pull request to stack #5408 November 2, 2026 15:26
@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the needs-review PR is ready for code review and waiting on a reviewer label Nov 2, 2026

@marcromeyn marcromeyn 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 Adam, the three PRs carry over well: the three constraints are met and the suites pass at f46c128 (1094 passed). Before merge, mostly the shard path:

  1. Shards can't be resumed or recovered (rollout_collection.py:1715): the manifest comes from RunManifest.import_legacy (legacy_import=True, unverified identity), so resume and resubmit --recover reject it, though RolloutStore.read works. Could the writer create a verified manifest and persist dispatch reservations first, like collection?
  2. _attempts isn't a reserved shard ending (:1643): aggregation skips *_attempts, so shards step_1 and step_1_attempts break the first. Reserve it; test both labels.
  3. Reused rows keep their old run id (:6059): dispatch keeps an existing _ng_run_id but each writer makes a new manifest id, so the Store rejects those failures. Stamp every dispatched copy with the writer's run id.
  4. Typed failures only when recording (:6072): with enrich_results=True, route_failures_to_sidecar=True and no shard, a judge failure returns the legacy dict with reward=0.0, unlike the description. Use the typed path for enrichment too (or narrow the description), with a test through the real dispatcher.

Minor: the shard status is written outside the token lock (:1781), so a stale writer can overwrite a newer one's; and the final status write is skipped once the loop succeeds (:4634), so a later upload or aggregation error leaves counts stale.

Approving once these are in.

@AdamRajfer

Copy link
Copy Markdown
Contributor Author

Thanks Marc. All six are in, each as its own signed commit on top of the earlier head:

  1. Verified manifest and reservations (111e16341): the writer now writes a RunManifest before the first request, as collection does: digests of the caller's rows and of the rows as dispatched, a digest of the recording options, and one attempt reserved per row in next_attempt. Records and materialized inputs carry the shard's run id, so the Store checks each record against the manifest. test_the_store_reads_a_shard_like_an_eval_run now also runs validate_resume and RolloutStore.start_or_resume(..., resume=True) on the shard and gets the failed rollout back as pending work.
  2. _attempts reserved (4afd75389); step_1_attempts is refused like the other sidecar endings, both labels in the test.
  3. Every dispatched copy names the shard's run (33fca7c8e), a row reused from an earlier run included; the caller's rows stay untouched. test_a_reused_row_is_recorded_under_the_shard_run reads the failure back through the Store.
  4. Typed path for enrichment (a52c28299): with enrich_results the rows are dispatched as collection dispatches them (copies naming the call's run, typed_outcomes=route_failures_to_sidecar, validate_results=True), so a judge failure comes back as the RolloutFailureRecord, as run_outcomes returns it. Rows without a rollout identity keep the plain dispatch, since a typed record needs one; the docstring says so. test_enrichment_returns_the_typed_failure_record_for_a_failed_run drives the real dispatcher with a judge failure and checks both paths.
  5. Shard status under the writer lock (b472d0505), and flush_status checks the writer token under the lock, so a superseded writer no longer overwrites the newer writer's status (test_a_superseded_writer_leaves_the_newer_shard_status_alone).
  6. Final status after a late failure (b06ca18ec): the exit-stack write runs whenever the regular final write has not happened yet, so an aggregation error after a successful loop leaves the counts current (test_run_status_ends_current_when_a_step_after_collection_fails).

Suites at the new head: tests/unit_tests/test_rollout_collection.py 717 passed; tests/unit_tests/test_cli_main.py 282 passed; tests/unit_tests/test_batch_status*.py 68 passed; tests/unit_tests/test_eval_recovery_gate.py 25 passed. The PR description is updated for the verified manifest and the typed enrichment path.

AdamRajfer and others added 5 commits November 4, 2026 14:34
run_examples records a shard on copies of the rows that name the shard's
run, but the copies kept the row's own rollout id, and with it the capture
key the model calls are staged under. Capture files are kept by default, so
a later shard that dispatched the same task and rollout (a row an earlier
shard returned, fed back, or indices numbered again each step) merged the
earlier shard's calls into its own records.

Each dispatched copy of a recorded shard now carries the row's own id (its
_ng_rollout_id, or <task>-<rollout>) prefixed with the shard's run id. A row
an earlier shard returned has that prefix replaced, not nested. The capture
key is that id with the usual attempt suffix, so capture_key and the
/ng-rollout/<capture key> path keep their form; only the key is now the
shard's own. The Store, the manifest, the records and the returned rows use
the same id, so a caller reads a capture's key from the returned row.
enrich_results without recording keeps the caller's keys.

Tests: two shards that dispatch the same task and rollout, with the row fed
back or the indices numbered again, each record only their own calls (they
fail without the change). The shard tests stage captures under the
dispatched key, as the model server does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Adam Rajfer <[email protected]>
A recorded shard's manifest hashed the caller's rows and the recording
options, while the manifest gym eval run computes on resume hashes the
source file's bytes and the resolved configuration. Resuming a shard with
resume_from_cache was therefore refused for its source dataset and its
configuration. The earlier test passed the saved manifest in as the current
one, so it never compared the two.

The writer now builds the shard's manifest with RunManifest.create, the
identity function collection uses. Its inputs are the shard's materialized
inputs as the source file, the rows as dispatched, a collection config that
names the shard's input and output paths and leaves every other setting at
its default, and the call's server configuration. The identity file is
saved beside the manifest, as for any run, and replaced with the shard. So

  gym eval run +input_jsonl_fpath=<dir>/rollouts-<shard>_materialized_inputs.jsonl
    +output_jsonl_fpath=<dir>/rollouts-<shard>.jsonl +resume_from_cache=true

verifies and runs only what the shard still lacks. An operational
difference resumes with the usual drift note, and a semantic one is refused
and named. If the running configuration gives no identity (for example it
does not name the rows' agent), the shard is still recorded, with a
warning, and a resume refuses it and says why.

Tests: a shard recorded with one failure resumes through run_from_config,
dispatches only the failed row and ends with both rows scored; a shard
without a configuration identity is recorded and warns. Both fail without
the change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Adam Rajfer <[email protected]>
The training-framework section now says that a recorded shard dispatches
each row under its rollout id prefixed with the shard's run id, so a
capture's key is read from the returned row, and that a shard resumes with
gym eval run on its materialized inputs and its rollouts file.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Adam Rajfer <[email protected]>
…apture keys

Only a recorded shard prefixes its rollout ids with its run id. A plain
gym eval run and run_examples with enrich_results alone dispatch every row
under the id Gym derived before: <task>-<rollout>, or the row's own
_ng_rollout_id. The saved results carry the same ids, so recovery and
re-verification of such runs read the identities they always did. The test
passes before and after the shard change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Adam Rajfer <[email protected]>
…nkept omitted row

With record_omitted_rollouts left off, the shard writer returned for an
omitted row before its status write. When that row was the last one
expected and status writes were throttled, the final counts never reached
the status file: with two scored rows and an omitted third, gym eval status
reported one completed result instead of two. Closing the iterator
corrected it, but iterating to the end does not close it.

The early return now flushes the status when it handles the last expected
row. As with any flush, a writer that another writer superseded leaves the
newer status alone. The saved results do not change.

Test: the throttled status test also writes two scored rows and an unkept
omitted row, and expects two completed and one remaining (it reports one
completed without the change).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Adam Rajfer <[email protected]>
@AdamRajfer

Copy link
Copy Markdown
Contributor Author

/ok to test e28bb71

AdamRajfer and others added 3 commits November 4, 2026 15:27
…e shard

A recorded shard prefixes each row's rollout id with its run id, after
removing the prefix an earlier shard put on a row it returned. A row fed back
as `<earlier run>.0` and a new row whose own id is `0` therefore both became
`<this run>.0` in the same call. They would then share capture files and one
manifest identity. A training framework hits this when a step resubmits a
returned row next to fresh rows whose numbering restarted.

run_examples now refuses such a call before dispatch, and before the
existing shard is replaced. The error names both rows and both of their own
ids, so the caller can give each row a distinct _ng_rollout_id or distinct
task and rollout indices.

Test: `<earlier run>.0` beside `0` is refused with both ids named, nothing
is dispatched and the existing shard is kept. `<earlier run>.0` beside `1`
still dispatches, as `<run>.0` and `<run>.1`. It fails without the change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Adam Rajfer <[email protected]>
The capture key, a rollout id with its attempt suffix, also names the model
server's capture files. The longest of them is `<key>.capture.incomplete`,
and a file name holds at most 255 bytes. A recorded shard adds a 33-character
run-id prefix to each row's id, so a long explicit id could pass that limit
and fail only when the first model call was captured, mid-rollout.

A shared check, check_rollout_id_length in nemo_gym.core.episode_context,
allows a rollout id of up to 230 bytes. That leaves room for attempt
suffixes up to -a9999 and the longest capture file suffix, and also keeps a
key under a 256-character id limit. run_examples applies it to each
recorded row's id after the prefix is added, before dispatch and before the
existing shard is replaced. The error names the id, its length and the
limit.

Test: an id one byte over the limit, after the prefix, is refused with
nothing dispatched and no shard written. The longest id that fits
dispatches, and its capture file name at attempt 9999 is exactly 255 bytes.
It fails without the change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Adam Rajfer <[email protected]>
The library reference page generated from the judge_profile module failed
to parse: its module docstring wrote the pool node variable as
``${GYM_POOL_<POOL>_NODES}``, and the generated MDX read `<POOL>` as a tag.
The docs preview of any change that rebuilds the full reference failed on
it.

The docstring now names the variable as ``GYM_POOL_*_NODES``. No other
docstring combines a ${...} reference with an angle-bracket placeholder,
and the other pages built from docstrings parsed in the same build.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Adam Rajfer <[email protected]>
@AdamRajfer

Copy link
Copy Markdown
Contributor Author

/ok to test a54a932

@AdamRajfer

Copy link
Copy Markdown
Contributor Author

/ok to test e39ad64

@AdamRajfer

Copy link
Copy Markdown
Contributor Author

/ok to test e39ad64

marcromeyn
marcromeyn previously approved these changes Nov 4, 2026

@marcromeyn marcromeyn 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 Adam, re-checked at the new head (suites pass, 1127). Rows that would share a shard-scoped id are now refused before dispatch and before the shard is replaced, with both source ids in the error, and over-long ids are refused against the capture file-name limit; both have tests. Approving.

…stant

The library reference page for the judge_profile module failed to parse.
The page generator writes each field's default into an MDX attribute as
its Python repr, and JudgeExecutionProfile.qos_source defaulted to the
string "the partition's default". Because of the apostrophe, the repr is
double-quoted, so the generated line was

  <ParamField path="qos_source" type="str = "the partition's default"">

and MDX stopped at the `'` ("Unexpected character `'` in attribute name").

The default is now the module constant PARTITION_DEFAULT_QOS, with the same
text, so the page shows `str = PARTITION_DEFAULT_QOS`, as it does for
`kind: str = CPU_PROFILE`. The two other places that set the same source
use the constant too. The text in the operator's log does not change. No
other plain string default in nemo_gym contains an apostrophe.

Verified by generating the page locally with the docs CLI and compiling it
with MDX 3: the old page fails with the error above, the new one compiles.
The judge profile tests pass unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Adam Rajfer <[email protected]>
@AdamRajfer

Copy link
Copy Markdown
Contributor Author

/ok to test 47cbb9b

@AdamRajfer

Copy link
Copy Markdown
Contributor Author

/ok to test 47cbb9b

marcromeyn
marcromeyn previously approved these changes Nov 4, 2026

@marcromeyn marcromeyn 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.

Re-approving: the only change since my approval is the QOS-source default in judge_profile.py becoming a module constant, with no behaviour change.

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

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

@AdamRajfer

Copy link
Copy Markdown
Contributor Author

/ok to test 4eb68bf

@marcromeyn marcromeyn 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.

Re-approving after the merge of main: the PR's own change is identical (14 files), and the two conflict resolutions are imports only.

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

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

This branch was previously deployed

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

Labels

area:evaluation Evaluation, rollout collection, reward profiling, comparison, and exporters feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer 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.

4 participants