Repository navigation
refactor(utils): move general helpers into nemo_gym/utils - #5195
Conversation
|
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. |
6bb867b to
e98f164
Compare
e98f164 to
587b4ca
Compare
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
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.
587b4ca to
319e87e
Compare
41a4aaf to
e4dd47c
Compare
e4dd47c to
9f807a3
Compare
9f807a3 to
5d1d59b
Compare
yaoyu-33
left a comment
There was a problem hiding this comment.
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.pyandcli/utils.pyis 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-importskeeps the contract with 25 exceptions, and dropping thecomparison.loading -> cli.utilsexception 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,gdpvalanddenovo_swe. A two-worker launch ofexample_session_state_mgmtfound its entrypoint. The updated patches in the four server tests reach the apps, becauselazy_exportslooks the name up on every access. - Unit tests.
pytest tests/unit_tests -n 8passed 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-pathDeprecationWarnings turned into errors raised none, which matches the PR's validation.
PR description
- "How to review" says
scripts/migrate_imports.pyrewrote the in-repo references. But about 60 files (server apps, scaffold templates, tutorials,patterns.md, six unit tests) now import from thenemo_gym.utilspackage 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_setupnow fails withAttributeError: 'MovedModuleFinder' object has no attribute 'get_code'; it worked before the move. No in-repo caller uses-m. Delegatingget_codeto 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.setattron a name served by a module__getattr__(an oldserver_utilsname, ornemo_gym.utils.<name>) writes the real function into the module on undo. After that, later patches ofnemo_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.pyemitsnemo_gym.utils.server_processandnemo_gym.utils.path_utilsrather than thenemo_gym.utilspackage 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.
yaoyu-33
left a comment
There was a problem hiding this comment.
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.
|
On the review's other notes:
|
yaoyu-33
left a comment
There was a problem hiding this comment.
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]>
What and why
Moves the general helpers into a new
nemo_gym/utils/package, just aboveconfig/. It is the first PR that splits files: the worker-process helpers leaveserver_utils.py, anddid_you_meanleavescli/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.
Where the package sits
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 thisWhich patches still work
server_utils.pyimports the helpers it calls fromutils/server_process.py, so a patch onnemo_gym.server_utilsstill reaches its own call sites. The server apps now importis_nemo_gym_fastapi_entrypointfrom the new module, so a patch onserver_utilsno 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 thisFour 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, andresources_servers/proof_jury_judge. The other in-repo patches throughserver_utilsare of names it still calls, and are unchanged.How to review
One commit. Its changes:
utils/server_process.pyandutils/text.pywith the split-out code, unchanged;server_utils.pyandcli/utils.pyimport back what they call, and serve the other moved names through__getattr__with a warning, includingNEMO_GYM_CONFIG_DICT_ENV_VAR_NAME, whichserver_utils.pyimported and no longer uses;nemo_gym/_moved_paths.py, shipping in 0.8.0;scripts/migrate_imports.py, including the code templates innemo_gym/environment/scaffold.pyand the code samples in the environment tutorials;nemo_gym/, imports of names thatnemo_gym.utilsexports now come from the package: server apps, the scaffold templates, the tutorials,patterns.md, and six unit tests;nemo_gym.utilspackage), the resolved import-linter exception forcomparison/loading.py, redirects infern/docs.ymlfor the moved library reference pages,utils/server_process.pyin the session-routing e2e path filter, and the conformance CI selector's entry for the old CLI compatibility helpers, which can no longer match.tests/unit_tests/utils/:test_install_lock.py, andtest_cli_compat.py, which checks the old CLI import paths served throughutils/compat.py.Validation
pytest -n 16 tests/unit_tests. The failures are the same onmainat 5911d62 on this machine: the benchmark listing test and the Harbor run summary tests, which fail because this machine's hostname resolves to127.0.1.1, and the Docker PTY tests for a PID file that is not a regular file.-W errorfor every moved path and name: same result.lint-imports, with 25 exceptions now.gym env testforenvironment_servers/single_agent_turn,resources_servers/proof_jury_judge, andresources_servers/genrm_eval, whose tests patch the moved helpers.pre-commit run --all-files.Rollout evidence: N/A. The code moves unchanged.
Compatibility
server_utilsstill imports for its own use, anddid_you_meanincli/utils, resolve without a warning until those modules stop importing them._moved_paths.pymarks which.is_nemo_gym_fastapi_entrypointthroughnemo_gym.server_utilsno longer reaches a server app, and neither does a patch ofserver_utils.is_nemo_gym_fastapi_workerorserver_utils.getenv. Patchnemo_gym.utils.server_processinstead.from nemo_gym.server_utils import *no longer brings in the five names its__getattr__serves.python scripts/migrate_imports.py <paths>.Issue
Part of #5166.