Repository navigation
fix(translation): always emit Responses usage detail objects - #144
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (4)
WalkthroughResponses usage encoders now always emit ChangesResponses usage details
Estimated code review effort: 2 (Simple) | ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Comment |
Signed-off-by: Lin Jia <[email protected]>
f46a043 to
69ab31b
Compare
The published 0.1.0 cannot serve this server's /v1/responses endpoint at all. Its chat->responses translation emits a usage object without the input_tokens_details and output_tokens_details members that the Responses schema marks required, so every response fails NeMoGymResponse validation and the endpoint returns 500. A real eval against integrate.api.nvidia.com failed on every rollout; /v1/chat/completions was unaffected, which is why this only surfaced for Responses-API agents. NVIDIA-NeMo/Switchyard#144 makes both members unconditional. It is merged but unreleased -- PyPI still carries only 0.1.0 -- so this pins the merge commit directly and should move to `>=0.1.1,<0.2.0` as soon as a release ships. Installing from git builds Switchyard's Rust extension through maturin, so this now requires a cargo toolchain on the installing machine. Gym's CI does not provide one, so `gym env test` for this server will not run there until the pin moves to a released wheel. That cost is accepted deliberately: the alternative is shipping a server whose Responses endpoint cannot serve a single request. The uv override that neutralized 0.1.0's stale openai>=2.34.0 floor is dropped with it. Switchyard declares openai>=2.7,<3.0 as of #142, which co-installs with Gym's ceiling directly -- verified by rebuilding the server venv from scratch, which resolves openai 2.7.2 with no override present. Verified end to end from a clean venv: 25 unit tests pass, and a `gym eval run` against a live model returns reward 1.0 rollouts carrying well-formed usage, where the same run previously failed on every rollout. Co-Authored-By: Claude Opus 5 <[email protected]> Signed-off-by: Lin Jia <[email protected]>
The published 0.1.0 cannot serve this server's /v1/responses endpoint at all. Its chat->responses translation emits a usage object without the input_tokens_details and output_tokens_details members that the Responses schema marks required, so every response fails NeMoGymResponse validation and the endpoint returns 500. A real eval against integrate.api.nvidia.com failed on every rollout; /v1/chat/completions was unaffected, which is why this only surfaced for Responses-API agents. NVIDIA-NeMo/Switchyard#144 makes both members unconditional. It is merged but unreleased -- PyPI still carries only 0.1.0 -- so this pins the merge commit directly and should move to `>=0.1.1,<0.2.0` as soon as a release ships. Installing from git builds Switchyard's Rust extension through maturin, so this now requires a cargo toolchain on the installing machine. Gym's CI does not provide one, so `gym env test` for this server will not run there until the pin moves to a released wheel. That cost is accepted deliberately: the alternative is shipping a server whose Responses endpoint cannot serve a single request. The uv override that neutralized 0.1.0's stale openai>=2.34.0 floor is dropped with it. Switchyard declares openai>=2.7,<3.0 as of #142, which co-installs with Gym's ceiling directly -- verified by rebuilding the server venv from scratch, which resolves openai 2.7.2 with no override present. Verified end to end from a clean venv: 25 unit tests pass, and a `gym eval run` against a live model returns reward 1.0 rollouts carrying well-formed usage, where the same run previously failed on every rollout. Co-Authored-By: Claude Opus 5 <[email protected]> Signed-off-by: Lin Jia <[email protected]>
The published 0.1.0 cannot serve this server's /v1/responses endpoint at all. Its chat->responses translation emits a usage object without the input_tokens_details and output_tokens_details members that the Responses schema marks required, so every response fails NeMoGymResponse validation and the endpoint returns 500. A real eval against integrate.api.nvidia.com failed on every rollout; /v1/chat/completions was unaffected, which is why this only surfaced for Responses-API agents. NVIDIA-NeMo/Switchyard#144 makes both members unconditional. It is merged but unreleased -- PyPI still carries only 0.1.0 -- so this pins the merge commit directly and should move to `>=0.1.1,<0.2.0` as soon as a release ships. Installing from git builds Switchyard's Rust extension through maturin, so this now requires a cargo toolchain on the installing machine. Gym's CI does not provide one, so `gym env test` for this server will not run there until the pin moves to a released wheel. That cost is accepted deliberately: the alternative is shipping a server whose Responses endpoint cannot serve a single request. The uv override that neutralized 0.1.0's stale openai>=2.34.0 floor is dropped with it. Switchyard declares openai>=2.7,<3.0 as of #142, which co-installs with Gym's ceiling directly -- verified by rebuilding the server venv from scratch, which resolves openai 2.7.2 with no override present. Verified end to end from a clean venv: 25 unit tests pass, and a `gym eval run` against a live model returns reward 1.0 rollouts carrying well-formed usage, where the same run previously failed on every rollout. Co-Authored-By: Claude Opus 5 <[email protected]> Signed-off-by: Lin Jia <[email protected]>
The published 0.1.0 cannot serve this server's /v1/responses endpoint at all. Its chat->responses translation emits a usage object without the input_tokens_details and output_tokens_details members that the Responses schema marks required, so every response fails NeMoGymResponse validation and the endpoint returns 500. A real eval against integrate.api.nvidia.com failed on every rollout; /v1/chat/completions was unaffected, which is why this only surfaced for Responses-API agents. NVIDIA-NeMo/Switchyard#144 makes both members unconditional. It is merged but unreleased -- PyPI still carries only 0.1.0 -- so this pins the merge commit directly and should move to `>=0.1.1,<0.2.0` as soon as a release ships. Installing from git builds Switchyard's Rust extension through maturin, so this now requires a cargo toolchain on the installing machine. Gym's CI does not provide one, so `gym env test` for this server will not run there until the pin moves to a released wheel. That cost is accepted deliberately: the alternative is shipping a server whose Responses endpoint cannot serve a single request. The uv override that neutralized 0.1.0's stale openai>=2.34.0 floor is dropped with it. Switchyard declares openai>=2.7,<3.0 as of #142, which co-installs with Gym's ceiling directly -- verified by rebuilding the server venv from scratch, which resolves openai 2.7.2 with no override present. Verified end to end from a clean venv: 25 unit tests pass, and a `gym eval run` against a live model returns reward 1.0 rollouts carrying well-formed usage, where the same run previously failed on every rollout. Co-Authored-By: Claude Opus 5 <[email protected]> Signed-off-by: Lin Jia <[email protected]>
…ion provenance (#2141) Part of #2088. This PR now also absorbs #2600 (routing-condition provenance) so the whole feature reviews in one place. Adds `responses_api_models/switchyard_model/`, a model server that routes Gym model calls through a Switchyard proxy, so any benchmark Gym supports can run against a router without harness changes — unlike the per-harness integrations in #2026/#2080, which are right for RL trace capture but not for evaluating the router itself. Gym either hosts the router in-process from a native Switchyard TOML deployment (`deployment=routes.toml`; a bad deployment fails at startup, nothing outlives the process, and multi-worker configs are rejected since each worker would host its own proxy) or attaches to an externally run proxy via `switchyard_base_url`, which does support multiple workers. A caller-supplied `model` is always overridden with the configured route so an agent can't bypass the router, and Gym forwards its rollout-attempt id as the Switchyard session id (`x-switchyard-session-id`) so routing decisions and costs join back to the rollout that produced them. That id only arrives when model-call capture or token capture is enabled, so the server validates the requirement at startup: a warning under the default config, a refusal to start when forwarding was requested explicitly but no capture is on. From #2600: set `condition_dir` and the server records the routing condition the run served under — `switchyard-condition.json` at startup (route, mode, proxy URL, deployment SHA-256 plus an archive with inline `api_key` and all `extra_headers` values redacted, and the proxy's identity: the local wheel version when hosting, a caller-supplied `proxy_provenance` mapping when attaching) and `switchyard-stats.json` at shutdown (per-target requests, errors, tokens, and latency plus classifier-side usage from `/v1/stats`, fetched through Gym's shared async client as the configured caller and hard-capped inside the shutdown window). The snapshot labels its scope, since a hosted proxy's counters cover exactly the run while an attached proxy's aggregate everything it has served. Both writes are best-effort and cannot take down serving. This makes two routed runs comparable and a hosted run reproducible from the archived deployment; the docs page gains a "Compare routing conditions" workflow that aligns rollout rows by task and rollout index, reports rollouts missing a counterpart, and includes the classifier tokens the selected model's usage omits. The only dependency is `nemo-switchyard==0.2.0`, pinned exactly in this server's own pyproject.toml (Gym core never imports Switchyard); 0.2.0 is the floor because it is the first release whose Responses translation passes `NeMoGymResponse` validation (NVIDIA-NeMo/Switchyard#144), and the ceiling because upstream has already removed the Python serve stack this PR originally drove. 47 tests pass with 100% coverage on app.py, including an integration suite that drives the real 0.2.0 wheel with no mocks (chat/responses round trips, route override, stats, provenance files written across a real shutdown), and a live routed rollout ran against this revision with reward 1.0 (results in [this comment](#2141 (comment))). Two reviewer notes. `ModelCallRecord.model_ref` names the Gym model server, not the routed target, so per-call attribution must be read from captured payloads — promoting it to a first-class record field is the follow-up flagged for #2088 and needs a core-schema design pass. And `harbor_agent` overwrites `response["model"]` with the policy model name, so Harbor-run benchmarks report the route name for every call; flagging in case that overwrite is unintentional. --------- Signed-off-by: Lin Jia <[email protected]> Co-authored-by: Claude Opus 5 <[email protected]>
What
encode_responses_usage(buffered) andresponses_usage_value(streaming) emittedinput_tokens_detailsandoutput_tokens_detailsonly when the upstream happened to report acache or reasoning breakdown. Both are now always emitted, defaulting to zero.
Why
Both fields are required by the Responses
usageschema. The OpenAI SDK types them asnon-optional, with non-optional ints inside:
So when an upstream omits the breakdown, Switchyard returns a Responses payload that any
OpenAI-SDK client fails to deserialize:
This is not a hypothetical. Routing
/v1/responsesto an OpenAI-format upstream onintegrate.api.nvidia.comfails for every request, because those models report nocompletion_tokens_details:prompt_tokens_detailscompletion_tokens_detailsmeta/llama-3.3-70b-instruct{cached_tokens: 32}nvidia/nemotron-3-ultra-550b-a55bnvidia/nemotron-3-nano-omni-30b-a3b-reasoningAbsent means the upstream reported no cached or reasoning tokens — that is zero, not unknown — so
defaulting to zero is the accurate encoding rather than a placeholder.
Found while routing NeMo Gym evals through Switchyard:
/v1/chat/completionsworked end-to-endwhile
/v1/responsesreturned 500 on every rollout.How tested
cargo fmt --all --checkcleancargo clippy --workspace --all-targets -- -D warningscleancargo test --workspacegreenuv run ruff check .cleanuv run mypy switchyardclean (160 files)uv run pytest tests/ -m "not integration"green (1944 passed, 12 skipped)integrate.api.nvidia.comusage payloads above through thebindings; both now deserialize into
openai.types.responses.ResponseUsage.Three regression tests added: no-breakdown (buffered), cache-only-still-emits-reasoning
(buffered, guards the partial case), and no-breakdown (streaming).
Notes for reviewers
buffered.rswould have left SSEclients broken, so both are changed together.
response_translation.rscompared the wholeusageobject for achat→responses translation and was updated to include the two now-always-present objects. No
other expectation changed; the decode paths are untouched.
do not mark these objects required.
🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
0, improving compatibility with clients expecting the standard schema.Tests