Skip to content

refactor(observability): consolidate model-call capture into base_responses_api_model - #1993

Merged
bxyu-nvidia merged 1 commit into
feat/model-server-observabilityfrom
ffrujeri/model-server-observability
Jul 10, 2026
Merged

bxyu-nvidia merged 1 commit into
feat/model-server-observabilityfrom
ffrujeri/model-server-observability

Conversation

@ffrujeri

Copy link
Copy Markdown
Contributor

Summary

Merges nemo_gym/model_call_capture.py and nemo_gym/observability.py into nemo_gym/base_responses_api_model.py and deletes both modules. Pure consolidation — the code moved verbatim, no behavior changes.

The model server is where capture lives: SimpleResponsesAPIModel installs the middleware, the middleware writes the store, and the record/aggregation helpers read what the middleware wrote. Splitting that across three modules added indirection without a real seam, so everything now has a single home.

Changes

nemo_gym/base_responses_api_model.py now contains, in reading order:

  1. Model server base classes (SimpleResponsesAPIModel etc.) — unchanged.
  2. Capture configuration + rollout-keyed storage (ModelCallCaptureConfig, CaptureStore).
  3. Observability records (ModelCallRecord, token/cache normalization, read/aggregate helpers).
  4. Capture middleware (SSE terminal-event handling, streamed-response reconstruction, _CaptureMiddleware, install_model_call_capture).
  5. Run-level helpers used by rollout collection (model_call_capture_dirs_from_config, clear_model_call_captures_for_rollouts, merge_model_call_capture_into_record).

Deleted: nemo_gym/model_call_capture.py, nemo_gym/observability.py.

Import sites updated:

  • nemo_gym/rollout_collection.py — imports the run-level helpers from the new home.
  • nemo_gym/server_utils.py — comment pointing at observability.py updated.
  • tests/unit_tests/test_observability.py → renamed to tests/unit_tests/test_base_responses_api_model_capture.py (it tests the capture feature of the merged module; test_base_responses_api_model.py already covers the server classes), all imports and monkeypatch targets rewritten.
  • responses_api_models/openai_model/tests/test_app.py and fern/versions/latest/pages/model-server/model-call-capture.mdx — import paths updated.

One incidental cleanup: dropped from __future__ import annotations (present in the old modules). The repo is Python 3.12+ so it's unnecessary, and PEP 563 string annotations can interact badly with FastAPI's runtime annotation evaluation on the endpoint signatures that now share the module.

Notes for review

  • No circular imports: base_responses_api_model's dependencies (anthropic_converter, openai_utils, server_utils) never import rollout_collection, so rollout collection importing the model-server module is safe.
  • The run-level helpers (section 5) are consumed by rollout collection rather than the model server itself, but they read the store and record shapes defined right above them — keeping them co-located beats scattering them into rollout_collection.py.

Testing

  • Capture, model-base, and rollout-collection suites pass (97 tests).
  • Full core unit suite passes (1175 passed; the 2 test_opensandbox_provider.py failures are pre-existing on the base branch).
  • ruff check and ruff format clean.

@copy-pr-bot

copy-pr-bot Bot commented Jul 10, 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.

@ffrujeri
ffrujeri changed the base branch from main to feat/model-server-observability July 10, 2026 18:08
@github-actions

Copy link
Copy Markdown
Contributor

@bxyu-nvidia
bxyu-nvidia merged commit b0607fa into feat/model-server-observability Jul 10, 2026
19 checks passed
@bxyu-nvidia
bxyu-nvidia deleted the ffrujeri/model-server-observability branch July 10, 2026 18:20
Glorf pushed a commit that referenced this pull request Jul 14, 2026
…ponses_api_model (#1993)

## Summary

Merges `nemo_gym/model_call_capture.py` and `nemo_gym/observability.py`
into `nemo_gym/base_responses_api_model.py` and deletes both modules.
Pure consolidation — the code moved verbatim, no behavior changes.

The model server is where capture lives: `SimpleResponsesAPIModel`
installs the middleware, the middleware writes the store, and the
record/aggregation helpers read what the middleware wrote. Splitting
that across three modules added indirection without a real seam, so
everything now has a single home.

## Changes

**`nemo_gym/base_responses_api_model.py`** now contains, in reading
order:

1. Model server base classes (`SimpleResponsesAPIModel` etc.) —
unchanged.
2. Capture configuration + rollout-keyed storage
(`ModelCallCaptureConfig`, `CaptureStore`).
3. Observability records (`ModelCallRecord`, token/cache normalization,
read/aggregate helpers).
4. Capture middleware (SSE terminal-event handling, streamed-response
reconstruction, `_CaptureMiddleware`, `install_model_call_capture`).
5. Run-level helpers used by rollout collection
(`model_call_capture_dirs_from_config`,
`clear_model_call_captures_for_rollouts`,
`merge_model_call_capture_into_record`).

**Deleted:** `nemo_gym/model_call_capture.py`,
`nemo_gym/observability.py`.

**Import sites updated:**

- `nemo_gym/rollout_collection.py` — imports the run-level helpers from
the new home.
- `nemo_gym/server_utils.py` — comment pointing at `observability.py`
updated.
- `tests/unit_tests/test_observability.py` → renamed to
`tests/unit_tests/test_base_responses_api_model_capture.py` (it tests
the capture feature of the merged module;
`test_base_responses_api_model.py` already covers the server classes),
all imports and `monkeypatch` targets rewritten.
- `responses_api_models/openai_model/tests/test_app.py` and
`fern/versions/latest/pages/model-server/model-call-capture.mdx` —
import paths updated.

One incidental cleanup: dropped `from __future__ import annotations`
(present in the old modules). The repo is Python 3.12+ so it's
unnecessary, and PEP 563 string annotations can interact badly with
FastAPI's runtime annotation evaluation on the endpoint signatures that
now share the module.

## Notes for review

- No circular imports: `base_responses_api_model`'s dependencies
(`anthropic_converter`, `openai_utils`, `server_utils`) never import
`rollout_collection`, so rollout collection importing the model-server
module is safe.
- The run-level helpers (section 5) are consumed by rollout collection
rather than the model server itself, but they read the store and record
shapes defined right above them — keeping them co-located beats
scattering them into `rollout_collection.py`.

## Testing

- Capture, model-base, and rollout-collection suites pass (97 tests).
- Full core unit suite passes (1175 passed; the 2
`test_opensandbox_provider.py` failures are pre-existing on the base
branch).
- `ruff check` and `ruff format` clean.

Signed-off-by: Felipe Vieira Frujeri <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants