Skip to content

refactor(server_runtime): split server_utils into the server runtime package - #5215

Merged
ananthsub merged 1 commit into
mainfrom
ananthsub/layout-server-utils
Nov 2, 2026
Merged

ananthsub merged 1 commit into
mainfrom
ananthsub/layout-server-utils

Conversation

@ananthsub

@ananthsub ananthsub commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Moves server_utils.py into nemo_gym/server_runtime/ as base_server.py and splits it by responsibility. After #5206 took the HTTP and server clients out, it still held the server base classes, Ray setup, the head server, and four pieces of request middleware. Now each lives in its own module, and base_server.py keeps the server base classes and their uvicorn setup, named like base_resources_server.py and base_environment_server.py beside it.

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

What moves

flowchart LR
  subgraph SU["server_utils.py today"]
    B["BaseServer, SimpleServer,<br/>uvicorn configs"]
    R["Ray detection and cluster setup"]
    F["Entrypoint class flags"]
    H["HeadServer"]
    E["Validation error logging"]
    C["Request context isolation"]
    D["Disconnect cancellation"]
    T["Trace context in the URL path"]
  end
  B --> B2["server_runtime/base_server.py"]
  R --> R2["server_runtime/ray_support.py"]
  F --> F2["server_runtime/entrypoint_flags.py"]
  H --> H2["server_runtime/registry_server.py"]
  E --> E2["request_handling/errors.py"]
  C --> C2["request_handling/request_context.py"]
  D --> D2["request_handling/disconnect.py"]
  T --> T2["request_handling/trace_context.py"]
  classDef this fill:#fde68a,stroke:#b45309,stroke-width:2px,color:#1f2937
  class B2,R2,F2,H2,E2,C2,D2,T2 this
Loading

server_utils.py to base_server.py is a git rename, so its history follows it. The modules split out of it are new files.

flowchart TD
  H2["registry_server"] --> B2["base_server"]
  B2 --> R2["ray_support"]
  B2 --> E2["request_handling: errors, request_context,<br/>disconnect, trace_context"]
  R2 --> F2["entrypoint_flags"]
  HC["tasks/harbor/cli"] --> F2
Loading

entrypoint_flags.py is the one module the proposal did not name. Ray support and the Harbor CLI both read literal class flags from an entrypoint's source. Left in base_server.py, those helpers would make Ray support import base_server back.

What stays importable from the old paths

  • nemo_gym.server_utils is the same module object as nemo_gym.server_runtime.base_server.
  • Every name that left it resolves at the old path with one warning: the names split out here, the client names refactor(client): move the HTTP and server clients into nemo_gym/client #5206 moved, and the names server_utils imported only for code that moved out.
  • A patch through server_utils of a name that a split module now looks up has no effect. In this repo the test patches and log captures now target the module that looks each name up.

How to review

One commit. Its changes:

  1. Rename only: server_utils.py becomes server_runtime/base_server.py.
  2. Everything else:
    • The split code is cut out unchanged. The new modules import what they use from base_server.py, and base_server.py imports back the five names it uses.
    • The validation error logging gets its own module logger, so those warnings now log under nemo_gym.server_runtime.request_handling.errors.
    • The moves are recorded in nemo_gym/_moved_paths.py.
    • In-repo references are rewritten by scripts/migrate_imports.py, and test patches and caplog logger names are pointed at the module that looks each name up.
    • The contract's server runtime layer is now the nemo_gym.server_runtime package alone.
    • Code that imported the module under its old name, server_utils, now names it base_server. Where such code read an HTTP client name through it, it now reads the name from nemo_gym.client.http_client, which defines it.
    • The OpenHands capture overlay runs in a runtime whose nemo-gym nv-OpenHands locks, which can predate nemo_gym.client. It imports ServerClient and the HTTP client from nemo_gym.client, and falls back to nemo_gym.server_utils when that package is missing. Before this, the rewritten import raised there and the overlay installed nothing.
  3. Tests: test_server_utils.py becomes tests/unit_tests/server_runtime/test_base_server.py, and test_ray_opt_out.py moves into tests/unit_tests/server_runtime/.

History of split files

The repository squash-merges, so this PR lands as one commit. Whole-module moves still show as renames. A split file does not: its old path stays with less in it, so the new file starts its own history. git blame -C -C <new file> follows the moved lines back to the old file, and git log --follow does not.

Public API

Every layout package that exists after this PR has a lazy public API in its __init__.py: the names non-test code outside nemo_gym/ imports from it (servers, benchmarks, scripts, and code samples in docs and skills), each served from the submodule that defines it on first use. Code outside nemo_gym/ and its tests (servers and their tests, benchmarks, scripts, and docs) imports those names from nemo_gym.<package>, so later moves inside a package leave it alone. Code inside nemo_gym/, and the library's tests under tests/, import from the module that defines each name, so the import-linter contract sees every dependency and a test reads what it patches. A patch target names the module the code under test looks the name up in. AGENTS.md states the rule.

Validation

  • pytest -n 16 tests/unit_tests, also with -W error for every old server_utils path and name. The only failures are environment-specific and unrelated to the move: this machine's hostname resolves to 127.0.1.1, which the sandbox host check refuses (the Harbor run summary tests and the benchmark listing test), and two Docker PTY tests.
  • The OpenHands overlay tests, against the current layout and against a stand-in for a nemo-gym from before 0.8.0, in an interpreter without site-packages.
  • lint-imports.
  • pre-commit run on the changed files.
  • Server and agent tests run in CI.

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

Compatibility

  • Old paths work until 0.10.0, with one warning each, and give the same objects.
  • Logger names follow the module path: the base server module logs under nemo_gym.server_runtime.base_server, and the head server, Ray support, and request handling under their own modules. A logging config set on nemo_gym still covers them.
  • A patch through nemo_gym.server_utils of a name that moved to a split module no longer takes effect.
  • 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 19:25
@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 feature New capabilities, enhancements, or enablement work area:core Shared APIs, servers, telemetry, health, and registries labels Oct 28, 2026
@ananthsub ananthsub changed the title ananthsub/layout server utils refactor(server_runtime): split server_utils into the server runtime package Oct 28, 2026
@ananthsub ananthsub added the needs-review PR is ready for code review and waiting on a reviewer label Oct 28, 2026
@ananthsub
ananthsub requested a review from yaoyu-33 October 28, 2026 19:28
@ananthsub
ananthsub marked this pull request as ready for review October 28, 2026 19:28
@ananthsub
ananthsub requested a review from a team as a code owner October 28, 2026 19:28
@nemo-automation-bot
nemo-automation-bot Bot requested review from a team October 28, 2026 19:28
@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

@ananthsub
ananthsub force-pushed the ananthsub/layout-server-utils branch from 9e993d2 to 4f1e4c0 Compare October 28, 2026 22:26
@ananthsub
ananthsub force-pushed the ananthsub/layout-server-utils branch from 4f1e4c0 to 5a29873 Compare October 28, 2026 23:10
@ananthsub
ananthsub force-pushed the ananthsub/layout-server-utils branch from 5a29873 to db0b04d Compare October 29, 2026 00:55
@ananthsub
ananthsub force-pushed the ananthsub/layout-server-utils branch from db0b04d to 43e50d7 Compare October 29, 2026 14:04
…package

Move nemo_gym/server_utils.py to nemo_gym/server_runtime/base_server.py.
It keeps the server base classes, BaseServer and SimpleServer, and their
uvicorn setup, next to base_resources_server.py and
base_environment_server.py. The rest moves out unchanged:

- Ray detection and cluster setup to server_runtime/ray_support.py;
- the head server to server_runtime/registry_server.py;
- request validation errors, request context isolation, disconnect
  cancellation and trace context middleware to
  server_runtime/request_handling/;
- the two helpers that read literal class flags from an entrypoint's
  source to server_runtime/entrypoint_flags.py, which both Ray support
  and the Harbor CLI use, so Ray support does not import base_server
  back.

Record the module move in MOVED_MODULES and the split names in
MOVED_NAMES, including the names server_utils imported only for code
that moved out. Rewrite in-repo references with
scripts/migrate_imports.py, point test patches and log captures at the
module that now looks each name up, and make the contract's server
runtime layer the nemo_gym.server_runtime package alone.

Regenerate the public API of each layout package that exists here from
what non-test code outside nemo_gym imports. Code outside nemo_gym and
its tests imports from nemo_gym.<package>; the library's tests import
from the module that defines each name.

Signed-off-by: Ananth Subramaniam <[email protected]>

This branch was previously deployed

1 inactive deployment
public — 51272b19 Deployed Nov 2, 2026 by copy-pr-bot[bot] via release / finalize / notify #9240
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 needs-review PR is ready for code review and waiting on a reviewer sla:review-overdue Review response is over the one-business-day SLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant