Skip to content

fix(responses-streaming): integer usage detail counts on the wire - #3968

Merged
linj-glitch merged 1 commit into
mainfrom
alexandery/streaming-integer-usage-counts
Oct 5, 2026
Merged

linj-glitch merged 1 commit into
mainfrom
alexandery/streaming-integer-usage-counts

Conversation

@alexandery-nvidia

Copy link
Copy Markdown
Contributor

What does this PR do?

Gym keeps an unreported cache or reasoning token breakdown as None internally, to tell "unknown" from "zero". On the wire, the Responses schema types input_tokens_details.cached_tokens and output_tokens_details.reasoning_tokens as integers. A strict streaming client that meets null there fails to parse response.completed, treats the stream as disconnected, and re-sends the whole request: the Codex CLI retried every call five times before giving up on the turn.

synthesize_responses_sse now passes the usage object through _wire_usage, which fills a missing or None detail count with 0 in the synthesized SSE envelope only. The internal response object and the non-streaming path are unchanged.

Issue

No issue filed; the defect was observed as five identical retries of every streaming call from the Codex CLI, each logged by the engine as a complete generation.

Validation

  • tests/unit_tests/test_responses_api_model_streaming.py gains test_unknown_usage_details_are_integers_on_the_wire, which synthesizes the SSE stream for a response whose detail counts are None and asserts the response.completed payload carries integers.
  • Core unit suite on this branch (pytest tests/unit_tests, with the telemetry tests and test_collect_downstream_junit.py excluded for missing local packages): 6229 passed, 27 skipped, 1 failed. The one failure is test_slurm_script.py::test_build_vllm_ray_serve_command_single_node_model_with_space_survives_quoting, which needs a pip that this machine's externally managed Python refuses; it fails identically on main.
  • ruff check and ruff format --check on the changed files: clean.
  • Rollout evidence: this change has served several weeks of GRPO training in a downstream fork with the Codex CLI as the harness; the retries stopped the day it landed.

🤖 Generated with Claude Code

@copy-pr-bot

copy-pr-bot Bot commented Oct 3, 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.

@linj-glitch linj-glitch left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the synthesized SSE usage normalization and the streaming/capture contracts in #3382. No logical issues found. Missing or null detail counts become integers only in the SSE envelope; known counts, totals, extension fields, and the caller's original response remain unchanged. The streaming, base model, and external capture integration suites pass 377 tests on this head with Python 3.13.14 and locked dependencies; full pre-commit checks pass. Additional checks cover missing, empty, null, and known detail values and source immutability. No fixes needed. Approval is for this head; required CI and merge-queue validation still apply.

@linj-glitch
linj-glitch marked this pull request as ready for review October 4, 2026 22:59
@linj-glitch
linj-glitch enabled auto-merge October 4, 2026 22:59
@yaoyu-33 yaoyu-33 added area:core Shared APIs, servers, telemetry, health, and registries bug Something isn't working complexity:low Localized change in one scope with a small, straightforward review surface ready-to-merge PR is approved, current, and waiting for final CI or merge labels Oct 4, 2026
Gym keeps an unreported cache or reasoning token breakdown as None
internally to tell unknown from zero. On the wire the Responses schema types
those counts as integers, and a strict streaming client that meets null
fails to parse response.completed, treats the stream as disconnected, and
re-sends the whole request: the Codex CLI retried every call five times.
The synthesized SSE envelope fills zeros; the internal object is unchanged.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
@linj-glitch
linj-glitch force-pushed the alexandery/streaming-integer-usage-counts branch from 0d39f28 to ac68e3a Compare October 5, 2026 06:24

@linj-glitch linj-glitch left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed after rebasing onto main (1f2446c). The patch is preserved and the branch is linear. All 377 relevant streaming, base-model, and external-capture tests and pre-commit run --all-files passed on this head. The wire envelope supplies integer detail counts without mutating the original internal usage object. No remaining logical issue found in the scoped changes.

@linj-glitch

Copy link
Copy Markdown
Collaborator

/ok to test ac68e3a

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/37273437087

Merged via the queue into main with commit b748ded Oct 5, 2026
43 checks passed
@linj-glitch
linj-glitch deleted the alexandery/streaming-integer-usage-counts branch October 5, 2026 06:51

This branch was previously deployed

1 inactive deployment
public — ac68e3a6 Deployed Oct 5, 2026 by copy-pr-bot[bot] via release / finalize / notify #4253
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core Shared APIs, servers, telemetry, health, and registries bug Something isn't working complexity:low Localized change in one scope with a small, straightforward review surface ready-to-merge PR is approved, current, and waiting for final CI or merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants