Skip to content

refactor(rollouts): move rollout collection and health into nemo_gym/rollouts - #5231

Merged
ananthsub merged 1 commit into
mainfrom
ananthsub/layout-rollouts
Nov 3, 2026
Merged

ananthsub merged 1 commit into
mainfrom
ananthsub/layout-rollouts

Conversation

@ananthsub

@ananthsub ananthsub commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Moves rollout collection and what judges saved rollouts into a new nemo_gym/rollouts/ package: the rollout collector, batch status, rollout health and outcomes, omitted rollouts, and reading saved model calls. The observability package becomes rollouts itself. The model call record splits out of observability/model_calls.py into trajectory/model_call_record.py instead: ModelCallRecord, building one from a saved exchange, its token counts, and totals across calls. That half depends on nothing above config/, and trajectory_record.py already refers to ModelCallRecord. Reading, merging, and clearing saved model calls needs the capture store, so it stays in rollouts/model_calls.py. harness_capabilities moves here too: it judges an agent harness from its saved rollouts, imports the rollout health code, and nothing in the library imports it. The collector's performance and trajectory-building code is split out in the next PR.

Where this PR sits

The stack lands bottom-up; each PR's base is the branch of the PR before it, so each diff shows only that PR's change.

flowchart LR
  compat["#5167<br/>Old import paths<br/>keep working"]
  linter["#5168<br/>import-linter<br/>layer contract"]
  prep["#5169<br/>Remove path and<br/>name couplings"]
  config["#5189<br/>Move config/"]
  utils["#5195<br/>Move utils/"]
  core["#5203<br/>Move core/"]
  client["#5206<br/>Move client/,<br/>start telemetry/"]
  trajectory["#5209<br/>Move trajectory/"]
  verification["#5210<br/>Move verification/"]
  metrics["#5211<br/>Move metrics/"]
  artifacts["#5212<br/>Move artifacts/"]
  srmods["#5214<br/>Move server_runtime/<br/>modules"]
  su["#5215<br/>Split server_utils"]
  model["#5224<br/>Move models/<br/>modules"]
  modelbase["#5225<br/>Split model<br/>call capture"]
  agents["#5228<br/>Move agents/"]
  data["#5229<br/>Move data/"]
  harbor["#5230<br/>Split the<br/>Harbor task CLI"]
  rollouts["#5231<br/>Move rollouts/"]
  rsplit["#5232<br/>Split the<br/>rollout collector"]
  testing["#5233<br/>Dissolve testing/"]
  orch["#5234<br/>Move orchestration/<br/>modules"]
  sup["#5235<br/>Split the<br/>server supervisor"]
  eval["#5244<br/>Move eval/"]
  env["#5298<br/>Move environment/<br/>registries"]
  cli["#5300<br/>Retire the<br/>cli_setup_command shim"]
  docs["#5385<br/>Describe the<br/>package layout"]
  owners["next<br/>CODEOWNERS:<br/>per-package groups"]
  remove["0.10.0<br/>Remove the<br/>old paths"]
  compat --> linter
  linter --> prep
  prep --> config
  config --> utils
  utils --> core
  core --> client
  client --> trajectory
  trajectory --> verification
  verification --> metrics
  metrics --> artifacts
  artifacts --> srmods
  srmods --> su
  su --> model
  model --> modelbase
  modelbase --> agents
  agents --> data
  data --> harbor
  harbor --> rollouts
  rollouts --> rsplit
  rsplit --> testing
  testing --> orch
  orch --> sup
  sup --> eval
  eval --> env
  env --> cli
  cli --> docs
  docs --> owners
  owners --> remove
  classDef this fill:#fde68a,stroke:#b45309,stroke-width:2px,color:#1f2937
  classDef later fill:#f3f4f6,stroke:#9ca3af,color:#4b5563,stroke-dasharray: 4 3
  class rollouts this
  class owners,remove later
Loading

Where the package sits

flowchart TD
  cli["cli/"]
  eval["eval/"]
  environment["environment/"]
  orchestration["orchestration/"]
  rollouts["rollouts/"]
  data["data/"]
  agents["agents/"]
  model["models/"]
  server_runtime["server_runtime/"]
  artifacts["artifacts/"]
  metrics["metrics/"]
  verification["verification/"]
  trajectory["trajectory/"]
  sandbox["sandbox/"]
  client["client/"]
  telemetry["telemetry/"]
  core["core/"]
  utils["utils/"]
  config["config/"]
  cli --> eval
  cli --> environment
  cli --> orchestration
  eval --> rollouts
  environment --> data
  orchestration --> data
  rollouts --> data
  rollouts --> agents
  rollouts --> model
  data --> server_runtime
  data --> artifacts
  agents --> server_runtime
  model --> server_runtime
  server_runtime --> metrics
  server_runtime --> verification
  server_runtime --> trajectory
  artifacts --> trajectory
  artifacts --> utils
  metrics --> utils
  verification --> sandbox
  trajectory --> core
  sandbox --> client
  client --> telemetry
  client --> utils
  telemetry --> core
  core --> config
  utils --> config
  classDef this fill:#fde68a,stroke:#b45309,stroke-width:2px,color:#1f2937
  classDef done fill:#d1fae5,stroke:#047857,color:#1f2937
  classDef todo fill:#f3f4f6,stroke:#9ca3af,color:#4b5563
  class rollouts this
  class config,utils,core,telemetry,client,trajectory,verification,metrics,artifacts,server_runtime,model,agents,data done
  class cli,eval,environment,orchestration,sandbox todo
Loading

An arrow means "imports"; each package imports only packages below it. Yellow: created by this PR. Green: created by an earlier PR in the stack. Grey: still to come.

What moves

Whole modules, unchanged:

Old path New path
nemo_gym/observability/__init__.py nemo_gym/rollouts/__init__.py
nemo_gym/observability/model_calls.py nemo_gym/rollouts/model_calls.py
nemo_gym/observability/model_calls.py (the record half) nemo_gym/trajectory/model_call_record.py
nemo_gym/rollout_collection.py nemo_gym/rollouts/rollout_collection.py
nemo_gym/batch_status.py nemo_gym/rollouts/batch_status.py
nemo_gym/rollout_health.py nemo_gym/rollouts/rollout_health.py
nemo_gym/health/ nemo_gym/rollouts/health/
nemo_gym/rollout_outcomes.py nemo_gym/rollouts/rollout_outcomes.py
nemo_gym/omitted_rollouts.py nemo_gym/rollouts/omitted_rollouts.py
nemo_gym/harness_capabilities/ nemo_gym/rollouts/harness_capabilities/
nemo_gym/rollout_records.py nemo_gym/rollouts/rollout_records.py
nemo_gym/rollout_recovery.py nemo_gym/rollouts/rollout_recovery.py
nemo_gym/rollout_store.py nemo_gym/rollouts/rollout_store.py

rollout_records.py, rollout_recovery.py and rollout_store.py came in with #3302 (persist failures and resume evaluations) after this stack started. main placed them in the rollouts layer, so they move with the rest of it and get MOVED_MODULES entries like the others.

How to review

One commit. Its changes:

  1. Renames, with no content changes.
  2. Everything else:
    • The moves are recorded in MOVED_MODULES in nemo_gym/_moved_paths.py.
    • In-repo references are rewritten by scripts/migrate_imports.py.
    • The contract's rollouts layer becomes the nemo_gym.rollouts package.
    • fern/docs.yml redirects the old library reference pages to the new ones.
    • observability, health, and harness_capabilities are recorded as packages, so their submodules resolve too; python -m nemo_gym.harness_capabilities keeps working.
    • The contract's testing layer drops harness_capabilities; it is part of nemo_gym.rollouts now. The testing package is dissolved in a later PR.
    • trajectory_record.py now imports ModelCallRecord from its own package, so the contract exception for that import goes away. 9 remain.
    • The names split into trajectory/model_call_record.py, and ModelServerRef, which observability/model_calls.py imported, have MOVED_NAMES entries, so they still resolve at nemo_gym.observability.model_calls and nemo_gym.rollouts.model_calls with one warning.
    • By hand: tests/unit_tests/telemetry/test_call_sites.py imports the moved test module as from tests.unit_tests.rollouts import test_rollout_collection, a form the test-move rewrite missed, and the checker's README links the harness conformance guide one directory further up.
    • The harness checker's __init__.py becomes a lazy public API of its own (see Public API).
    • Found while building this PR, and fixed in refactor(artifacts): move run artifacts and exporters into nemo_gym/artifacts #5212: the __getattr__ rollout_collection.py gained there looked moved names up under the module's own name, which changes when the module moves.
  3. Tests: the collector, batch status, health, outcomes, model call, rollout record, recovery, store and recovery review tests move into tests/unit_tests/rollouts/; the model call record tests into tests/unit_tests/trajectory/; and the harness capability tests into tests/unit_tests/rollouts/harness_capabilities/. The conformance CI workflow, its scripts, and their docs name the new test path; tests that find the repository root look one level further up.

Public API

Every layout package that exists after this PR has a lazy public API in its __init__.py: the names code outside nemo_gym/ imports from it (servers and their tests, benchmarks, scripts, and code samples in docs and skills), plus every name it already exported, each served from the submodule that defines it on first use. Code outside nemo_gym/ and its tests (servers and their tests, benchmarks, scripts, and docs) imports those names from nemo_gym.<package>, so later moves inside a package leave it alone. Code inside nemo_gym/, and the library's tests under tests/, import from the module that defines each name, so the import-linter contract sees every dependency and a test reads what it patches. A patch target names the module the code under test looks the name up in. AGENTS.md states the rule.

nemo_gym.rollouts.harness_capabilities has a public API of its own, as nemo_gym.data.tasks.harbor does since #5229. The checker's names, such as main, NAMES and json_rows, would otherwise be exported from nemo_gym.rollouts, where from nemo_gym.rollouts import main reads like the collector's entry point. The harness conformance scripts import them from nemo_gym.rollouts.harness_capabilities, and nemo_gym.rollouts exports only the rollout collection and health names.

Validation

  • pytest -n 16 tests/unit_tests, also with -W error for the moved paths.
  • Tests that need the telemetry extra, such as tests/unit_tests/telemetry/test_call_sites.py, skip without it, so locally they run only in a venv with that extra; CI's Test job runs them. That is how the stale test import above reached CI at an earlier head.
  • lint-imports.
  • pre-commit run on the changed files.
  • Server and agent tests run in CI.

Rollout evidence: N/A. The modules move unchanged.

Compatibility

  • Old paths work until 0.10.0, with one warning each, and give the same module objects.

  • Logger names follow the module path, so these modules now log under nemo_gym.rollouts.*. A logging config set on nemo_gym still covers them.

  • Patch targets that change with the model_calls split. No patch in this repo is affected, but a downstream test that patches the old module may stop taking effect:

    Names Patch them on
    extract_token_stats, ModelCallRecord, _cache_signal, _tool_calls_and_reasoning, _as_arguments, _prompt_size, _token_count, _usage_detail_token nemo_gym.trajectory.model_call_record. A patch on nemo_gym.observability.model_calls or nemo_gym.rollouts.model_calls no longer reaches build_model_call_record.
    build_model_call_record, aggregate_model_call_records nemo_gym.rollouts.model_calls. Its readers call their own imported bindings, so a patch on nemo_gym.trajectory.model_call_record does not reach them.
  • Open branches: run python scripts/migrate_imports.py <paths>.

Issue

Part of #5166.

@ananthsub
ananthsub added this pull request to stack #5170 October 28, 2026 22:26
@copy-pr-bot

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

@ananthsub ananthsub changed the title ananthsub/layout rollouts refactor(rollouts): move rollout collection and health into nemo_gym/rollouts Oct 28, 2026
@ananthsub ananthsub added feature New capabilities, enhancements, or enablement work area:core Shared APIs, servers, telemetry, health, and registries labels Oct 28, 2026
@ananthsub
ananthsub requested a review from yaoyu-33 October 28, 2026 22:27
@ananthsub ananthsub added the needs-review PR is ready for code review and waiting on a reviewer label Oct 28, 2026
@ananthsub
ananthsub marked this pull request as ready for review October 28, 2026 22:27
@ananthsub
ananthsub requested a review from a team as a code owner October 28, 2026 22:27
@nemo-automation-bot
nemo-automation-bot Bot requested review from a team October 28, 2026 22:28
@github-actions

github-actions Bot commented Oct 28, 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.

HOLD — one BLOCKER in executable-module compatibility, one RISK in the telemetry test migration, and one documentation NOTE.

Reviewed the changed hunks and affected import aliases, consumers, test fixtures, and conformance paths. Static source review only; tests, CLI commands, and documentation generation were not executed.

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


Inline comments (escaped v1):

  • nemo_gym/_moved_paths.py line 77: BLOCKER — Preserve execution through the old package name.

    python -m nemo_gym.harness_capabilities --help no longer reaches the CLI. This alias routes executable-module loading of nemo_gym.harness_capabilities.__main__ through MovedModuleFinder, which implements ordinary imports but has no get_code method. Executable-module loading therefore fails instead of printing help. The base entry point was a physical source module; the new canonical command still is. This affects callers retaining the advertised old CLI path, not ordinary rollout collection.

    Could you support code loading without importing/executing the canonical __main__ prematurely? A small suggested implementation is to add CodeType to the existing types import and add this method to MovedModuleFinder:

    def get_code(self, fullname: str) -> CodeType | None:
        resolved = _resolve(fullname, self._moves)
        if resolved is None:
            return None
        _, new_name, _ = resolved
        spec = importlib.util.find_spec(new_name)
        get_code = getattr(spec.loader, "get_code", None) if spec else None
        return None if get_code is None else get_code(new_name)

    This delegates to the canonical source loader while leaving create_module/exec_module unchanged: old/new ordinary imports must remain identical objects, and relative CLI imports must still resolve through those aliases. Please verify this source-reasoned suggestion before adopting it.

    Proposed acceptance checks, not executed: subprocess-run both package names with --help; both must exit 0 and list inspect/matrix. Run both against the same valid synthetic bundle with separate output directories: both must return 0 with verdict=fulfilled; removing a required request must make both return 1. Retain the existing module-identity, single-execution, and patch-through-alias assertions in the compatibility tests.

  • tests/unit_tests/telemetry/test_call_sites.py line 766: RISK — Update the remaining import of the relocated collector tests.

    With the telemetry extra installed, test_materialized_dispatch_takes_its_id_from_the_row_not_the_episode_body now raises ImportError here before exercising dispatch. This PR moves the imported module into the rollout test package, but leaves this import unchanged. The old module is absent and the package initializer supplies no alias. The core CI script installs telemetry specifically so these tests run.

    Could you replace this line with:

        from tests.unit_tests.rollouts import test_rollout_collection as collection_tests
    

    The relocated helpers and routing fixtures retain everything this test uses; no production or fixture changes are needed. Preserve the distinction between collector-row identity and the posted episode body rather than removing or skipping this regression case.

    Proposed acceptance checks, not executed: with telemetry installed, run this case and then the complete call-site test file. This case must reach the assertions that the dispatch span has rollout ID 0-0 and the posted body contains episode_id. The neighboring standalone and embedded flat-row tests must retain their separate-trace versus caller-trace assertions.

  • nemo_gym/rollouts/harness_capabilities/README.md line 3: NOTE — Update the relocated README’s guide link.

    Clicking “Harness Conformance” now resolves the two parent traversals to nemo_gym, producing a nonexistent nemo_gym/fern/... destination. Before this move, they reached the repository root. Could you preserve access to the existing guide with this replacement?

    The checker guide is maintained in [Harness Conformance](../../../fern/versions/latest/pages/observability/harness-conformance.mdx).
    

    Static acceptance check: resolving the replacement relative to the README directory must yield that existing root-level guide. Preserve the inspector command in lines 5–7 unchanged; only the document-relative link needs correction. No checks were executed.

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

@ananthsub
ananthsub removed this pull request from stack #5170 October 29, 2026 15:55
@ananthsub
ananthsub added this pull request to stack #5319 October 29, 2026 15:56
@ananthsub
ananthsub force-pushed the ananthsub/layout-rollouts branch from 0475d97 to a44c92c Compare October 29, 2026 16:27
@ananthsub
ananthsub force-pushed the ananthsub/layout-rollouts branch from a44c92c to bf51ad8 Compare October 29, 2026 17:01
@ananthsub
ananthsub force-pushed the ananthsub/layout-rollouts branch from bf51ad8 to 0f2bf03 Compare October 29, 2026 18:25

@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 this, Ananth. The move itself checks out: the moved files are identical apart from imports, the model_calls split keeps every definition unchanged, each old path still gives the same module object, lint-imports stays KEPT with one fewer exception, and the rollout outputs (JSONL fields and file names) don't change. One test import was missed, and it turns Unit tests / Test red; it's inline below.

Verdict: SHIP WITH CARE. 1 RISK and 1 NOTE inline, plus the items below.

The earlier automated review (svcnvidia-nemo-ci, at c42f580)

  • Its BLOCKER on python -m nemo_gym.harness_capabilities no longer applies. MovedModuleFinder.get_code from #5167 serves the old path, and --help exits 0 with the same output on both paths.
  • Its other two points are still open at this head and are carried inline: the test_call_sites.py:766 import and the README link.

Belongs in #5230

  • nemo_gym/data/__init__.py:90 (and :58) adds ORACLE_AGENT back to nemo_gym.data's public API. That fixes #5230, which drops the entry while environment_servers/harbor/app.py:115 and session.py:30 still import it. As a result, the Harbor environment server fails to import at #5230's head. Could the two lines move into #5230, so main isn't broken between the two merges? If not, could the PR body mention them?

Patch targets that change with the model_calls split

#5166 asks each split PR to list these. No patch in the repo is affected, but downstream tests that patch the old module would silently stop taking effect:

Names Patch them on
extract_token_stats, ModelCallRecord, _cache_signal, _tool_calls_and_reasoning, _as_arguments, _prompt_size, _token_count, _usage_detail_token nemo_gym.trajectory.model_call_record (a patch on nemo_gym.observability.model_calls or nemo_gym.rollouts.model_calls no longer reaches build_model_call_record)
build_model_call_record, aggregate_model_call_records still nemo_gym.rollouts.model_calls (its readers call their own imported bindings; a patch on nemo_gym.trajectory.model_call_record doesn't reach them)

Could this table go in the body's Compatibility section?

Smaller points (your call)

  • The move changes the CLI-shim warning text. from nemo_gym.rollout_collection import collect_rollouts now says "nemo_gym.rollouts.rollout_collection.collect_rollouts has moved", which names a path that never shipped, because moved_attr_getter(__name__, ...) now gets the new module name. It's the same pattern raised on #5211 (metrics/reward_profile.py), and it recurs at data/prompt.py:189 (#5229). It's probably best fixed once for the whole stack: either moved_attr_getter resolves the old name the way moved_names_getattr does since #5212, or the two names move into MOVED_NAMES["nemo_gym.rollout_collection"].
  • Is it intended that nemo_gym.rollouts exports the harness checker's main (plus NAMES and json_rows) at package level? from nemo_gym.rollouts import main reads like the collector's entry point, and it rules out any later rollouts main.

CI at 21575f5

  • Unit tests / Test: 1 failed, 13526 passed. The one failure is the inline test_call_sites.py:766 import, and Nemo_CICD_Test fails only because of it.
  • Harness conformance (non-blocking): the kilocode model_error probe fails exactly as it does on #5230, so it isn't from this PR.
  • All eight server shards pass. Lint, secrets-detector, copyright and docs checks pass too.
  • After the fix, could the Validation section be updated? It currently says the only failures are environment-specific.

What we checked

  • Renames are byte-identical or identical apart from imports. All 295 rewritten imports resolve to the same object. The split's 23 definitions are body-identical. 1286 test IDs before and after.
  • Old paths give the same modules, with a warning. In-repo patch targets still reach their lookups.
  • fern/docs.yml redirects are complete in both forms, and the frozen v0.6.0/v0.7.0 links are already pinned. CI path filters and CODEOWNERS are updated.
  • lint-imports is KEPT (9 ignored).
  • The wheel ships all 21 nemo_gym/rollouts/ files. Base-era pickles load at head.
  • Touched server, model and agent tests pass locally.

Not verified: GPU, real sandboxes, and agents whose own dependencies (tau2, nooa, hermes, miniswe, terminus_2) aren't in the core venv; their new imports were checked to resolve.

…rollouts

The observability package becomes nemo_gym/rollouts itself, with
model_calls.py; the rollout collector, batch status, rollout health and
outcomes, omitted rollouts, the health package, and harness_capabilities
move into it.

Record the eight moves in MOVED_MODULES (observability, health and
harness_capabilities as packages), rewrite in-repo references with
scripts/migrate_imports.py, make the contract's rollouts layer the
nemo_gym.rollouts package and its testing layer nemo_gym.testing alone,
and redirect the old library reference pages in fern/docs.yml.

The harness capability tests move with their package to
tests/unit_tests/rollouts/harness_capabilities; the conformance CI
workflow, its scripts and their docs name the new test path. Tests that
find the repository root look one level further up.

Regenerate the public API of each layout package that exists here from
what non-test code outside nemo_gym imports, and point code outside
nemo_gym, tests included, at nemo_gym.<package>.

Signed-off-by: Ananth Subramaniam <[email protected]>
@ananthsub

Copy link
Copy Markdown
Contributor Author

Replies to the summary, as of 38b6ad2c36:

  • The earlier automated review: both open points are fixed. The test_call_sites.py import uses the new test path, and the checker README links the guide from its new depth.
  • ORACLE_AGENT (belongs in refactor(data): split the Harbor run commands out of the task CLI module #5230): resolved there and in refactor(data): move the task data modules into nemo_gym/data #5229. nemo_gym.data.tasks.harbor has a public API of its own that exports ORACLE_AGENT, so main is not broken between merges, and this PR no longer touches nemo_gym/data/__init__.py.
  • Patch targets of the model_calls split: your table is in the description's Compatibility section. The definitions are where it says: all ten names are defined in trajectory/model_call_record.py, and rollouts/model_calls.py calls build_model_call_record and aggregate_model_call_records through its own imports.
  • CLI-shim warning text: fixed stack-wide in refactor(models): split model call capture out of the model server base and move the OpenAI client into client/ #5225, where moved_attr_getter names the path the caller imported. from nemo_gym.rollout_collection import collect_rollouts now warns about nemo_gym.rollout_collection.collect_rollouts.
  • nemo_gym.rollouts exporting the checker's main: the checker now has a public API of its own, nemo_gym.rollouts.harness_capabilities, as Harbor does since refactor(data): move the task data modules into nemo_gym/data #5229. main, NAMES, json_rows and the other checker names are exported there and not from nemo_gym.rollouts, and the conformance scripts import them from the checker. Verdict stays in nemo_gym.rollouts, because it is defined in rollout health.
  • Validation: updated. The section no longer says the only failures are environment-specific, and it notes why the telemetry tests run only where that extra is installed.

This branch was previously deployed

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

Labels

area:core Shared APIs, servers, telemetry, health, and registries feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants