Skip to content

refactor(utils): move general helpers into nemo_gym/utils - #5195

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

ananthsub merged 1 commit into
mainfrom
ananthsub/layout-utils

Conversation

@ananthsub

@ananthsub ananthsub commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Moves the general helpers into a new nemo_gym/utils/ package, just above config/. It is the first PR that splits files: the worker-process helpers leave server_utils.py, and did_you_mean leaves cli/utils.py.

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

flowchart LR
  subgraph whole["Whole modules"]
    A["decorators.py"] --> A2["utils/decorators.py"]
    B["path_utils.py"] --> B2["utils/path_utils.py"]
    C["install_lock.py"] --> C2["utils/install_lock.py"]
    D["cli/_compat.py"] --> D2["utils/compat.py"]
    E["cli/_venv_setup.py"] --> E2["utils/venv_setup.py"]
  end
  subgraph split["Split out of a module that stays"]
    F["server_utils.py<br/>worker-process flags and env-var helpers"] --> F2["utils/server_process.py"]
    G["cli/utils.py<br/>did_you_mean"] --> G2["utils/text.py"]
  end
  classDef this fill:#fde68a,stroke:#b45309,stroke-width:2px,color:#1f2937
  class A2,B2,C2,D2,E2,F2,G2 this
Loading

Which patches still work

server_utils.py imports the helpers it calls from utils/server_process.py, so a patch on nemo_gym.server_utils still reaches its own call sites. The server apps now import is_nemo_gym_fastapi_entrypoint from the new module, so a patch on server_utils no longer reaches them.

flowchart LR
  P1["monkeypatch.setattr(server_utils,<br/>'is_nemo_gym_fastapi_worker', ...)"] -->|"still reaches"| C1["server_utils call sites:<br/>connection pool, run_webserver"]
  P2["monkeypatch.setattr(server_utils,<br/>'is_nemo_gym_fastapi_entrypoint', ...)"] -.->|"no longer reaches"| C2["Server app.py:<br/>if is_nemo_gym_fastapi_entrypoint(__file__)"]
  P3["monkeypatch.setattr('nemo_gym.utils.server_process.<br/>is_nemo_gym_fastapi_entrypoint', ...)"] -->|"reaches"| C2
  classDef this fill:#fde68a,stroke:#b45309,stroke-width:2px,color:#1f2937
  class P3 this
Loading

Four server tests made the second kind of patch, and now patch the new module: environment_servers/legacy_agent, single_agent_turn, single_agent_turn_legacy, and resources_servers/proof_jury_judge. The other in-repo patches through server_utils are of names it still calls, and are unchanged.

How to review

One commit. Its changes:

  1. Renames only of the five whole modules, with no content changes.
  2. Everything else:
    • utils/server_process.py and utils/text.py with the split-out code, unchanged;
    • server_utils.py and cli/utils.py import back what they call, and serve the other moved names through __getattr__ with a warning, including NEMO_GYM_CONFIG_DICT_ENV_VAR_NAME, which server_utils.py imported and no longer uses;
    • the moves recorded in nemo_gym/_moved_paths.py, shipping in 0.8.0;
    • in-repo references rewritten by scripts/migrate_imports.py, including the code templates in nemo_gym/environment/scaffold.py and the code samples in the environment tutorials;
    • outside nemo_gym/, imports of names that nemo_gym.utils exports now come from the package: server apps, the scaffold templates, the tutorials, patterns.md, and six unit tests;
    • by hand: the four server tests above, the contract's utils layer (now the nemo_gym.utils package), the resolved import-linter exception for comparison/loading.py, redirects in fern/docs.yml for the moved library reference pages, utils/server_process.py in the session-routing e2e path filter, and the conformance CI selector's entry for the old CLI compatibility helpers, which can no longer match.
  3. Tests of the moved modules move into tests/unit_tests/utils/: test_install_lock.py, and test_cli_compat.py, which checks the old CLI import paths served through utils/compat.py.

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: same result.
  • lint-imports, with 25 exceptions now.
  • gym env test for environment_servers/single_agent_turn, resources_servers/proof_jury_judge, and resources_servers/genrm_eval, whose tests patch the moved helpers.
  • pre-commit run --all-files.

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

Compatibility

  • The old module paths work until 0.10.0 with one warning each, and give the same objects. So do the moved names, with one exception: the six names server_utils still imports for its own use, and did_you_mean in cli/utils, resolve without a warning until those modules stop importing them. _moved_paths.py marks which.
  • A patch of is_nemo_gym_fastapi_entrypoint through nemo_gym.server_utils no longer reaches a server app, and neither does a patch of server_utils.is_nemo_gym_fastapi_worker or server_utils.getenv. Patch nemo_gym.utils.server_process instead.
  • from nemo_gym.server_utils import * no longer brings in the five names its __getattr__ serves.
  • 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 16:54
@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.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added area:core Shared APIs, servers, telemetry, health, and registries feature New capabilities, enhancements, or enablement work labels Oct 28, 2026
@ananthsub ananthsub self-assigned this Oct 28, 2026
@ananthsub ananthsub changed the title ananthsub/layout utils refactor(utils): move general helpers into nemo_gym/utils Oct 28, 2026
@ananthsub
ananthsub force-pushed the ananthsub/layout-utils branch from 6bb867b to e98f164 Compare October 28, 2026 17:41
@ananthsub
ananthsub force-pushed the ananthsub/layout-utils branch from e98f164 to 587b4ca Compare October 28, 2026 17:45
@ananthsub
ananthsub marked this pull request as ready for review October 28, 2026 17:47
@ananthsub
ananthsub requested a review from a team as a code owner October 28, 2026 17:47
@ananthsub
ananthsub requested a review from yaoyu-33 October 28, 2026 17:47
@nemo-automation-bot
nemo-automation-bot Bot requested review from a team October 28, 2026 17:49
@github-actions

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

LGTM — no concerns found.

Reviewed all changed files and directly affected compatibility, worker-startup, CLI setup, artifact-path, scaffold, documentation, and CI-selection paths. The move registry preserves the old import locations, and the extracted process helpers retain their previous implementations.

Static source review only; tests and documentation builds were inspected but 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.

@ananthsub
ananthsub force-pushed the ananthsub/layout-utils branch from 41a4aaf to e4dd47c Compare October 28, 2026 21:23
@ananthsub
ananthsub force-pushed the ananthsub/layout-utils branch from e4dd47c to 9f807a3 Compare October 28, 2026 21:56
@ananthsub
ananthsub force-pushed the ananthsub/layout-utils branch from 9f807a3 to 5d1d59b Compare October 29, 2026 00:54

@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 keeping this one strictly mechanical; it made the move easy to check. We found no blockers or risks, only three small notes inline.

What this PR does. It moves five modules into the new nemo_gym/utils package unchanged. It splits the worker-process env helpers out of server_utils.py into utils/server_process.py, and did_you_mean out of cli/utils.py into utils/text.py. It records the moves in _moved_paths.py and points code outside the library at the lazy nemo_gym.utils API.

What we checked

  • Moves. The five whole-module moves are byte-identical renames, and the code split out of server_utils.py and cli/utils.py is token-identical to the base.
  • Imports. Of the 106 changed Python files, 91 differ only in their imports. The rest are the split itself, the registry, the four hand-edited tests, path strings, and the scaffold templates. Every added import resolves and no new import cycle appears. lint-imports keeps the contract with 25 exceptions, and dropping the comparison.loading -> cli.utils exception is correct.
  • Old paths. All five old module paths give the same module object and warn once, in either import order, and all 12 moved names resolve to the identical objects.
  • Servers. Every touched server installs nemo-gym from the checkout. Tests pass for single_agent_turn, legacy_agent, single_agent_turn_legacy, proof_jury_judge, genrm_eval, partner_if, gdpval and denovo_swe. A two-worker launch of example_session_state_mgmt found its entrypoint. The updated patches in the four server tests reach the apps, because lazy_exports looks the name up on every access.
  • Unit tests. pytest tests/unit_tests -n 8 passed 12,223 tests. Each failure either also fails at the base (optional dependencies missing from the dev venv) or was a timing failure under load that passed when re-run alone. Running the suite with the moved-path DeprecationWarnings turned into errors raised none, which matches the PR's validation.

PR description

  • "How to review" says scripts/migrate_imports.py rewrote the in-repo references. But about 60 files (server apps, scaffold templates, tutorials, patterns.md, six unit tests) now import from the nemo_gym.utils package API, and the script doesn't emit that form. The commit message describes this step and the PR body doesn't; one line there would help reviewers.

For earlier PRs in the stack (not blocking this one)

  • #5167: python -m nemo_gym.cli._venv_setup now fails with AttributeError: 'MovedModuleFinder' object has no attribute 'get_code'; it worked before the move. No in-repo caller uses -m. Delegating get_code to the new module's loader would fix it for every moved module with a __main__ guard.
  • #5167 / #5189: the repo locks pytest 9.0.3. In that version, monkeypatch.setattr on a name served by a module __getattr__ (an old server_utils name, or nemo_gym.utils.<name>) writes the real function into the module on undo. After that, later patches of nemo_gym.utils.server_process.<name> stop showing through. pytest 9.2 fixed this, and no in-repo test triggers it today. Bumping the lock, or documenting "patch the defining module", would cover it.
  • #5167: scripts/migrate_imports.py emits nemo_gym.utils.server_process and nemo_gym.utils.path_utils rather than the nemo_gym.utils package API that server code now uses. So running it on open branches, as the Compatibility section suggests, leaves imports that differ from the repo's.

Outside this PR: environment_servers/swe_together/app.py:829 imports create_nemo_gym_fastapi_app from nemo_gym.server_utils, but nothing defines it (since #4943), so that server's multi-worker branch would fail. This PR only touches the import line above it, so it's worth a separate fix.

Comment thread nemo_gym/_moved_paths.py Resolved
Comment thread nemo_gym/utils/server_process.py Resolved
Comment thread scripts/harness_conformance/ci.py Resolved
yaoyu-33
yaoyu-33 previously approved these changes Oct 29, 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 9155a70. The PR's own patch is unchanged from the commit we reviewed, and the three inline notes are non-blocking.

The Unit tests / Server suite (shard 0) failure is not from this change. Two responses_api_agents/harbor_agent_general docker tests failed because the runner could not find the ubuntu:24.04 image, and that server is not touched here.

@ananthsub

Copy link
Copy Markdown
Contributor Author

On the review's other notes:

yaoyu-33
yaoyu-33 previously approved these changes Oct 29, 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.

Re-approving at f99cdf0. The new push adds the versioned docs redirects, the CI path filter for nemo_gym/utils/server_process.py, and comments in the moved-names table; the rest of the patch is the one we reviewed. The failing checks are the non-blocking harness conformance job.

Rename decorators.py, path_utils.py, install_lock.py, cli/_compat.py,
and cli/_venv_setup.py into the new nemo_gym/utils package without
changing their contents. cli/_compat.py becomes utils/compat.py and
cli/_venv_setup.py becomes utils/venv_setup.py.

Move the worker-process flags and their environment-variable helpers out
of server_utils.py into utils/server_process.py, and did_you_mean out of
cli/utils.py into utils/text.py, unchanged. Both old modules import back
the names they call, so a patch on the old module still reaches its own
call sites, and serve the other moved names through __getattr__ with a
deprecation warning.

Record the moves in nemo_gym/_moved_paths.py and rewrite in-repo
references with scripts/migrate_imports.py, including the code templates
in the environment scaffold and the code samples in the environment
tutorials. By hand: four server tests now patch
is_nemo_gym_fastapi_entrypoint on its new module, which is where their
apps look it up; the import-linter contract's utils layer is the
nemo_gym.utils package, and the exception that did_you_mean resolved is
removed; fern/docs.yml redirects the moved library reference pages.

Move the tests of modules that moved into nemo_gym/utils into a matching
test package: test_install_lock.py, and test_cli_compat.py, which checks
the old CLI import paths served through utils/compat.py.

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 — 66571bc5 Deployed Oct 30, 2026 by copy-pr-bot[bot] via release / finalize / notify #8677
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.

3 participants