Repository navigation
fix(capture): record usage for streamed chat without a usage chunk - #5061
Conversation
|
/ok to test 0f3067c |
|
/review |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
SHIP
LGTM — no reliability concerns.
Reviewed all three changed files and traced immediate/delayed streaming dispatch through capture storage and downstream token accounting. The fallback preserves existing usage and leaves client SSE unchanged. The new regression test exercises real dispatch and capture for both usage settings.
Static review only; tests were not executed.
Note: formal approval is not available for this request, so this review is posted as a comment only.
Review generated by codex. This was a full review. Request a full review with /review reset=true.
|
/ok to test 25eb296 |
|
/review |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
SHIP
LGTM — no concerns found.
This follow-up checked changes since the previous clean review. Both production files are unchanged. The expanded regression test adds delayed responses, verifies that a keepalive came first, and retains client-usage and captured-token assertions for both usage settings.
I traced delayed dispatch through capture finalization and storage. Capture reads the request-state usage after the streamed handler completes. One delegated report was unavailable, so I checked its capture-storage topic directly.
Static review only; tests were not executed.
Review generated by codex. This was a findings-only review. Request a full review with /review reset=true.
… no usage chunk A chat client that does not set stream_options.include_usage gets no usage chunk, so the model-call record reconstructed from the stream had no token counts. The dispatch now hands the backend's usage to capture, as the Responses SSE path already does. Signed-off-by: Christian Munley <[email protected]>
25eb296 to
2d7a980
Compare
|
/ok to test 2d7a980 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/42264665410 |
What does this PR do?
Model-call capture now records token usage for streamed Chat Completions calls whose client does not set
stream_options.include_usage.Gym answers a streaming chat request by calling the backend non-streaming and replaying the answer as SSE. A client that asks for no usage chunk gets none, which is correct, but capture rebuilds its record from that same stream, so the record had no token counts. The OpenClaw gateway streams this way. In a SWE-Atlas QA run through NeMo Fabric's OpenClaw adapter, capture recorded 24 and 96 calls with null tokens.
The dispatch now keeps the backend's usage on
request.state, and capture fills it in when the rebuilt response has none. The bytes sent to the client are unchanged.Validation
test_capture_records_usage_the_client_did_not_ask_for: a streamed request with and withoutinclude_usagethrough the real dispatch and capture middleware. Theinclude_usage: falsecase fails onmain.pytest tests/unit_tests/test_chat_completions_streaming.py tests/unit_tests/test_base_responses_api_model.py tests/unit_tests/test_rollout_correlation.py: 147 passed.tests/unit_tests: the same failures with and without this change, all in environment-dependent tests on macOS (OpenSandbox, telemetry extras, launchers). None touch capture.ruff formatandruff checkon the changed files: passed.Compatibility and benchmark impact
Capture records only. Streamed calls that already carry a usage chunk and non-streamed calls are unchanged.
Checklist
nemo_gym/chat_streaming.pyupdated.