Skip to content

Show usage stats in context window for BYOK#315394

Merged
vijayupadya merged 2 commits into
mainfrom
keen-mule
May 8, 2026
Merged

Show usage stats in context window for BYOK#315394
vijayupadya merged 2 commits into
mainfrom
keen-mule

Conversation

@vijayupadya
Copy link
Copy Markdown
Contributor

Fixes #291100

The Context Window widget in chat shows 0% and zero token counts for all BYOK models. The root cause is in ExtensionContributedChatEndpoint.makeChatRequest2 — the success response hardcoded usage to all zeros.

Fix:
Mirror the existing ContextManagement / StatefulMarker pattern by introducing a new CustomDataPartMimeTypes.Usage data part. BYOK providers emit token usage into the response stream as a LanguageModelDataPart, and ExtensionContributedChatEndpoint decodes it into the APIUsage returned to the chat layer.

Copilot AI review requested due to automatic review settings May 8, 2026 22:47
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes missing token/usage reporting for BYOK models in the Chat “Context Window” by propagating APIUsage through the VS Code Language Model streaming channel (as a custom LanguageModelDataPart) and decoding it back into the ChatResponse.usage returned to the chat layer.

Changes:

  • Introduce CustomDataPartMimeTypes.Usage for streaming token usage as a LanguageModelDataPart.
  • Emit usage data parts from BYOK providers (Anthropic/Gemini) and from CopilotLanguageModelWrapper.
  • Decode usage data parts in ExtensionContributedChatEndpoint and use them instead of hardcoded zero usage.
Show a summary per file
File Description
extensions/copilot/src/platform/endpoint/vscode-node/extChatEndpoint.ts Collect Usage data parts from the response stream and populate ChatResponse.usage (fallback remains zeros).
extensions/copilot/src/platform/endpoint/common/endpointTypes.ts Add CustomDataPartMimeTypes.Usage constant.
extensions/copilot/src/extension/conversation/vscode-node/languageModelAccess.ts Have CopilotLanguageModelWrapper return APIUsage and emit it as a Usage LanguageModelDataPart.
extensions/copilot/src/extension/byok/vscode-node/geminiNativeProvider.ts Emit Gemini BYOK usage as a Usage LanguageModelDataPart.
extensions/copilot/src/extension/byok/vscode-node/anthropicProvider.ts Emit Anthropic BYOK usage as a Usage LanguageModelDataPart.

Copilot's findings

  • Files reviewed: 5/5 changed files
  • Comments generated: 4

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 8, 2026

blocks-ci screenshots changed

Replace the contents of test/componentFixtures/blocks-ci-screenshots.md with:

Updated blocks-ci-screenshots.md
<!-- auto-generated by CI — do not edit manually -->

#### editor/codeEditor/CodeEditor/Dark
![screenshot](https://hediet-screenshots.azurewebsites.net/images/67bfb687fd2818bd53771a60660541b9ed6f38b80d37da0aac15d267ecaeacec)

#### editor/codeEditor/CodeEditor/Light
![screenshot](https://hediet-screenshots.azurewebsites.net/images/0469dd8d0a587d94a1eaec514c79917b93b9a38694ef2b767bb1892819ae0a55)

#### editor/inlineChatZoneWidget/InlineChatZoneWidget/Dark
![screenshot](https://hediet-screenshots.azurewebsites.net/images/97162fc53c861ee13dc78a18e41fe3a25a42f62dc52a560510ebf084a418e1c3)

#### editor/inlineChatZoneWidget/InlineChatZoneWidget/Light
![screenshot](https://hediet-screenshots.azurewebsites.net/images/3b7e2eb5cc9ba727e2bc1c5113c3e17d8e9a6ce9a37b77519be3716ceb9a9afa)

#### editor/inlineChatZoneWidget/InlineChatZoneWidgetTerminated/Dark
![screenshot](https://hediet-screenshots.azurewebsites.net/images/97162fc53c861ee13dc78a18e41fe3a25a42f62dc52a560510ebf084a418e1c3)

#### editor/inlineChatZoneWidget/InlineChatZoneWidgetTerminated/Light
![screenshot](https://hediet-screenshots.azurewebsites.net/images/3b7e2eb5cc9ba727e2bc1c5113c3e17d8e9a6ce9a37b77519be3716ceb9a9afa)

@vijayupadya vijayupadya marked this pull request as ready for review May 8, 2026 23:14
@vijayupadya vijayupadya enabled auto-merge (squash) May 8, 2026 23:14
@vijayupadya vijayupadya merged commit 2e3f347 into main May 8, 2026
24 of 25 checks passed
@vijayupadya vijayupadya deleted the keen-mule branch May 8, 2026 23:30
@vs-code-engineering vs-code-engineering Bot added this to the 1.120.0 milestone May 8, 2026
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.

Context Window widget doesn't show usage on BYOK scenarios

3 participants