Foundry Toolkit Copilot model provider drops token usage and always reports zero context tokens
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 48/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- github, javascript, vscode
调研方向
The report identifies provideTokenCount() and provideLanguageModelResponse in the bundled dist/extension.js, and mentions convertOpenAIChunkToChatChunk as the usage conversion point. Start by locating these in the unminified extension source and tracing how response chunks reach Copilot. Done means actual input, output, and cached token usage is forwarded and token counting no longer always returns zero; the issue names no tests to run.
由索引模型根据 Issue 内容生成。
描述
Title: Foundry Toolkit Copilot model provider drops token usage and always reports zero context tokens
Environment
- VS Code: 1.142.0
- Integrated Copilot extension: 0.70.0
- Microsoft Foundry Toolkit: 1.6.19
- OS: Windows x64
- Model: Azure Foundry deployment
gpt-5.6-sol - Integration: Foundry Toolkit language model provider in VS Code Copilot Chat
Problem
When using an Azure Foundry model through Foundry Toolkit in GitHub Copilot Chat, token usage is not reported correctly.
Observed behavior:
- Context window indicator always displays
0 / 1M tokens. - Agent Debug Logs report 0 input and output tokens.
- Copilot
/usagereports AI Units but no Azure API token usage. - OpenTelemetry file export is enabled, but no chat token usage metrics are recorded.
Azure Foundry itself processes and bills the model requests normally. A separate direct API test confirms that the service returns valid usage information, including prompt_tokens, completion_tokens, and total_tokens.
Root cause identified through local extension analysis
1. Token counting always returns zero
In the installed Foundry Toolkit bundle:
dist/extension.js, around line 2520:
async provideTokenCount(i,a,o){return 0}
This explains why the Copilot context window indicator always displays zero.
2. API usage is not forwarded to Copilot
The internal response conversion handles the API usage information:
convertOpenAIChunkToChatChunk, around line 4988.
However, the language model provider implementation:
provideLanguageModelResponse, around line 2517
appears to forward text and tool-call content without forwarding the token usage data.
In the integrated Copilot extension, around line 7013, the consumer expects usage information as a LanguageModelDataPart. When it is missing, input, output, and cache token counts are set to zero.
These findings are based on inspection of the installed, bundled JavaScript code and have not been independently validated against the unminified source.
Expected behavior
- Forward actual API input, output, and cached token usage to VS Code Copilot.
- Implement meaningful token counting instead of returning zero.
- Make token usage available to the Agent Debug Logs and supported telemetry consumers.
- Allow developers using Azure Foundry BYOK deployments to monitor token consumption per model request.
Additional observation
OpenTelemetry file export works and produces telemetry data, but the inspected file contains no model-request token usage metrics. The missing model-turn spans may require separate investigation.
Impact
Without reliable token reporting, developers cannot monitor or optimize API token consumption within Copilot Chat.
In our environment, 296 Azure requests consumed approximately 3.28 million tokens, while the Copilot UI continued displaying zero usage.
Request
Could you confirm whether forwarding token usage from Foundry Toolkit language model providers to Copilot is currently supported?
If supported, please investigate the missing usage forwarding and the provideTokenCount() implementation.
If not yet supported, please consider implementing it so that users of Azure Foundry BYOK models can monitor their actual token consumption.
- 主要语言
- JavaScript
- 星标
- 2.1k
- 派生
- 260
- 平均合并
- 3 小时 22 分钟
- 30 天内合并 PR
- 42
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
microsoft/foundry-dev-tools 的其他 Issue
-
Foundry Toolkit: GPT-6 luna tool calls fail in VS Code Chat because Chat Completions is used with reasoning可能已有人在做 @a1exwang 于 1 天前认领。 未关闭needs attention
难度 3/5 1-2 天 新手友好度 70/100
microsoft/foundry-dev-tools#924 · 3 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
error while deploying model可能已有人在做 @JerryYangKai 于 8 天前认领。 未关闭investigating
难度 4/5 3-5 天 新手友好度 35/100
microsoft/foundry-dev-tools#899 · 2 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Unable to use the account even when I am logged in!可能已有人在做 @JerryYangKai 于 8 天前认领。 未关闭investigating
难度 4/5 3-5 天 新手友好度 35/100
microsoft/foundry-dev-tools#896 · 2 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
VS Code Web Shows "Source Code Is Not Trusted" Prompt from Foundry Toolkit Across All Solution Accelerators可能已有人在做 @MuyangAmigo 于 8 天前认领。 未关闭needs attention
难度 4/5 3-5 天 新手友好度 45/100
microsoft/foundry-dev-tools#895 · 3 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Failed to load Prompt Agents for project banula-foundry-002可能已有人在做 @JerryYangKai 于 8 天前认领。 未关闭as designed
难度 2/5 1-3 小时 新手友好度 35/100
microsoft/foundry-dev-tools#894 · 2 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
查看 microsoft/foundry-dev-tools 的全部 Issue
相似的 Issue
-
bug new-client
难度 1/5 1-3 小时 新手友好度 88/100
NUWCDIVNPT/stig-manager#2285 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 88/100
Fei2411/DeepSeek-Bot#922 · 1 个 reaction ·
-
server errored
难度 2/5 1-3 小时 新手友好度 75/100
OpenTermsArchive/contrib-declarations#4273 ·
维护者通常 1 天内回复
-
needs-area-label
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 2 天内回复
-
serienstream.to未关闭N: AdGuard for Windows P2: High T: Annoyance
难度 2/5 1-3 小时 新手友好度 61/100
AdguardTeam/AdguardFilters#246310 ·
维护者通常 1 天内回复