Repository navigation
refactor(models): split model call capture out of the model server base and move the OpenAI client into client/ - #5225
Merged
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. |
ananthsub
marked this pull request as ready for review
October 28, 2026 21:27
35 of 41 tasks
Contributor
ananthsub
force-pushed
the
ananthsub/layout-model-base
branch
from
October 28, 2026 21:56
09667f8 to
e634541
Compare
ananthsub
force-pushed
the
ananthsub/layout-model-base
branch
from
October 28, 2026 22:26
e634541 to
187f38c
Compare
ananthsub
force-pushed
the
ananthsub/layout-model-base
branch
from
October 29, 2026 15:14
bd84c01 to
bea5c9c
Compare
ananthsub
force-pushed
the
ananthsub/layout-model-base
branch
from
October 29, 2026 15:51
bea5c9c to
874d883
Compare
ananthsub
force-pushed
the
ananthsub/layout-model-base
branch
from
October 29, 2026 17:01
874d883 to
3a42360
Compare
yaoyu-33
reviewed
Nov 2, 2026
yaoyu-33
left a comment
Contributor
There was a problem hiding this comment.
Thanks for this split. We reviewed it at 6dff4dd122ae and found nothing blocking; every inline comment is a NOTE.
What we checked
- Every top-level definition from the old
nemo_gym/base_responses_api_model.pylanded in exactly one of the two new modules, AST-identical apart from imports. The only new code is the wrapper__getattr__. SimpleResponsesAPIModelinstalls the same middleware, routes, lifespan and exception handlers, in the same order, before and after. We compared four capture and checkpoint configurations.- Module-level state exists once.
SSE_KEEPALIVEis a single object acrosscore, the capture module,_checkpointand both old paths. - There is no new import cycle, and
lint-importsis clean. ReadingCaptureStoreno longer loads the server base, which roughly halves the import. - Every name the old module served resolves at the old path to the same object, and the in-repo patch targets still reach the code they patch.
- CI is green apart from the non-blocking kilocode conformance probe.
PR description
- [PROCESS] The history note is reversed. git pairs the old file with
models/model_call_capture.py(rename, 51% similarity) and treatsmodels/base_responses_api_model.pyas a new file. GitHub also shows the base as a new 998-line file, so step 1, "Rename only", is not in the diff. After the squash,git log --followon the base stops at this commit, whilemodel_call_capture.pycarries the old file's history;git blame -C -Cfollows the base back. The "What moves" diagram and step 1 also saymodel/formodels/. - [PROCESS] #5166 asks each split PR to list the patch targets that stop taking effect. The Compatibility section covers capture names in one line. Could it list the names, and add two cases it misses? No in-repo patch target is affected.
- Names bound in both modules:
token_capture_config,_SSE_KEEPALIVEanduuid4. A patch through the base module reaches only the base's own use and gives no warning. For example,install_model_call_capturereadstoken_capture_configfrom the capture module, whilesetup_policy_checkpointreads it from the base. - The base module's logger: its name also changes, to
nemo_gym.models.base_responses_api_model.
- Names bound in both modules:
Outside the diff
config_types.py:1028still says the capture middleware inbase_responses_api_model.pystrips the rollout prefix. That middleware is now inmodels/model_call_capture.py.
Across the stack
- #5228 adds the same
"Body": "base_responses_api_agent"entry tonemo_gym.agents, so whatever is decided forBodyhere applies there too. - The legacy-warning path issue at
base_responses_api_model.py:958also affectsmetrics/reward_profile.py(from #5211) and every module that moves later with amoved_attr_getter(__name__, ...)shim (#5229, #5231, #5232). Thenemo_gym/utils/compat.pychange suggested inline fixes all of them.
yaoyu-33
previously approved these changes
Nov 2, 2026
yaoyu-33
left a comment
Contributor
There was a problem hiding this comment.
Approving at 6dff4dd122ae. The team review found no blockers or risks; the remaining inline notes are optional and can be handled here or in a follow-up.
…se and move the OpenAI client into client/ base_responses_api_model.py held both the model server base classes and the middleware that records every model call, along with that middleware's store. The base classes now live in models/base_responses_api_model.py, and the capture middleware and its store move unchanged to models/model_call_capture.py, which gets its own logger. Git pairs the old file with model_call_capture.py, because most of its lines were capture code. The liveness-only SSE frame SSE_KEEPALIVE moves from models/chat_streaming.py to core/responses_api_types.py, because the checkpoint gate and the dispatch both compare against it. models/openai_utils.py moves to client/openai_client.py, because it calls model endpoints over the shared HTTP client and is not part of the model server. It now imports ClientResponseError from aiohttp instead of from the server runtime, which pointed up the layer order. nemo_gym.openai_utils resolves to the new module. nemo_gym.models.openai_utils gets no old-path entry, because no release contained it. The client names are exported from nemo_gym.client, and servers import them from there. The module and name moves are recorded in MOVED_MODULES and MOVED_NAMES. Each moved name routes to the module that defines it, so migrate_imports rewrites old imports to the public nemo_gym.models API. The deprecation warning for a name served by a module that itself moved now names the path the caller imported. In-repo references are rewritten with scripts/migrate_imports.py, and the lazy exports, two capture tests, the docs links and the library reference redirects in fern/docs.yml point at the new modules. The public API of each layout package that exists here is regenerated from what code outside the library imports. Code outside nemo_gym and its tests imports from nemo_gym.<package>, and the library's tests import from the module that defines each name. Signed-off-by: Ananth Subramaniam <[email protected]>
This was referenced Nov 2, 2026
This was referenced Nov 3, 2026
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
Moves
base_responses_api_model.pyintonemo_gym/models/and splits its model call capture into its own module. The file held both the model server base classes and the middleware that records every model call, along with that middleware's store. After this PR, each lives in its own module, andmodels/holds the whole model server.It also moves the OpenAI-compatible client,
models/openai_utils.py, toclient/openai_client.py. The client calls model endpoints over the shared HTTP client inclient/http_client.py, so it belongs with the other clients rather than with the model server. It used to importClientResponseErrorfrom the server runtime, which made the client layer depend on a higher layer. It now imports it fromaiohttpdirectly.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.
What moves
flowchart LR subgraph B["base_responses_api_model.py today"] S["SimpleResponsesAPIModel and config,<br/>request validation and dispatch"] C["Capture middleware, CaptureStore,<br/>SSE reconstruction"] end K["chat_streaming.py:<br/>SSE_KEEPALIVE"] O["models/openai_utils.py:<br/>NeMoGymAsyncOpenAI"] S --> S2["models/base_responses_api_model.py"] C --> C2["models/model_call_capture.py"] K --> K2["core/responses_api_types.py"] O --> O2["client/openai_client.py"] classDef this fill:#fde68a,stroke:#b45309,stroke-width:2px,color:#1f2937 class S2,C2,K2,O2 thisbase_responses_api_model.pywithmodels/model_call_capture.py, because most of the file's lines were capture code.models/base_responses_api_model.pyshows as a new file.git blame -C -Cfollows its lines back to the old file.SSE_KEEPALIVE, the liveness-only SSE frame, moves tocore/as the proposal places it: the checkpoint gate and the dispatch both compare against it.client/openai_client.pyis a git rename ofmodels/openai_utils.py, and its test moves totests/unit_tests/client/test_openai_client.py.NeMoGymAsyncOpenAI,PermanentEndpointError,RATE_LIMIT_ERROR_CODES,RETRY_ERROR_CODESandMAX_NUM_TRIESare exported fromnemo_gym.clientand no longer fromnemo_gym.models.What stays importable from the old paths
nemo_gym.base_responses_api_modelis the same module object asnemo_gym.models.base_responses_api_model.SSE_KEEPALIVEatnemo_gym.chat_streamingandnemo_gym.models.chat_streaming.ModelCallRecord. Their warning names the path the caller imported,nemo_gym.base_responses_api_model, as it did before this PR.moved_attr_getterinnemo_gym/utils/compat.pynow names the old path of a module that itself moved, which also fixes the same message inmetrics/reward_profile.py.nemo_gym.openai_utilsnow resolves tonemo_gym.client.openai_client, with one warning.nemo_gym.models.openai_utilsgets no old-path entry. It was added by refactor(models): move the model clients, converters and token capture into nemo_gym/models #5224 and has not been in a release.How to review
One commit. Its changes:
base_responses_api_model.pybecomesmodels/model_call_capture.pyin git's pairing (see above).models/openai_utils.pybecomesclient/openai_client.py.models/base_responses_api_model.py. The capture code moves unchanged intomodels/model_call_capture.py, which gets its own module logger, and the base module imports back the three names it uses.SSE_KEEPALIVEmoves tocore/responses_api_types.py, andchat_streaming.pygains a__getattr__that serves it.nemo_gym/_moved_paths.py, including the namesbase_responses_api_model.pyimported only for code that moved out. Each name routes to the module that defines it, somigrate_importsrewrites to the publicfrom nemo_gym.models import ....scripts/migrate_imports.py. By hand:nemo_gym/__init__.py;nemo_gym.modelspackage alone);models/openai_utilsreference page;nemo_gym.client;tests/unit_tests/models/.token_id_capture_config.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 code outsidenemo_gym/imports from it (servers and their tests, benchmarks, scripts, and code samples in docs and skills), plus every name it already exported, 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.nemo_gym.modelsalso exports FastAPI'sBody. Servers in 0.7.0 imported it from the server base modules, so code thatmigrate_importsrewrites from those paths needs a public name to point at.Validation
pytest -n 16 tests/unit_tests, also with-W errorfor the oldbase_responses_api_modelandchat_streamingpaths and names.utils/compat.pyand passes with it.lint-imports.pre-commit runon the changed files.Rollout evidence: N/A. The code moves unchanged.
Compatibility
nemo_gym.models.base_responses_api_modeland model call capture undernemo_gym.models.model_call_capture. A logging config set onnemo_gymstill covers both.base_responses_api_modelof a capture name no longer reaches the capture code; patchnemo_gym.models.model_call_capture.token_capture_config,_SSE_KEEPALIVEanduuid4are bound in both modules. A patch reaches only the module it names, so patch the one whose code you are testing.requestorsleepthroughnemo_gym.models.openai_utilsmust namenemo_gym.client.openai_client.python scripts/migrate_imports.py <paths>.Issue
Part of #5166.