Skip to content

refactor(rollouts): split rollout performance and trajectory building out of the collector - #5232

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

ananthsub merged 1 commit into
mainfrom
ananthsub/layout-rollouts-split

Conversation

@ananthsub

@ananthsub ananthsub commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Splits two parts out of the rollout collector: its performance numbers and building a rollout's trajectory record.

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 rsplit this
  class owners,remove later
Loading

What moves

flowchart LR
  subgraph RC["rollouts/rollout_collection.py"]
    C["The collector"]
    P["ng_perf numbers,<br/>DispatchLatencyTracker"]
    T["Building a rollout's<br/>trajectory record"]
  end
  subgraph TR["trajectory/trajectory_record.py"]
    M["The record models"]
    J["Joining model calls<br/>into observations"]
  end
  P --> P2["rollouts/rollout_perf.py"]
  T --> T2["rollouts/trajectory_builder.py"]
  T2 -->|"imports"| M
  classDef this fill:#fde68a,stroke:#b45309,stroke-width:2px,color:#1f2937
  class P2,T2 this
Loading
  • The functions that join model calls into observations stay in trajectory/trajectory_record.py. They transform records only, take no rollout state, and enforce identity rules that the trajectory record defines.
  • _nonnegative_int, a helper only the trajectory builder used, moves with it.

What stays importable from the old paths

  • Every moved name resolves at nemo_gym.rollout_collection and nemo_gym.rollouts.rollout_collection. A name the collector no longer uses resolves with one warning.
  • The collector imports back the five names it still calls: DispatchLatencyTracker, NG_PERF_KEY, _attach_ng_perf, _attach_trajectory_record and _has_observation_gap. They are ordinary attributes of rollout_collection, so they resolve there with no warning.
  • Patches that change with the split:
    • No longer reach anything through rollout_collection: _build_ng_perf, _build_trajectory_record, _trajectory_identity, _turn_content, _turns_from_model_calls and _nonnegative_int, and the globals the moved code looks up, such as maybe_rollout_id_from_run_body, TASK_ID_FIELDS, _strip_capture_payloads and the trajectory_record models. Patch them on nemo_gym.rollouts.rollout_perf or nemo_gym.rollouts.trajectory_builder.
    • The five imported-back names are the exception: patch them on nemo_gym.rollouts.rollout_collection to affect collection. A patch of them on rollout_perf or trajectory_builder does not reach the collector's call sites.
    • Nothing in this repo patches any of these through the wrong module.

How to review

One commit: the split with its MOVED_NAMES entries, rewritten references, retargeted test patches and attribute accesses, and test_trajectory_builder.py, which tests nemo_gym.models.token_capture.builder, moving to tests/unit_tests/models/test_token_capture_builder.py next to the other token capture tests. By hand:

  • The collector's imports from rollout_perf and trajectory_builder sit in the top import block, apart from the CLI shims at the end of the module, whose comment describes only them.
  • _strip_capture_payloads is grouped in _moved_paths.py with the names the collector no longer imports.
  • The _attach_ng_perf error test builds a trajectory that does produce ng_perf and checks that the patched _build_ng_perf ran, so it fails if the patch targets a module the code does not read.
  • A comment in terminus_2_sandboxed_agent names nemo_gym.rollouts.trajectory_builder for _trajectory_identity.

History of split files

The repository squash-merges, so this PR lands as one commit. Whole-module moves still show as renames. A split file does not: its old path stays with less in it, so the new file starts its own history. git blame -C -C <new file> follows the moved lines back to the old file, and git log --follow does not.

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.

Validation

  • pytest -n 16 tests/unit_tests, also with -W error for the moved names.
  • The _attach_ng_perf error test passes as written and fails with its patch moved to rollout_collection.
  • lint-imports.
  • pre-commit run on the changed files.
  • Server and agent tests run in CI.

Rollout evidence: N/A. The code moves unchanged; rollout rows and trajectory records are written as before.

Compatibility

  • Old paths work until 0.10.0, with one warning each, and give the same objects.
  • Trajectory building and performance numbers now log under nemo_gym.rollouts.trajectory_builder and nemo_gym.rollouts.rollout_perf.
  • 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:36
@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 split refactor(rollouts): split rollout performance and trajectory building out of the collector Oct 28, 2026
@ananthsub
ananthsub requested a review from yaoyu-33 October 28, 2026 22:36
@ananthsub ananthsub added feature New capabilities, enhancements, or enablement work area:core Shared APIs, servers, telemetry, health, and registries needs-review PR is ready for code review and waiting on a reviewer labels Oct 28, 2026
@ananthsub
ananthsub marked this pull request as ready for review October 28, 2026 22:36
@ananthsub
ananthsub requested a review from a team as a code owner October 28, 2026 22:36
@nemo-automation-bot
nemo-automation-bot Bot requested review from a team October 28, 2026 22:37
@ananthsub
ananthsub requested review from a team as code owners October 28, 2026 23:10
@ananthsub
ananthsub force-pushed the ananthsub/layout-rollouts-split branch from e786d38 to 08794c8 Compare October 28, 2026 23:10
@ananthsub
ananthsub force-pushed the ananthsub/layout-rollouts-split branch from 08794c8 to 594c35a Compare October 29, 2026 00:55
@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-split branch from fb6b98f to 4fc4df5 Compare October 29, 2026 16:27
@ananthsub
ananthsub force-pushed the ananthsub/layout-rollouts-split branch from 4fc4df5 to dd4d099 Compare October 29, 2026 16:45
@ananthsub
ananthsub force-pushed the ananthsub/layout-rollouts-split branch from dd4d099 to a9b8cb5 Compare October 29, 2026 17:01
@ananthsub
ananthsub force-pushed the ananthsub/layout-rollouts-split branch from a9b8cb5 to 0dcbb02 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.

Reviewed at 38b9e95. No blockers. The split itself checks out: no behaviour change, no new import cycle, and old paths still resolve. What's left is two small inline notes and a few text fixes below.

What we checked

  • Moved code is unchanged. All 11 items that leave rollout_collection.py are AST-identical in rollout_perf.py / trajectory_builder.py, docstrings included, and every collector definition that stays is unchanged. Every name the moved code reads binds to the same object as before.
  • Outputs are byte-identical. We ran the collector end to end on base and head with the same inputs. ng_trajectory, ng_perf, the output JSONL rows (key order included), the failures sidecar and the aggregate metrics file match byte for byte. That covers both dialects, error attempts, observation gaps, verifier-owned calls, and forced _build_* failures. Trajectory is still attached before ng_perf.
  • Compat and layering. Every moved name resolves at both nemo_gym.rollout_collection and nemo_gym.rollouts.rollout_collection to the same object. lint-imports keeps the contract. Neither new module imports rollout_collection. test_moved_paths.py, test_import_linter_coverage.py and test_public_api_facades.py pass.
  • Tests. tests/unit_tests/rollouts, test_dispatch_latency.py, server_runtime/test_verifier_observability.py and test_moved_paths.py all pass locally with the telemetry extra installed (1409 passed); test_rollout_collection.py really runs that way. The touched server and agent tests pass locally or in CI. Every hunk outside nemo_gym/ is a one-name retarget to the defining module.

Notes not tied to a diff line

  • tests/unit_tests/rollouts/test_trajectory_builder.py (pure rename, so there's no line to comment on) tests nemo_gym.models.token_capture.builder, not the new nemo_gym.rollouts.trajectory_builder; it only shares the name. Could it stay where it was, or go to tests/unit_tests/models/ next to the other token-capture tests (for example as test_token_capture_builder.py)? Under rollouts/ it reads as the new module's test file, and per-package CODEOWNERS would route it to the wrong group.
  • responses_api_agents/terminus_2_sandboxed_agent/app.py:185 still says "_trajectory_identity in rollout_collection"; it now lives in nemo_gym.rollouts.trajectory_builder.

PR text

  • Compatibility section. "Every moved name resolves … with one warning" and "A patch through rollout_collection of a moved function has no effect" don't hold for the five names the collector imports back: DispatchLatencyTracker, NG_PERF_KEY, _attach_ng_perf, _attach_trajectory_record and _has_observation_gap.
    • They resolve from rollout_collection with no warning.
    • A patch on rollout_collection still reaches the collector's call sites, and a patch on rollout_perf / trajectory_builder does not.
    • Since #5166 asks each split PR to list the patches that stop taking effect, could the section say instead:
      • Patches through rollout_collection that no longer reach anything: _build_ng_perf, _build_trajectory_record, _trajectory_identity, _turn_content, _turns_from_model_calls and _nonnegative_int.
      • Same for the globals the moved code looks up, such as maybe_rollout_id_from_run_body, TASK_ID_FIELDS, _strip_capture_payloads and the trajectory_record models.
      • The five imported-back names are the exception: patch them on rollout_collection to affect collection.
    • Nothing in this repo patches any of these through the wrong module today.
  • Commit message. It still says the three join functions move from trajectory/trajectory_record.py to trajectory_builder.py, that the contract drops the trajectory→rollouts exception ("9 remain"), and that code outside nemo_gym, "tests included", is pointed at nemo_gym.<package>. None of that is in this diff: trajectory_record.py and pyproject.toml are untouched, and the PR body correctly says the join functions stay. Since the PR lands as one squashed commit, could the message be brought in line before merge?
  • For anyone with log filters: the three warning lines from trajectory building and ng_perf now log under nemo_gym.rollouts.trajectory_builder / nemo_gym.rollouts.rollout_perf, as the body says.

CI at 38b9e95

  • Unit tests / Test: one failure, inherited from #5231 with the identical failure on its head: tests/unit_tests/telemetry/test_call_sites.py::test_materialized_dispatch_takes_its_id_from_the_row_not_the_episode_body.
    • Cause: line 766 still does from tests.unit_tests import test_rollout_collection, but #5231 moved that file into tests/unit_tests/rollouts/.
    • Fix: belongs in #5231. Change the import to from tests.unit_tests.rollouts import test_rollout_collection as collection_tests.
  • Harness conformance: only the non-blocking kilocode model_error probe fails, the same as on #5231.
  • Server suites: all shards pass.

Comment thread nemo_gym/rollouts/rollout_collection.py Resolved
yaoyu-33
yaoyu-33 previously approved these changes Nov 2, 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.

Approving at 38b9e957a059. The team review found no blockers or risks; the remaining inline notes are optional and can be handled here or in a follow-up.

@ananthsub

Copy link
Copy Markdown
Contributor Author

Replies to the summary, as of 3be239ce79:

  • test_trajectory_builder.py: it now moves to tests/unit_tests/models/test_token_capture_builder.py, next to the other token capture tests, since it tests nemo_gym.models.token_capture.builder and not the new trajectory_builder.
  • terminus_2_sandboxed_agent/app.py: the comment now names nemo_gym.rollouts.trajectory_builder for _trajectory_identity.
  • Compatibility section: rewritten as you suggested. It lists the patches through rollout_collection that no longer reach anything, by name, and calls out the five imported-back names as the exception: patch them on rollout_collection to affect collection.
  • Commit message: rewritten to match the diff. It no longer says the join functions move or that a contract exception goes away, and it states the public API rule as the stack applies it.
  • CI telemetry import: fixed in refactor(rollouts): move rollout collection and health into nemo_gym/rollouts #5231, where the file moved.

… out of the collector

rollout_collection.py loses the per-rollout performance numbers, which move to
rollouts/rollout_perf.py, and the code that builds a rollout's trajectory record from its model
calls, which moves to rollouts/trajectory_builder.py, along with a small helper only that code
used.
The join functions in trajectory/trajectory_record.py stay where they are, and the import-linter
contract does not change.
The collector imports back the five names it still calls: DispatchLatencyTracker, NG_PERF_KEY,
_attach_ng_perf, _attach_trajectory_record and _has_observation_gap.

The split names are recorded in MOVED_NAMES under the old module paths.
In-repo references are rewritten with scripts/migrate_imports.py, and test patches and attribute
accesses point at the new modules.
The token capture builder test moves to tests/unit_tests/models/test_token_capture_builder.py, next
to the other token capture tests, because it tests nemo_gym.models.token_capture.builder, not the
new trajectory_builder module.

The public API of each layout package that exists here is regenerated from what code outside the
library imports.
Code outside nemo_gym and its tests imports from nemo_gym.<package>, and the library's tests import
from the module that defines each name.

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

This branch was previously deployed

1 inactive deployment
public — 4d1f1030 Deployed Nov 3, 2026 by copy-pr-bot[bot] via release / finalize / notify #9589
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 ready-to-merge PR is approved, current, and waiting for final CI or merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants