Skip to content

test(orchestration): enforce the orchestration boundary - #5749

Merged
prokotg merged 6 commits into
mainfrom
tgrzegorzek/orchestration-boundary-test
Nov 10, 2026
Merged

prokotg merged 6 commits into
mainfrom
tgrzegorzek/orchestration-boundary-test

Conversation

@prokotg

@prokotg prokotg commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds tests/unit_tests/test_orchestration_boundary.py, which enforces the orchestration boundary: no module in nemo_gym/ outside nemo_gym/orchestration/ may import nemo_gym.orchestration, except nemo_gym/cli/main.py, which wires the orchestration entrypoint into the CLI.

Why

nemo_gym.orchestration should 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/**/*.py file with ast, so lazy imports inside functions and relative imports are caught, while string tables such as _moved_paths.py and comments are not. On failure it prints each violation as path: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_VIOLATIONS in 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:

nemo_gym/cli/env.py:79                            orchestration.server_supervisor
nemo_gym/cli/env.py:84                            orchestration.server_venv
nemo_gym/cli/eval.py:126                          orchestration.server_supervisor (RunHelper)
nemo_gym/cli/eval.py:507                          orchestration.recovery
nemo_gym/cli/eval.py:1952                         orchestration.jobs
nemo_gym/cli/utils.py:158                         orchestration.executors.resume_script
nemo_gym/config/global_config.py:72               orchestration.h2_ping_sidecar.config
nemo_gym/environment/benchmark_preparation.py:38  orchestration.jobs (installed_gym_commit)
nemo_gym/environment/in_process.py:59             orchestration.server_supervisor
nemo_gym/eval/rollout_reverification.py:1364      orchestration.recovery

Outside nemo_gym/ (servers with their own tests, benchmarks, scripts; the core suite under tests/ is not scanned):

benchmarks/terminal_bench_science/prepare_codex.py:47
resources_servers/{deepswe,math_with_autograder,physics_judge,terminal_bench_4}/tests/
responses_api_agents/miniswe_sandboxed_agent/tests/test_server.py
responses_api_models/vllm_model/tests/test_runtime_policy.py

After merging main (70 commits later), 7 more importers appeared and are listed too: resources_servers/agentic_if_realworld (benchmark/core.py and tests/test_driver.py), and orchestration.recovery imports in the tests of agentic_turn_simulation, bbq, deepswe_external1, gdp_pdf and harbor_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.

# Code Move to Why
1 orchestration/server_supervisor.py (RunHelper, _configured_servers, _resolve_server_dir, ...) server_runtime/supervisor.py, in its own layer above the other server_runtime modules; the two helpers move with it Launches every server in a run (local gym env start, in-process), not a scheduler piece. Nothing in orchestration imports it
2 orchestration/server_venv.py server_runtime/server_venv.py Builds uv venv commands for server dirs; used by the supervisor and, through the public API, by servers and benchmarks
3 orchestration/h2_ping_sidecar/ (config.py, launcher.py) server_runtime/h2_ping_sidecar/; only the "sidecar" key-name constant goes to config/global_config.py global_config needs just that string. The schema and launcher are used only by the supervisor, so they stay together and config/ has no upward import
4 jobs.installed_gym_commit utils/gym_commit.py Imports nothing from nemo_gym
5 gym eval status (job-ID lookup: MANIFEST_NAME, SubmissionRecord, local_index_dir) Own PR: eval_status stays in cli/eval.py and takes the benchmark artifact directories as input; cli/main.py resolves a job ID or manifest to them through a helper in orchestration/jobs.py. Later, with #5344: job-ID targets move to gym job status with a progress option Only the job-ID lookup is orchestration; the rest reads run-directory files. See gym eval status
6 record_failure_kind, DRIVER_FAILURE_ENV eval/recovery/markers.py Tiny writer used by every CLI command; the chain imports it from below
7 orchestration/recovery.py, collect_evidence.py eval/recovery/planner.py, evidence.py (in progress in #5596) The planner imports only lower layers except the chain markers (moved in #6); orchestration then imports downward

gym eval status

gym eval status shows 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 in eval_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_files takes 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 left config/global_config.py importing upward.

Related: #5344 (gym job list, status, info) adds cli/job.py and cli/job_render.py, which import nemo_gym.orchestration and would be new violations of this rule. Its command bodies and renderer belong in orchestration, wired from cli/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_VIOLATIONS entries. An import-linter contract for nemo_gym/ can be added once the list is empty.

Validation

  • pytest tests/unit_tests/test_orchestration_boundary.py passes (2 tests).
  • Both failure modes checked by hand: an unlisted import of nemo_gym.orchestration fails the first test, and a listed entry with no matching import fails the second.
  • Without KNOWN_VIOLATIONS the test fails on exactly the violations above.
  • pre-commit hooks pass on the committed file.

Rollout evidence: N/A, test-only change with no environment or agent behavior change.

@copy-pr-bot

copy-pr-bot Bot commented Nov 6, 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.

@prokotg

prokotg commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 0dfd1ed

@svcnvidia-nemo-ci svcnvidia-nemo-ci added ci CI, automation, test queue, or workflow infrastructure work area:ci CI workflows, test routing, and repository automation labels Nov 7, 2026
@prokotg
prokotg marked this pull request as ready for review November 9, 2026 20:07
@prokotg

prokotg commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 86329c8

@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 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")):

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.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.")

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.

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:

Suggested change
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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread AGENTS.md Outdated
(`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

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.

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?

Suggested change
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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 73eede5.

@prokotg
prokotg added this pull request to the merge queue Nov 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/42817519510

@prokotg
prokotg removed this pull request from the merge queue due to a manual request Nov 10, 2026
…tion outside the CLI entrypoint

Signed-off-by: Tomasz Grzegorzek <[email protected]>
… and the test message

Signed-off-by: Tomasz Grzegorzek <[email protected]>
…asses and can only shrink

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]>
@github-actions

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/42832784162

Merged via the queue into main with commit 19f0531 Nov 10, 2026
108 of 111 checks passed
@prokotg
prokotg deleted the tgrzegorzek/orchestration-boundary-test branch November 10, 2026 14:37

This branch was previously deployed

1 inactive deployment
public — 43e5bf92 Deployed Nov 10, 2026 by copy-pr-bot[bot] via release / finalize / notify #11422
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ci CI workflows, test routing, and repository automation ci CI, automation, test queue, or workflow infrastructure work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants