Repository navigation
refactor(client): move the HTTP and server clients into nemo_gym/client - #5206
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. |
a4908c6 to
5942e02
Compare
|
Something went wrong on our side and the automatic retries didn't recover — please try again. (ref: |
8209d2a to
cc7e36b
Compare
cc7e36b to
3f42725
Compare
yaoyu-33
left a comment
There was a problem hiding this comment.
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.pyland unchanged inclient/http_client.py,client/server_client.pyandtelemetry/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.profilingis the same module object asnemo_gym.telemetry.profiling. The global aiohttp client is one client whether it is set up or read throughserver_utils,nemo_gym.clientorclient.http_client. lint-importsis KEPT with 17 exceptions. Both forms of the profiling redirect are infern/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): theopenai_modelTestRefusedProviderConnectiontests.Unit tests / Test: the twotest_propagationtests.
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_utilsstill imports, includingServerClientandSESSION_ID_KEY, do not warn untilserver_utilsitself moves. - #5166 asks each split PR to list the names whose patches through
server_utilsstop taking effect. Here that is at leastrequest,get_global_aiohttp_client,get_nemo_gym_fastapi_num_workersandbuild_connection_pool_connector. The Compatibility section could list them. client/__init__.pyis not empty: it holds the lazy public API.http_clienthas no logger (it prints), so onlyServerClientlogs under a new name.- Validation lists
pre-commit runon 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.settingsimport-linter exception, the session-routing CI filter, and the exit-hook registration inserver_utils. - #5215: several agents still import
get_global_config_dict/get_first_server_config_dictfromnemo_gym.server_utils: codex, openclaw, pi, swe_agents, mini_swe_agent, osworld and harbor skillsbench. These imports need rewriting whenserver_utilsmoves. - #5167 / #5189: the string-form patch rewrite in
migrate_imports.pyand the AGENTS.md "defining module" rule; see the inline comment on_moved_paths.py.
|
/ok to test 93aeeb8 |
yaoyu-33
left a comment
There was a problem hiding this comment.
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]>
What and why
Moves the HTTP client and the server client out of
server_utils.pyinto a newnemo_gym/client/package, and startsnemo_gym/telemetry/profiling.py. Every server, agent, and resources server calls other servers through these, andserver_utils.pytoday 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.
Where the package sits
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 onmain; this PR addsprofiling.pyto 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 thisclient/server_client.pyimportsrequestand the client helpers fromclient/http_client.py.server_utils.pyimports back the names it uses itself and serves the rest through__getattr__with a warning.What a patch through
server_utilsstill reachesflowchart 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 thisThis is the one break the tracking issue names. In this repo, the test patches now target the module that looks each name up:
ServerClienttests patchnemo_gym.client.server_client, and tests of the aiohttp client patchnemo_gym.client.http_client.scripts/migrate_imports.pyflags patches through the old module that need a check by hand.How to review
One commit. Its changes:
profiling.pybecomestelemetry/profiling.py, andclient/__init__.pyis added with the package's lazy public API.server_utils.pyunchanged, and the profiling middleware configs are appended totelemetry/profiling.py.nemo_gym/_moved_paths.py: theprofilingmodule, and the names that leftserver_utils, including the ones it still imports for its own use.scripts/migrate_imports.py, and test patches are pointed at the module that looks each name up.nemo_gym/__init__.py; the sandbox HTTP transport, the E2B SDK adapter, and the Terminal Bench 4 smoke script, which reached private client state throughserver_utils; the contract's client and telemetry layers; and a redirect infern/docs.ymlfor the movedprofilinglibrary reference page.sitecustomize.pykeeps the old path on purpose: it runs inside the pinned OpenHands image, which can carry an older nemo-gym.ServerClienttests move out oftest_server_utils.pyintotests/unit_tests/client/, andtest_profiling.pymoves intotests/unit_tests/telemetry/. The server runtime tests stay intest_server_utils.pyand move withserver_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, andgit log --followdoes 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 outsidenemo_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 outsidenemo_gym/and its tests (servers and their tests, benchmarks, scripts, and docs) imports those names fromnemo_gym.<package>, so later moves inside a package leave it alone. Code insidenemo_gym/, and the library's tests undertests/, 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.mdstates the rule.Validation
pytest -n 16 tests/unit_tests, also with-W errorfor every moved path and name so far. The only failures are environment-specific and unrelated to the move: this machine's hostname resolves to127.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 importserver_utils, andServerClient's import of the checkpoint settings is a new exception. It stays through the end of the stack, since_checkpoint/settings.pymoves with the server runtime rather than underconfig/.pre-commit run --all-files.Rollout evidence: N/A. The code moves unchanged.
Compatibility
server_utilsstill imports for its own use, includingServerClientandSESSION_ID_KEY, do not warn untilserver_utilsitself moves;_moved_paths.pygroups them.ServerClientnow logs undernemo_gym.client.server_client. The aiohttp client has no logger.nemo_gym.server_utilsof a name the client code looks up no longer takes effect, as shown above: at leastrequest,get_global_aiohttp_client,get_nemo_gym_fastapi_num_workers, andbuild_connection_pool_connector. Patchnemo_gym.client.http_clientinstead.python scripts/migrate_imports.py <paths>.Issue
Part of #5166.