Skip to content

fix(openai): include cache details in continuous Completions usage - #28801

Open
EazyReal wants to merge 1 commit into
sgl-project:mainfrom
EazyReal:vmax/fix-usage-cached-tokens
Open

EazyReal wants to merge 1 commit into
sgl-project:mainfrom
EazyReal:vmax/fix-usage-cached-tokens

Conversation

@EazyReal

@EazyReal EazyReal commented Jun 20, 2026 •

Copy link
Copy Markdown
Contributor

The /v1/completions streaming handler tracks cached tokens but omits them from continuous_usage_stats chunks. This adds prompt_tokens_details with the per-choice cached count when --enable-cache-report is enabled, including zero. Disabled reporting stays unchanged.

Adds a handler regression test for zero, positive, and disabled-reporting cases. The response/final-stream and Chat zero-value fix is split into #44010; these PRs can merge independently.

Thanks to @rlrs for the earlier investigation and implementation in #20203.

Validation: pre-commit and git diff --check passed. Isolated streaming checks passed for cache counts, reporting flags, repeated chunks, and multiple choices; the same checks reproduce the bug on main. Full registered handler tests were not run locally because PyTorch/FastAPI are unavailable.


CI States

Latest PR Test (Base): ❌ Run #38368450828
Latest PR Test (Extra): ❌ Run #38368450626
Latest PR Test (AMD ROCm 10): ❌ Run #38368450892

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates the UsageProcessor._details_if_cached method to always return PromptTokensDetails even when the cached token count is 0. This change allows clients to distinguish between cache reporting being enabled with zero cached tokens versus cache reporting being disabled. Additionally, a new unit test suite has been added to verify this behavior under different configurations. I have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@EazyReal
EazyReal force-pushed the vmax/fix-usage-cached-tokens branch from d8b13bd to b891fb8 Compare June 30, 2026 08:35
@EazyReal

Copy link
Copy Markdown
Contributor Author

@ispobock @CatherineSue @slin1237 @merrymercy @JustinTong0323 Could I get a quick review and run-ci on this usage-reporting fix? It reports cached_tokens=0 when cache reporting is enabled but no tokens were cached.

@EazyReal

EazyReal commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

@ispobock could you take a look at this usage-reporting fix if you have bandwidth? It reports cached_tokens=0 when cache reporting is enabled but no tokens were cached; a run-ci label would help if it looks OK.

@EazyReal
EazyReal force-pushed the vmax/fix-usage-cached-tokens branch from b891fb8 to ce1ca23 Compare July 7, 2026 18:11
@EazyReal
EazyReal force-pushed the vmax/fix-usage-cached-tokens branch from ce1ca23 to 2e5bf81 Compare August 12, 2026 03:30
@EazyReal

Copy link
Copy Markdown
Contributor Author

@ispobock @JustinTong0323 this is refreshed on current main. Cache reporting is now the sole presence gate across response, final-stream, Chat-continuous, and legacy Completions-continuous paths, including meaningful zero values; focused zero/nonzero/disabled coverage is included. The legacy Completions gap is explicitly credited to #20203/@rlrs. Could you review and add run-ci when convenient?

Keep only the legacy Completions remainder of sgl-project#28801; the response/final-stream and Chat zero-value fix is split into sgl-project#44010. Credit @rlrs for the earlier investigation in sgl-project#20203.
@EazyReal EazyReal changed the title fix(openai): report cached_tokens=0 when cache reporting is enabled fix(openai): include cache details in continuous Completions usage Oct 13, 2026
@EazyReal EazyReal reopened this Oct 13, 2026
@EazyReal
EazyReal force-pushed the vmax/fix-usage-cached-tokens branch from 2e5bf81 to e7b6ff2 Compare October 13, 2026 08:19

This branch has not been deployed

No deployments
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.

1 participant