Skip to content

feat(rollout): expose per-rollout enrichment to run_examples callers - #5318

Closed
marcromeyn wants to merge 1 commit into
mainfrom
romeyn/rl-path-records
Closed

marcromeyn wants to merge 1 commit into
mainfrom
romeyn/rl-path-records

Conversation

@marcromeyn

Copy link
Copy Markdown
Contributor

What and why

run_examples returns the raw /run result, so a training framework that dispatches through it (NeMo RL) never gets what ng_collect_rollouts records for each rollout: the model server's captured calls, the normalized ng_trajectory and ng_perf. RL works around that today by dumping Gym state itself (NVIDIA-NeMo/RL#4890). This takes over #5023 (Pranav Thombre, co-author) on current main.

  • enrich_run_result(row, result, *, capture_dirs, observability_enabled, include_payloads=True, rollout_latency_ms=None, delete_capture=False) runs the collector's per-rollout steps in place: copy the row's rollout identity onto the result where it is missing, wait for the rollout's in-flight capture writes, merge its captured model calls, project ng_trajectory and assemble ng_perf. ng_collect_rollouts now calls it, so there is one implementation and no behavior change there.
  • run_examples(..., enrich_results=False, include_model_call_payloads=True, delete_model_call_capture=False): an opt-in to enrich each result before it is returned, including results recovered by aclose_and_drain(). With it off, results are exactly what /run returned.
  • An Environment Server reply to a materialized task is enriched through the record the collector stores; the enrichment and identity keys are added to the reply's top level, which otherwise keeps its shape.

Rules carried over from the collector and the run-record work:

  • A row the dispatch budget never started is not joined to model calls; an interrupted try keeps the calls it made.
  • A row that names no task (no task id, task index or trajectory identity) gets no ng_trajectory rather than a guessed task id. An explicit task id no longer needs a task index.
  • delete_model_call_capture removes a rollout's capture file only when its writes drained, the readback was complete and the bodies were kept; it is refused with include_model_call_payloads=False.

Not in this PR: Claude Code turns built from captured Anthropic calls (part of #5023, to follow separately), and Gym writing these records and failure rows to the run folder in the RL path (FEP-1907, next).

Validation

  • With the telemetry extra: pytest tests/unit_tests/test_rollout_collection.py tests/unit_tests/test_fern_docs_links.py: 638 passed.
  • 15 tests for the enrichment: merged calls without touching reward or response, metadata-only payloads, safe and refused capture deletion (writes not drained, unreadable records), identity only without capture, interrupted vs never-started tries, rows without a task, explicit task ids, episode replies (including a retried attempt), drained results, and the run_examples opt-in.
  • pre-commit on the changed files.

Rollout evidence

gym env start --resources-server example_single_tool_call --model-type openai_model ++observability_enabled=true ++model_call_capture_dir=... with gpt-6-luna, then RolloutCollectionHelper().run_examples(rows, enrich_results=...) on two example rows: without the option, the results were the raw /run replies; with it, each came back with its rollout id, its captured model calls, ng_trajectory and ng_perf. Not run: an Environment Server pairing through run_examples.

Compatibility

Opt-in only; ng_collect_rollouts output is unchanged. With enrich_results, run_examples fetches the global config once more per call to find the capture directories.

Linear: FEP-1907 (part of FEP-1829 / GYM-1170). Supersedes #5023.

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

@marcromeyn

Copy link
Copy Markdown
Contributor Author

/ok to test 5bede50

@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team October 29, 2026 15:37
@svcnvidia-nemo-ci svcnvidia-nemo-ci added 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 labels Oct 29, 2026

@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 — one documentation NOTE; no confirmed runtime defects found.

Reviewed both changed files and the affected capture, trajectory, episode-identity, and completion/drain contracts. The capture-safety topic was independently inspected because its delegated report was unavailable. This was a static, read-only review; tests were not executed.

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.

Connections that were never established can still be retried safely.
It does not convert failures to successful result rows.

``enrich_results`` runs :func:`enrich_run_result` on each result before it is returned, so the caller receives

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.

NOTE — Suggest documenting the framework enrichment workflow in the user guide.

The new public option is explained here, but the rollout-evidence guide and capture guide do not show how framework callers obtain these attachments through run_examples. This is the PR's principal user-facing feature, for which the review rubric calls for user documentation.

Correction: add a short section to the rollout-evidence guide, after “Enable Collection,” showing shared capture configuration and this usage with prepared rows:

from nemo_gym.rollout_collection import RolloutCollectionHelper

helper = RolloutCollectionHelper()
rows = helper.preprocess_examples(examples)
completions = helper.run_examples(rows, enrich_results=True)
try:
    for completion in completions:
        row, result = await completion
        # Consume the enriched result here.
finally:
    await completions.aclose()

Explain that the caller must be able to read the deployment's capture directory and that enrichment returns evidence in memory, not run-folder records. This is a proposed documentation example, not executed code; please verify it before adopting it.

Preserve: distinguish raw default-off replies from enriched replies; metadata-only capture from retained bodies; and optional deletion from unconditional cleanup (deletion requires retained payloads, drained writes, and complete readback). Do not imply that enrichment rebuilds training-token responses or changes rewards.

Acceptance: verify the rendered example and links. Against a capture-enabled deployment, the documented enriched call should return ng_model_call_capture and, for a named task with usable evidence, ng_trajectory; document that omitting enrich_results=True returns the raw reply.

@github-actions github-actions Bot added the sla:review-overdue Review response is over the one-business-day SLA label Oct 30, 2026
@marcromeyn
marcromeyn force-pushed the romeyn/rl-path-records branch from 5bede50 to 674a8f9 Compare November 2, 2026 13:57
@marcromeyn

Copy link
Copy Markdown
Contributor Author

/ok to test 674a8f9

run_examples returns the raw /run result, so a training framework that
dispatches through it (NeMo RL) never gets what ng_collect_rollouts records
for each rollout: the model server's captured calls, the normalized
ng_trajectory and ng_perf.

enrich_run_result runs the collector's per-rollout steps in place: wait for
capture quiescence, merge the captured model calls, project ng_trajectory and
assemble ng_perf. ng_collect_rollouts now calls it, so there is one
implementation and no behavior change there. run_examples gains an opt-in
enrich_results (with include_model_call_payloads and delete_model_call_capture);
with it off, results are exactly what /run returned.

A row that never started is not joined to calls; an interrupted try keeps the
calls it made. A row that names no task gets no ng_trajectory rather than a
guessed task id, and deleting the capture without keeping payloads is refused.

Co-authored-by: Pranav Thombre <[email protected]>
Signed-off-by: Marc Romeyn <[email protected]>
@marcromeyn
marcromeyn force-pushed the romeyn/rl-path-records branch from 674a8f9 to 7b9ed8d Compare November 2, 2026 13:58
@marcromeyn

Copy link
Copy Markdown
Contributor Author

/ok to test 7b9ed8d

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

All of this is carried in #5443 with your authorship: enrich_run_result and the enrich_results, include_model_call_payloads and delete_model_call_capture options on run_examples. The one real change in the port to main is that with enrich_results the rows now go through collection's own outcome builder, so under route_failures_to_sidecar a failed /run comes back as the typed RolloutFailureRecord instead of an enriched raw error; rows without a rollout identity keep the plain dispatch. #5443 is in the merge queue now, and once it lands nothing remains here, so this one can be closed.

@marcromeyn

Copy link
Copy Markdown
Contributor Author

Carried into #5443 (merged), rebased onto the failure stack with authorship kept; closing this one.

@marcromeyn marcromeyn closed this Nov 5, 2026

This branch was previously deployed

1 inactive deployment
public — 7b9ed8d4 Deployed Nov 2, 2026 by copy-pr-bot[bot] via release / finalize / notify #9152
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.

3 participants