Skip to content

refactor(core): move shared definitions into nemo_gym/core - #5203

Merged
ananthsub merged 1 commit into
mainfrom
ananthsub/layout-core
Oct 30, 2026
Merged

ananthsub merged 1 commit into
mainfrom
ananthsub/layout-core

Conversation

@ananthsub

@ananthsub ananthsub commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Moves the definitions every package and every environment shares into a new nemo_gym/core/ package, just above config/: the Responses API and Chat Completions types, episode identity, and failure kinds. These are the most imported names in Gym and in NeMo RL, so this PR is the biggest compatibility surface of the reorganization.

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

Where the package sits

flowchart TD
  cli["cli/"]
  eval["eval/"]
  environment["environment/"]
  testing["testing/"]
  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
  testing --> rollouts
  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 core this
  class config,utils done
  class cli,eval,environment,testing,orchestration,rollouts,data,agents,model,server_runtime,artifacts,metrics,verification,trajectory,sandbox,client,telemetry 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

Three files are split. Each keeps the part that belongs to a later package, which moves with that package.

flowchart LR
  subgraph OA["openai_utils.py today"]
    T["Responses API and Chat Completions types"]
    CL["NeMoGymAsyncOpenAI client and retries"]
  end
  subgraph RC["rollout_correlation.py today"]
    E["Current-episode tracking and capture keys"]
    MW["RolloutContextMiddleware and the routed path"]
  end
  subgraph ET["episode_types.py today"]
    ID["EpisodeId and TaskId"]
    REQ["Environment server request and response types"]
  end
  F["failure_kinds.py"] --> F2["core/failure_kinds.py"]
  T --> T2["core/responses_api_types.py"]
  E --> E2["core/episode.py"]
  ID --> E2
  CL --> CL2["openai_utils.py<br/>moves to model/ later"]
  MW --> MW2["rollout_correlation.py<br/>moves to server_runtime/ later"]
  REQ --> REQ2["episode_types.py<br/>moves to server_runtime/ in #5214,<br/>then to core/ in #5536"]
  classDef this fill:#fde68a,stroke:#b45309,stroke-width:2px,color:#1f2937
  class F2,T2,E2 this
Loading

The two large parts are git renames, so history follows them: openai_utils.py becomes core/responses_api_types.py and rollout_correlation.py becomes core/episode.py. The parts that stay behind are recreated at the old paths.

What stays importable from the old paths

flowchart LR
  O["from nemo_gym.openai_utils import X"] --> Q{"X is the client?"}
  Q -->|"yes"| C["Defined there"]
  Q -->|"no: a Gym type, or an openai or pydantic name it imported"| W["Warn once, return X from<br/>nemo_gym.core.responses_api_types"]
  classDef this fill:#fde68a,stroke:#b45309,stroke-width:2px,color:#1f2937
  class W this
Loading
  • Every name openai_utils.py defined or imported from outside the standard library resolves at the old path, including OpenAI SDK types such as Reasoning that code imported through it.
  • rollout_correlation.py and episode_types.py do the same for the names that left them.

How to review

One commit. Its changes:

  1. Renames, with no content changes.

  2. Everything else:

    • The parts that stay are cut back out of the renamed files unchanged: the client into a new openai_utils.py, the middleware into a new rollout_correlation.py. EpisodeId, TaskId, and _CAPTURE_KEY_ATTEMPT move from episode_types.py into core/episode.py.
    • core/episode.py imports four config key names inside maybe_rollout_id_from_run_body, its only user. At module level that import would close a cycle: global_config imports feature modules that import episode_types, which now imports core/episode.py.
    • The moves are recorded in nemo_gym/_moved_paths.py, which gains a small helper for listing many names at once.
    • In-repo references are rewritten by scripts/migrate_imports.py.
    • By hand: the lazy exports in nemo_gym/__init__.py, a lazy-import map in base_responses_api_model.py and its test, a test that read three type aliases through the openai_utils module object, the contract's core layer (now the nemo_gym.core package, with the middleware module moved to the server runtime group), and a redirect in fern/docs.yml for the moved failure_kinds library reference page.
  3. Tests move into tests/unit_tests/core/, split the same way as the code:

    • test_failure_kinds.py moves whole;
    • test_openai_utils.py becomes core/test_responses_api_types.py, and its client tests, with the fixture that pins their retry jitter, stay in test_openai_utils.py;
    • the EpisodeId and TaskId tests move from test_episode_types.py into core/test_episode.py;
    • test_rollout_correlation.py stays: it checks rollout IDs end to end through the servers, and moves with server_runtime/.

    No test is added or dropped: each split file pair holds exactly the tests of the original.

  4. Record the names the old modules still import. rollout_correlation.py still imports ROLLOUT_ID_PATTERN and rollout_context, and episode_types.py still imports EpisodeId and TaskId, so those names resolved at the old paths without an entry. Recording them in MOVED_NAMES lets the import rewriter move in-repo imports to nemo_gym.core.episode and tracks their removal like every other moved name.

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 non-test code outside nemo_gym/ imports from it (servers, benchmarks, scripts, and code samples in docs and skills), 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. The failures are the same on main at 5911d62 on this machine: the benchmark listing test and the Harbor run summary tests, which fail because this machine's hostname resolves to 127.0.1.1, and the Docker PTY tests for a PID file that is not a regular file.
  • The same suite with -W error for every moved path and name so far: same result.
  • lint-imports, with 19 exceptions now: the Responses API types no longer point up the order.
  • gym env test for responses_api_models/openai_model, responses_api_models/vllm_model, responses_api_agents/simple_agent, resources_servers/example_single_tool_call, and environment_servers/harbor.
  • pre-commit run --all-files.

Rollout evidence: N/A. The code moves unchanged.

Compatibility

  • Old paths work until 0.10.0, with one warning each, and give the same objects. Pickles that name the old classes still load.
  • Patches that stop taking effect: rebinding a moved name through its old module, such as nemo_gym.rollout_correlation.ROLLOUT_ID_PATTERN or nemo_gym.openai_utils.RESPONSES_TO_TRAIN, no longer reaches the code that uses it. Patch the new module; mutating the shared object in place still works.
  • from nemo_gym.openai_utils import * now yields only the names openai_utils still defines or imports, without the moved types such as NeMoGymResponse.
  • failure_kinds now logs under nemo_gym.core.failure_kinds.
  • 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 17:41
@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 self-assigned this Oct 28, 2026
@ananthsub ananthsub added the area:core Shared APIs, servers, telemetry, health, and registries label Oct 28, 2026
@ananthsub ananthsub changed the title ananthsub/layout core refactor(core): move shared definitions into nemo_gym/core Oct 28, 2026
@ananthsub
ananthsub force-pushed the ananthsub/layout-core branch from b6ff053 to abef69e Compare October 28, 2026 17:45
@ananthsub
ananthsub force-pushed the ananthsub/layout-core branch from abef69e to dda10ab Compare October 28, 2026 17:47
@ananthsub
ananthsub marked this pull request as ready for review October 28, 2026 17:48
@ananthsub
ananthsub requested a review from yaoyu-33 October 28, 2026 17:48
@ananthsub
ananthsub requested review from a team as code owners October 28, 2026 17:48
@nemo-automation-bot
nemo-automation-bot Bot requested review from a team October 28, 2026 17:50
@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

@svcnvidia-nemo-ci svcnvidia-nemo-ci added feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer labels Oct 28, 2026
@ananthsub
ananthsub force-pushed the ananthsub/layout-core branch from 3a5bb65 to 7a253cf Compare October 28, 2026 19:01

Copy link
Copy Markdown
Contributor

Something went wrong on our side and the automatic retries didn't recover — please try again. (ref: github:c5cd0ad0-d311-11f1-9b8e-8a2ebb025de2)

@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 laying this split out so carefully; the description made a 633-file diff easy to check. We reviewed this PR's own commit (base f99cdf08b1, head 29c432b0a5).

Verdict: SHIP. No blockers or risks. The inline comments are small NOTEs: one missing old-path name, a few stale "lives in openai_utils.py" pointers, two third-party names routed through nemo_gym.core, and one test that does not pin its map entry.

What we checked

  • The 613 rewritten .py files are AST-identical to base apart from imports, and all 1,998 rewritten import bindings resolve to the same objects as before.
  • The three split modules lose and duplicate nothing. The only body change is the declared function-level config import in maybe_rollout_id_from_run_body, and the import cycle it avoids is real.
  • Every moved pydantic model has a byte-identical JSON schema, and objects pickled under the old class paths load at this head.
  • Every base name of openai_utils, rollout_correlation, episode_types and failure_kinds still resolves at its old path to the same object, except TypedDict (inline).
  • The five sandbox runners keep their old-path fallbacks and still import against a tree without nemo_gym.core. Every touched server installs nemo-gym from the same checkout or wheel.
  • lint-imports passes with 19 ignores. The split test files hold the same 373 test IDs. The full unit suite shows no failures caused by this PR, including with moved-path DeprecationWarnings turned into errors.
  • CI: the red Unit tests / Test is 11 Harbor tests hitting Docker Hub "Too Many Requests" for ubuntu:24.04. The kilocode conformance probe fails the same way on #5189, #5195 and #5206. Neither comes from this PR.

PR description

  • [PROCESS] #5166 asks each split PR to list the patches that stop taking effect, and #5195 has a "Which patches still work" section. This PR splits three modules but lists none. Worth adding:

    • Rebinding a moved name through its old module no longer reaches the code that uses it, e.g. nemo_gym.rollout_correlation.ROLLOUT_ID_PATTERN or nemo_gym.openai_utils.RESPONSES_TO_TRAIN. Mutating the shared object in place still works.
    • from nemo_gym.openai_utils import * now yields 37 names instead of 290, without NeMoGymResponse.
    • The failure_kinds logger is now named nemo_gym.core.failure_kinds.

    We found no user of any of these in Gym or in NeMo RL main.

Stack-wide, not for this PR

  • The star-import shrinks because moved_names_getattr (#5167) defines no __dir__ or __all__. Adding them there would let star-imports reach __getattr__ and warn.
  • No test pins the _LAZY_EXPORTS targets in nemo_gym/__init__.py to the module that defines each name: a stale entry still passes, because the old path serves the same object. A check that each name is in vars() of the module it names would cover it, in whichever PR next edits that map.
  • migrate_imports rewrites only whole-module paths in text. Later split PRs will leave file-path mentions like the ones flagged here, so a grep for the old file name is worth a step in each.

Comment thread nemo_gym/_moved_paths.py Resolved
Comment thread nemo_gym/core/responses_api_types.py Resolved
Comment thread nemo_gym/openai_utils.py Resolved
Comment thread nemo_gym/_moved_paths.py Resolved
yaoyu-33
yaoyu-33 previously approved these changes Oct 30, 2026
Rename openai_utils.py to core/responses_api_types.py,
rollout_correlation.py to core/episode.py, and failure_kinds.py into
core/, without changing their contents.

Move back out of the renamed files, unchanged, what does not belong in
core: the OpenAI client into a new openai_utils.py, and the rollout
prefix middleware into a new rollout_correlation.py. Move EpisodeId,
TaskId, and _CAPTURE_KEY_ATTEMPT from episode_types.py into
core/episode.py. Each old module imports back what it uses and serves
the rest through __getattr__ with a deprecation warning, including the
openai and pydantic names that code imported through openai_utils.

core/episode.py imports four config key names inside
maybe_rollout_id_from_run_body, their only user: at module level the
import would close a cycle, because global_config imports feature
modules that import episode_types.

Record the moves in nemo_gym/_moved_paths.py, which gains a helper for
listing many names at once, and rewrite in-repo references with
scripts/migrate_imports.py. By hand: the lazy exports in
nemo_gym/__init__.py, the lazy-import map in base_responses_api_model.py
and its test, a test that read three type aliases through the
openai_utils module object, and the import-linter contract, whose core
layer is the nemo_gym.core package and whose middleware module joins the
server runtime group; six exceptions this resolves are removed.

Move the tests of the code that moved into nemo_gym/core into a matching
test package. test_failure_kinds.py moves whole. test_openai_utils.py
becomes core/test_responses_api_types.py, and its client tests, with the
fixture that pins their retry jitter, stay in test_openai_utils.py. The
EpisodeId and TaskId tests move from test_episode_types.py into
core/test_episode.py. test_rollout_correlation.py stays: it checks
rollout IDs end to end through the servers, and moves with
server_runtime.

rollout_correlation still imports ROLLOUT_ID_PATTERN and
rollout_context, and episode_types still imports EpisodeId and TaskId,
so the names kept resolving without an entry. Record them in MOVED_NAMES
so the import rewriter moves in-repo imports to nemo_gym.core.episode
and their removal from the old modules is tracked like the other moved
names.

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]>

This branch was previously deployed

1 inactive deployment
public — 2702966a Deployed Oct 30, 2026 by copy-pr-bot[bot] via release / finalize / notify #8680
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.

4 participants