Skip to content

refactor(client): move the HTTP and server clients into nemo_gym/client - #5206

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

ananthsub merged 1 commit into
mainfrom
ananthsub/layout-client

Conversation

@ananthsub

@ananthsub ananthsub commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Moves the HTTP client and the server client out of server_utils.py into a new nemo_gym/client/ package, and starts nemo_gym/telemetry/profiling.py. Every server, agent, and resources server calls other servers through these, and server_utils.py today mixes them with the server base classes, middleware, Ray setup, and the head server. After this PR, code that only calls servers no longer imports the server runtime.

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

Where the package sits

flowchart TD
  cli["cli/"]
  eval["eval/"]
  environment["environment/"]
  testing["testing/"]
  orchestration["orchestration/"]
  rollouts["rollouts/"]
  data["data/"]
  agents["agents/"]
  model["models/"]
  server_runtime["server_runtime/"]
  artifacts["artifacts/"]
  metrics["metrics/"]
  verification["verification/"]
  trajectory["trajectory/"]
  sandbox["sandbox/"]
  client["client/"]
  telemetry["telemetry/"]
  core["core/"]
  utils["utils/"]
  config["config/"]
  cli --> eval
  cli --> environment
  cli --> orchestration
  eval --> rollouts
  environment --> data
  testing --> rollouts
  orchestration --> data
  rollouts --> data
  rollouts --> agents
  rollouts --> model
  data --> server_runtime
  data --> artifacts
  agents --> server_runtime
  model --> server_runtime
  server_runtime --> metrics
  server_runtime --> verification
  server_runtime --> trajectory
  artifacts --> trajectory
  artifacts --> utils
  metrics --> utils
  verification --> sandbox
  trajectory --> core
  sandbox --> client
  client --> telemetry
  client --> utils
  telemetry --> core
  core --> config
  utils --> config
  classDef this fill:#fde68a,stroke:#b45309,stroke-width:2px,color:#1f2937
  classDef done fill:#d1fae5,stroke:#047857,color:#1f2937
  classDef todo fill:#f3f4f6,stroke:#9ca3af,color:#4b5563
  class client this
  class config,utils,core,telemetry done
  class cli,eval,environment,testing,orchestration,rollouts,data,agents,model,server_runtime,artifacts,metrics,verification,trajectory,sandbox todo
Loading

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. telemetry/ already exists on main; this PR adds profiling.py to it.

What moves

flowchart LR
  subgraph SU["server_utils.py today"]
    H["Global aiohttp client, request,<br/>retries, raise_for_status"]
    SC["ServerClient and server URL helpers"]
    PM["Profiling middleware configs"]
    RT["Server base classes, middleware,<br/>Ray, head server"]
  end
  P["profiling.py"] --> P2["telemetry/profiling.py"]
  PM --> P2
  H --> H2["client/http_client.py"]
  SC --> S2["client/server_client.py"]
  RT --> RT2["server_utils.py<br/>moves to server_runtime/ later"]
  classDef this fill:#fde68a,stroke:#b45309,stroke-width:2px,color:#1f2937
  class P2,H2,S2 this
Loading

client/server_client.py imports request and the client helpers from client/http_client.py. server_utils.py imports back the names it uses itself and serves the rest through __getattr__ with a warning.

What a patch through server_utils still reaches

flowchart LR
  T["monkeypatch.setattr(server_utils, name, fake)"] --> Q{"Who looks the name up?"}
  Q -->|"code still in server_utils"| Y["The patch takes effect"]
  Q -->|"ServerClient or the aiohttp client"| N["No effect: patch<br/>nemo_gym.client.server_client or<br/>nemo_gym.client.http_client instead"]
  classDef this fill:#fde68a,stroke:#b45309,stroke-width:2px,color:#1f2937
  class N this
Loading

This is the one break the tracking issue names. In this repo, the test patches now target the module that looks each name up: ServerClient tests patch nemo_gym.client.server_client, and tests of the aiohttp client patch nemo_gym.client.http_client. scripts/migrate_imports.py flags patches through the old module that need a check by hand.

How to review

One commit. Its changes:

  1. Renames only: profiling.py becomes telemetry/profiling.py, and client/__init__.py is added with the package's lazy public API.
  2. Everything else:
    • The two client modules are cut out of server_utils.py unchanged, and the profiling middleware configs are appended to telemetry/profiling.py.
    • The moves are recorded in nemo_gym/_moved_paths.py: the profiling module, and the names that left server_utils, including the ones it still imports for its own use.
    • In-repo references are rewritten by scripts/migrate_imports.py, and test patches are pointed at the module that looks each name up.
    • By hand: the lazy exports in nemo_gym/__init__.py; the sandbox HTTP transport, the E2B SDK adapter, and the Terminal Bench 4 smoke script, which reached private client state through server_utils; the contract's client and telemetry layers; and a redirect in fern/docs.yml for the moved profiling library reference page.
    • The OpenHands sitecustomize.py keeps the old path on purpose: it runs inside the pinned OpenHands image, which can carry an older nemo-gym.
  3. Tests: the HTTP client and ServerClient tests move out of test_server_utils.py into tests/unit_tests/client/, and test_profiling.py moves into tests/unit_tests/telemetry/. The server runtime tests stay in test_server_utils.py and move with server_runtime/.
  4. More patch targets, found while building later PRs: the AnySWE model URL test, the connection pool tests, the genrm HTTP lifecycle test, and the vLLM generation-cut test patched names where the client code no longer looks them up. The genrm and vLLM tests fail without the fix.

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 moved path and name so far. 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.
  • lint-imports, with 17 exceptions now: the judge and the sandbox providers no longer import server_utils, and ServerClient's import of the checkpoint settings is a new exception. It stays through the end of the stack, since _checkpoint/settings.py moves with the server runtime rather than under config/.
  • pre-commit run --all-files.
  • Server and agent tests run in CI.

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

Compatibility

  • Old paths work until 0.10.0 and give the same objects. Names server_utils still imports for its own use, including ServerClient and SESSION_ID_KEY, do not warn until server_utils itself moves; _moved_paths.py groups them.
  • ServerClient now logs under nemo_gym.client.server_client. The aiohttp client has no logger.
  • A patch through nemo_gym.server_utils of a name the client code looks up no longer takes effect, as shown above: at least request, get_global_aiohttp_client, get_nemo_gym_fastapi_num_workers, and build_connection_pool_connector. Patch nemo_gym.client.http_client instead.
  • 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 18:31
@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 requested a review from yaoyu-33 October 28, 2026 18:33
@ananthsub ananthsub changed the title ananthsub/layout client refactor(client): move the HTTP and server clients into nemo_gym/client Oct 28, 2026
@ananthsub ananthsub added feature New capabilities, enhancements, or enablement work area:core Shared APIs, servers, telemetry, health, and registries needs-review PR is ready for code review and waiting on a reviewer labels Oct 28, 2026
@ananthsub
ananthsub marked this pull request as ready for review October 28, 2026 18:33
@ananthsub
ananthsub requested review from a team as code owners October 28, 2026 18:33
@nemo-automation-bot
nemo-automation-bot Bot requested review from a team October 28, 2026 18:34
@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Copy link
Copy Markdown
Contributor

Something went wrong on our side and the automatic retries didn't recover — please try again. (ref: github:9f0b78f0-d311-11f1-85af-8ea1cb912f9d)

@ananthsub
ananthsub force-pushed the ananthsub/layout-client branch from 8209d2a to cc7e36b Compare October 28, 2026 21:56
@ananthsub
ananthsub force-pushed the ananthsub/layout-client branch from cc7e36b to 3f42725 Compare October 28, 2026 23:10

@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.

SHIP WITH CARE. The move itself checks out. Two test patch targets turn CI red; each is a one-line fix.

This PR cuts the shared aiohttp client and ServerClient out of server_utils.py into nemo_gym/client/, moves profiling under telemetry/, keeps the old paths working through _moved_paths, and rewrites imports and test patches across the repo.

Checked and clean

  • The 46 definitions cut from server_utils.py land unchanged in client/http_client.py, client/server_client.py and telemetry/profiling.py (AST- and text-identical). All 129 moved tests are present, and no assertion changed.
  • Every rewritten import resolves to the same object through the old and the new path. nemo_gym.profiling is the same module object as nemo_gym.telemetry.profiling. The global aiohttp client is one client whether it is set up or read through server_utils, nemo_gym.client or client.http_client.
  • lint-imports is KEPT with 17 exceptions. Both forms of the profiling redirect are in fern/docs.yml. The in-sandbox runners (harness_agent, AnySWE, CVDP, Exa, AnyTerminal) still fall back to the old paths, checked against bundles from before #5167 up to #5203.

CI. Two failure groups come from this PR and also show up on #5209 and #5210; the inline comments below cover both:

  • Server suite (shard 3): the openai_model TestRefusedProviderConnection tests.
  • Unit tests / Test: the two test_propagation tests.

The other 11 failures in Unit tests / Test are Docker Hub HTTP 429 errors pulling ubuntu:24.04 in the Harbor tests. The kilocode conformance probe fails on #5195 and #5203 too.

PR description. None of these block merge. They are worth correcting because the later PRs reuse this text.

  • "every test patch now targets the module that looks the name up" does not hold yet; see the inline comments.
  • "Old paths work until 0.10.0, with one warning each": the 11 names server_utils still imports, including ServerClient and SESSION_ID_KEY, do not warn until server_utils itself moves.
  • #5166 asks each split PR to list the names whose patches through server_utils stop taking effect. Here that is at least request, get_global_aiohttp_client, get_nemo_gym_fastapi_num_workers and build_connection_pool_connector. The Compatibility section could list them.
  • client/__init__.py is not empty: it holds the lazy public API. http_client has no logger (it prints), so only ServerClient logs under a new name.
  • Validation lists pre-commit run on the changed files. AGENTS.md asks for --all-files.
For later PRs in the stack
  • #5215 / #5300: three things are unchanged at #5300: the client.server_client -> _checkpoint.settings import-linter exception, the session-routing CI filter, and the exit-hook registration in server_utils.
  • #5215: several agents still import get_global_config_dict / get_first_server_config_dict from nemo_gym.server_utils: codex, openclaw, pi, swe_agents, mini_swe_agent, osworld and harbor skillsbench. These imports need rewriting when server_utils moves.
  • #5167 / #5189: the string-form patch rewrite in migrate_imports.py and the AGENTS.md "defining module" rule; see the inline comment on _moved_paths.py.

Comment thread nemo_gym/server_utils.py Resolved
Comment thread nemo_gym/_moved_paths.py Resolved
Comment thread nemo_gym/_moved_paths.py Resolved
Comment thread nemo_gym/client/http_client.py Resolved
Comment thread pyproject.toml Resolved
@copy-pr-bot

copy-pr-bot Bot commented Oct 30, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@yaoyu-33

Copy link
Copy Markdown
Contributor

/ok to test 93aeeb8

yaoyu-33
yaoyu-33 previously approved these changes Oct 30, 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 93aeeb8. That commit retargets the patches behind both red CI groups: the openai_model TestRefusedProviderConnection fixture, and get_nemo_gym_fastapi_num_workers in test_propagation plus its four sibling sites. Locally, these pass on 93aeeb8:

  • the openai_model suite (103 passed)
  • the telemetry and client unit tests, with the telemetry extra installed so test_propagation runs
  • the terminus_2 sandboxed agent tests (70 passed)

The remaining review comments are NOTEs, for you to take here or in a follow-up.

Rename profiling.py into the telemetry package without changing it, and
add the nemo_gym/client package that the next commit fills from
server_utils.py.

Move the global aiohttp client and `request` into
`nemo_gym/client/http_client.py`, `ServerClient` into
`nemo_gym/client/server_client.py`, and the profiling middleware configs
into `nemo_gym/telemetry/profiling.py`.

`nemo_gym.server_utils` keeps importing the names it uses itself and
serves every other moved name through `__getattr__` with a deprecation
warning naming the new path. `nemo_gym.profiling` is recorded in
MOVED_MODULES.

In-repo imports are rewritten with `scripts/migrate_imports.py`. Test
patches now target the module that looks the name up: ServerClient tests
patch `nemo_gym.client.server_client`, aiohttp client tests patch
`nemo_gym.client.http_client`. The sandbox HTTP transport, the E2B SDK
adapter and the Terminal Bench 4 smoke script import the client modules
directly. The OpenHands `sitecustomize.py` keeps the old path, because
the pinned container image can carry an older nemo-gym.

Split the HTTP client and ServerClient tests out of test_server_utils.py
into tests/unit_tests/client/, and move the profiling tests into
tests/unit_tests/telemetry/.

Four tests patched names that the client code no longer looks up where
the patch went:

- the AnySWE model URL test patched trace_context_path_segment through
  server_utils, and the connection pool tests patched
  is_nemo_gym_fastapi_worker there, but apply_rollout_prefix and the
  lazy aiohttp client look both up in nemo_gym.client;
- the genrm HTTP lifecycle test reset the global aiohttp client through
  server_utils, which no longer holds it;
- the vLLM generation-cut test patched request on server_client, but
  the checkpoint requester calls http_client.request.

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]>

This branch was previously deployed

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