Skip to content

refactor: remove path and name couplings before the reorganization - #5169

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

ananthsub merged 1 commit into
mainfrom
ananthsub/layout-prep

Conversation

@ananthsub

@ananthsub ananthsub commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Some code finds other code by module name or file location. A move would break it without any error, so this PR changes it first.

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

The MCP gate recognizes Gym middleware by a marker

harvest_tools refuses to expose a resources server over MCP when the app has middleware that direct MCP dispatch would skip. It recognized Gym's own middleware by dotted names such as nemo_gym.server_utils.ClientDisconnectCancellationMiddleware. After the moves those names change, and every Gym resources server with expose_tools_over_mcp would fail to start.

flowchart TD
  M["Middleware on the app"] --> Q{"skipped_on_direct_mcp_dispatch<br/>set on it?"}
  Q -->|"yes"| S["Skip: Gym middleware"]
  Q -->|"no"| A{"applies_to_mcp_requests?"}
  A -->|"yes"| S2["Skip: it runs on the /mcp request"]
  A -->|"no"| R["Refuse to expose tools over MCP"]
  classDef this fill:#fde68a,stroke:#b45309,stroke-width:2px,color:#1f2937
  class Q this
Loading

Marked: RolloutContextMiddleware, ClientDisconnectCancellationMiddleware, and the add_session_id and exception_handling_middleware functions. Only a class's own marker counts, so a subclass that overrides __call__ is refused, as the name match refused it. A server's own middleware must not set the marker. Starlette's SessionMiddleware is still matched by name, since it is not Gym code.

Other couplings

Coupling Change
cli/setup_command.py ran _venv_setup.py from next to its own file; the two move to different packages finds it with importlib.util.find_spec("nemo_gym.cli._venv_setup"); the script still runs without importing Gym
setuptools ignores a package-data pattern that matches no file. With git metadata, setuptools-scm ships every tracked file anyway, so a stale pattern drops a file only from a build without it, such as a wheel built from an unpacked sdist a test checks every nemo_gym package-data pattern matches a file
The h2 ping sidecar launcher finds the Go source by a relative path a test checks the source is where the launcher looks

The resources/*.py package-data pattern matched no file, and this PR removes it.

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.
  • New tests check that the gate accepts the exception and cancellation middleware, which run_webserver adds after the gate runs, after checking both are on the app. Others check that a marked middleware defined outside Gym is accepted, and that unmarked custom middleware, as a function or a class, and a subclass of a marked class are refused. Removing any one marker fails the MCP tests, and the subclass test fails with the old getattr check.
  • In a rehearsal that moved nemo_gym/token_id_capture/, the package-data test failed on the pattern that still named the old directory.
  • pre-commit run --all-files.

Rollout evidence: N/A. The same middleware passes and fails the MCP gate as before, and gym env start runs the same venv setup script.

Compatibility

No user-visible change. The private constant nemo_gym.mcp_auto_exposure._GYM_MIDDLEWARE_MODULES is removed.

Issue

Part of #5166.

@ananthsub
ananthsub added this pull request to stack #5170 October 28, 2026 00:08
@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 added the area:core Shared APIs, servers, telemetry, health, and registries label Oct 28, 2026
@ananthsub ananthsub self-assigned this Oct 28, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the feature New capabilities, enhancements, or enablement work label Oct 28, 2026
@ananthsub
ananthsub force-pushed the ananthsub/layout-prep branch from 6b26517 to f94bf4e Compare October 28, 2026 14:38
@ananthsub
ananthsub force-pushed the ananthsub/layout-prep branch from f94bf4e to 46a454a Compare October 28, 2026 16:24
@ananthsub
ananthsub force-pushed the ananthsub/layout-prep branch from 46a454a to 6b257d7 Compare October 28, 2026 16:54
@ananthsub
ananthsub force-pushed the ananthsub/layout-prep branch from 6b257d7 to 54b474a Compare October 28, 2026 17:41
@ananthsub
ananthsub force-pushed the ananthsub/layout-prep branch from 54b474a to 6a7b1d7 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 yaoyu-33 October 28, 2026 17:47
@nemo-automation-bot
nemo-automation-bot Bot requested review from a team October 28, 2026 17:48
@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 seven changed files and their directly affected paths, including middleware registration and MCP dispatch, import-surface compatibility, standalone venv setup, and packaging checks. The marker-based gate retains unmarked-custom-middleware rejection, and the script lookup preserves standalone file execution and shell quoting.

Static review only; tests and package builds were 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-prep branch from 511c7b2 to 046a940 Compare October 28, 2026 20:49
@ananthsub
ananthsub force-pushed the ananthsub/layout-prep branch from 046a940 to c2f7c06 Compare October 28, 2026 21:23
@ananthsub
ananthsub force-pushed the ananthsub/layout-prep branch from c2f7c06 to 8386dca Compare October 28, 2026 21:56
@ananthsub
ananthsub force-pushed the ananthsub/layout-prep branch from 8386dca to 39a67e2 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 clearing these out before the moves. Checking a marker instead of the module name is the right fix for the MCP gate, and it follows the existing applies_to_mcp_requests pattern.

What we checked:

  • Before this PR, the module-name rule accepted only two function middleware: add_session_id and exception_handling_middleware. Both now carry the marker, so every app built in the repo passes or fails the gate exactly as before.
  • Removing any one of the four markers fails a test.
  • find_spec("nemo_gym.cli._venv_setup").origin gives the same path as Path(__file__).with_name(...) and does not import the script.
  • That lookup keeps working through #5167's MovedModuleFinder, which preserves origin, and after #5195 moves the script to nemo_gym/utils/venv_setup.py.

Verdict: SHIP. We found no blockers or risks, and left three non-blocking notes inline:

  1. A subclass of a marked middleware class inherits the marker and now passes the gate. The fix is one line, plus a test for class middleware being refused.
  2. test_accepts_every_gym_middleware claims to cover every middleware but leaves out SessionRoutingMiddleware.
  3. The package-data test's comment, and the dead resources/*.py pattern.

PR hygiene: Validation says the failures "match main on the same machine". Could you list which tests failed, and the main SHA you compared against?

CI: We reviewed 3d5f6a06. The current head cb55fece carries the same patch, rebased onto the updated #5168 branch, and its CI is still running. On 3d5f6a06, the red checks were unrelated to this PR:

  • Unit tests / Test and Server suite (shard 0) failed in the harbor tests on Docker Hub pull rate limits (HTTP 429).
  • The kilocode harness-conformance probe is non-blocking.
  • The new tests passed.

Comment thread nemo_gym/mcp_auto_exposure.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 cb55fece. The three inline notes are non-blocking and can be picked up here or in a follow-up.

@ananthsub

Copy link
Copy Markdown
Contributor Author

On PR hygiene: the Validation section now names the failing tests and the main commit, 5911d62, they were compared against. They are 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 tests fail on main.

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 91b3339. The marker is now read from the class's own vars(), so a subclass of Gym middleware is refused, and a test covers it. Unit tests / Test failed in the harbor tests on Docker Hub's rate limit (HTTP 429 for ubuntu:24.04), not on this change.

Some code finds other code by module name or by file location, which
would break silently when modules move.

- mcp_auto_exposure recognized Gym's own middleware by dotted module
  names. Gym middleware that direct MCP dispatch may skip now carries a
  skipped_on_direct_mcp_dispatch marker, so the check survives a move.
- setup_command found _venv_setup.py next to its own file. It now finds
  the script by module name, since the two move to different packages.
- Tests that each nemo_gym package-data pattern still matches a file,
  that the Go sidecar source is where the launcher looks, and that the
  venv setup script is found.

Signed-off-by: Ananth Subramaniam <ansubramania@nvidia.com>

This branch was previously deployed

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