Repository navigation
test(orchestration): enforce the orchestration boundary - #5749
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. |
|
/ok to test 0dfd1ed |
|
/ok to test 86329c8 |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
SHIP WITH CARE
Two RISK findings affect the new guard: generated dependency trees can cause false failures, and whole-module compatibility aliases can bypass detection. One NOTE clarifies the documented self-import exemption.
I inspected both changed files and their affected import, setup and CI paths. One delegated report wasn't delivered, so I covered its import-resolution topic directly. This was a static review; I couldn't execute tests.
Review generated by codex. This was a full review. Request a full review with /review reset=true.
| def _imports() -> dict[tuple[str, str], list[str]]: | ||
| """Every import of orchestration outside it and the CLI entrypoint, as (file, module) to its source lines.""" | ||
| found: dict[tuple[str, str], list[str]] = {} | ||
| for path in sorted(p for root in SCANNED_ROOTS if root.is_dir() for p in root.rglob("*.py")): |
There was a problem hiding this comment.
RISK — Exclude installed dependency trees from the scan.
This traversal treats ignored runtime files as repository source. CVDP's dependency provisioning creates a prefix beneath its agent directory, and the shared installer installs Gym there. The copied orchestration package isn't beneath the exact ORCHESTRATION path, so even its valid internal imports become new violations. A supported CVDP setup can therefore make this test fail without any repository-source change. Per-server .venv trees are scanned too.
Could _imports() enumerate tracked Python files instead, retaining the current scan-root and importer exclusions? The neighboring public-API check already uses tracked files. Add import subprocess and replace the loop header with:
tracked = subprocess.run(
["git", "ls-files", "-z", "--", "*.py"],
cwd=REPO_ROOT,
capture_output=True,
text=True,
check=True,
).stdout.split("\0")
for path in sorted(
REPO_ROOT / name
for name in tracked
if name and any((REPO_ROOT / name).is_relative_to(root) for root in SCANNED_ROOTS)
):This preserves checks of tracked core modules, server tests, benchmarks and scripts while excluding installed copies and downloaded assets. Keep the actual orchestration-tree and CLI-entrypoint exemptions; excluding only hidden directories wouldn't fix CVDP's non-hidden deps prefix.
Proposed acceptance checks: add a Python file importing orchestration beneath an ignored .venv and beneath CVDP's ignored dependency prefix; neither should change the result. Stage the same import in an ordinary scanned script or server test; the first boundary test must report its location. Confirm the real CLI entrypoint remains exempt and removing a listed source import still triggers the stale-entry test. The suggested code needs author verification and execution.
There was a problem hiding this comment.
Fixed in 73eede5. The scan now lists files with git ls-files (tracked, or untracked and not ignored), so a .venv or an installed dependency prefix isn't walked. Added a small test for the ignored-tree case.
|
|
||
|
|
||
| def _is_orchestration(module: str) -> bool: | ||
| return module == "nemo_gym.orchestration" or module.startswith("nemo_gym.orchestration.") |
There was a problem hiding this comment.
RISK — Recognize whole-module compatibility aliases.
A new scanned script containing from nemo_gym.cli_setup_command import run_command produces no violation: neither the base nor its imported name starts with nemo_gym.orchestration. However, the compatibility table maps that module directly to nemo_gym.orchestration.server_venv, and the finder imports that target. Both boundary tests therefore pass despite a new dependency on orchestration. The existing old-path check covers only imports inside the library, not these external scripts or servers.
Could _is_orchestration() resolve MOVED_MODULES aliases before checking the prefix? Add from nemo_gym._moved_paths import MOVED_MODULES, _resolve, then use this replacement:
| return module == "nemo_gym.orchestration" or module.startswith("nemo_gym.orchestration.") | |
| resolved = _resolve(module, MOVED_MODULES) | |
| module = resolved[1] if resolved is not None else module | |
| return module == "nemo_gym.orchestration" or module.startswith("nemo_gym.orchestration.") |
The invariant is that a static import of a compatibility module resolving into orchestration must be rejected outside the existing exemptions. This leaves canonical module keys and current exceptions unchanged; it doesn't import scanned modules or treat compatibility-table strings as import statements.
Proposed acceptance checks: in a scanned script, each of import nemo_gym.cli_setup_command, from nemo_gym.cli_setup_command import run_command, and from nemo_gym import cli_setup_command must be reported. Retain detection of direct, lazy and relative orchestration imports. A non-orchestration alias such as from nemo_gym import config_types must remain unreported by this boundary check, and the current known violations must remain matched. These are source-derived checks, not executed results; verify the suggestion before adopting it.
There was a problem hiding this comment.
Skipping this one. On this branch 3 aliases point into orchestration and nothing scanned uses them, and #5882 retargets all three to server_runtime/supervisor, so none are left once it lands.
| (`nemo_gym/_moved_paths.py`). For a summary of each package, see `fern/versions/latest/pages/api-reference/index.mdx`. | ||
|
|
||
| `nemo_gym.orchestration` is a Gym-aware orchestrator (submit, Slurm/Kubernetes executors, job tracking). It provides no | ||
| core functionality. No module in `nemo_gym/`, and no server, benchmark or script built on it, may import it, except `nemo_gym/cli/main.py`, which wires the |
There was a problem hiding this comment.
NOTE — Suggestion: state the orchestration self-import exemption.
This sentence also prohibits imports within orchestration itself, such as the existing import in api.py. Those imports are valid under the implemented boundary: _imports() explicitly excludes the orchestration tree. Could you make that distinction explicit so contributors aren't directed to move valid internal dependencies?
| core functionality. No module in `nemo_gym/`, and no server, benchmark or script built on it, may import it, except `nemo_gym/cli/main.py`, which wires the | |
| core functionality. No module in `nemo_gym/` outside `nemo_gym/orchestration/`, and no server, benchmark or script built on it, may import it, except `nemo_gym/cli/main.py`, which wires the |
Preserve the CLI-entrypoint exemption and the prohibition on dependencies from outside orchestration. Static acceptance: the revised text should permit orchestration-to-orchestration imports while still prohibiting unlisted imports from core modules, servers, benchmarks and scripts. No test behavior should change.
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/42817519510 |
…tion outside the CLI entrypoint Signed-off-by: Tomasz Grzegorzek <[email protected]>
… and the test message Signed-off-by: Tomasz Grzegorzek <[email protected]>
…ration imports Signed-off-by: Tomasz Grzegorzek <[email protected]>
…asses and can only shrink Signed-off-by: Tomasz Grzegorzek <[email protected]>
Signed-off-by: Tomasz Grzegorzek <[email protected]>
…hestration may import itself The boundary test walked every .py under the scanned roots, including git-ignored installed copies of Gym (a server's .venv, a dependency prefix such as CVDP's) whose orchestration imports are not source violations. It now lists files with git ls-files (tracked, or untracked and not ignored). AGENTS.md says the rule applies outside nemo_gym/orchestration/. Signed-off-by: Tomasz Grzegorzek <[email protected]>
73eede5 to
43e5bf9
Compare
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/42832784162 |
Summary
Adds
tests/unit_tests/test_orchestration_boundary.py, which enforces the orchestration boundary: no module innemo_gym/outsidenemo_gym/orchestration/may importnemo_gym.orchestration, exceptnemo_gym/cli/main.py, which wires the orchestration entrypoint into the CLI.Why
nemo_gym.orchestrationshould only act as a Gym-informed orchestrator. It must not provide core functionality that other packages depend on. In the ideal end state we could delete the orchestration package and the only remaining change would be the wiring of its entrypoint in the Gym CLI. Today, code that does not belong in orchestration keeps landing there because core modules can import it freely, and nothing catches that.The test parses every
nemo_gym/**/*.pyfile withast, so lazy imports inside functions and relative imports are caught, while string tables such as_moved_paths.pyand comments are not. On failure it prints each violation aspath:line: source.No issue linked: this is a small guard test with no behavior change.
Current state
This PR contains only the test. The imports that break the rule today are listed in
KNOWN_VIOLATIONSin the test, so it passes. The test fails on a new violation and on a listed entry that no longer matches an import, so the list can only shrink. Existing violations:Outside
nemo_gym/(servers with their own tests, benchmarks, scripts; the core suite undertests/is not scanned):After merging
main(70 commits later), 7 more importers appeared and are listed too:resources_servers/agentic_if_realworld(benchmark/core.pyandtests/test_driver.py), andorchestration.recoveryimports in the tests ofagentic_turn_simulation,bbq,deepswe_external1,gdp_pdfandharbor_agent_general.Planned moves
Proposed, to be done in follow-up PRs, which remove their entries from
KNOWN_VIOLATIONS. Each violation is code that is core functionality, not orchestration.orchestration/server_supervisor.py(RunHelper,_configured_servers,_resolve_server_dir, ...)server_runtime/supervisor.py, in its own layer above the otherserver_runtimemodules; the two helpers move with itgym env start, in-process), not a scheduler piece. Nothing in orchestration imports itorchestration/server_venv.pyserver_runtime/server_venv.pyuv venvcommands for server dirs; used by the supervisor and, through the public API, by servers and benchmarksorchestration/h2_ping_sidecar/(config.py,launcher.py)server_runtime/h2_ping_sidecar/; only the"sidecar"key-name constant goes toconfig/global_config.pyglobal_configneeds just that string. The schema and launcher are used only by the supervisor, so they stay together andconfig/has no upward importjobs.installed_gym_commitutils/gym_commit.pynemo_gymgym eval status(job-ID lookup:MANIFEST_NAME,SubmissionRecord,local_index_dir)eval_statusstays incli/eval.pyand takes the benchmark artifact directories as input;cli/main.pyresolves a job ID or manifest to them through a helper inorchestration/jobs.py. Later, with #5344: job-ID targets move togym job statuswith a progress optionrecord_failure_kind,DRIVER_FAILURE_ENVeval/recovery/markers.pyorchestration/recovery.py,collect_evidence.pyeval/recovery/planner.py,evidence.py(in progress in #5596)gym eval status
gym eval statusshows rollout progress from files in the run directory (*_batch_status.json, exporter markers) and never contacts a scheduler.gym job status(#5344) shows scheduler state. They share only the job record and<job_dir>/artifacts. Only the job-ID lookup ineval_status(MANIFEST_NAME,SubmissionRecord,local_index_dir) is orchestration code.The progress option would read the status files through the executor, which also works for remote Slurm jobs. Open points:
read_run_filestakes explicit paths while status file names carry a shard stem, and #5344 supports Slurm only.The sidecar config went into orchestration by accident: #5234 moved the whole
h2_ping_sidecar/folder along with the supervisor, which leftconfig/global_config.pyimporting upward.Related: #5344 (
gym job list,status,info) addscli/job.pyandcli/job_render.py, which importnemo_gym.orchestrationand would be new violations of this rule. Its command bodies and renderer belong in orchestration, wired fromcli/main.py. It also overlaps with #5 on resolving a job ID to its run directories.Follow-up PRs move the imported code into the packages that own it and delete the matching
KNOWN_VIOLATIONSentries. An import-linter contract fornemo_gym/can be added once the list is empty.Validation
pytest tests/unit_tests/test_orchestration_boundary.pypasses (2 tests).nemo_gym.orchestrationfails the first test, and a listed entry with no matching import fails the second.KNOWN_VIOLATIONSthe test fails on exactly the violations above.pre-commithooks pass on the committed file.Rollout evidence: N/A, test-only change with no environment or agent behavior change.