Agent host: BYOK Chat Completions adapter records cached input tokens as zero in Copilot session history
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 62/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- ollama, typescript
- Domain
- api
Research direction
The bug is in the BYOK Chat Completions adapter in the installed agent-host bundle agentHostMain.js, where the Responses-format usage object sets input_tokens_details.cached_tokens to a literal 0. Start by finding where the adapter maps the final usage chunk's prompt_tokens_details.cached_tokens into that object. Done means the provider's cached count is preserved in cacheReadTokens, verified by a regression test with a synthetic final usage chunk that has a nonzero cache count.
Written by the indexing model from the issue text.
Description
Description
On VS Code 1.147.0 (macOS), a custom OpenAI-compatible Chat Completions endpoint reported a cache hit, but Copilot session history recorded cacheReadTokens: 0. The input and output counts matched for the same request:
| Source | Input tokens | Output tokens | Cached input tokens |
|---|---|---|---|
| Endpoint (Ollama) | 39,228 | 144 | 30,592 |
| Copilot session history | 39,228 | 144 | 0 |
Steps to reproduce
- Configure a custom OpenAI-compatible Chat Completions model in VS Code and use it in a Copilot agent-host session.
- Send a streaming request with usage reporting enabled. Use a provider or mock that returns a known nonzero
usage.prompt_tokens_details.cached_tokensvalue in the final usage chunk. - Compare that value with
data.usage.cacheReadTokensin the savedsession.usage_recordfor the same call.
Expected: A provider-reported value of 30592 is saved as cacheReadTokens: 30592.
Actual: The saved value is 0. This is not just a display issue: the zero is present in the session record itself.
Likely fix and regression test
In the installed agent-host bundle (agentHostMain.js), the BYOK adapter constructs a Responses-format usage object. It copies the input and output counts but sets input_tokens_details.cached_tokens to a literal 0.
Please preserve the provider’s cached-token count through that conversion. A regression test using a synthetic final usage chunk with a nonzero cache count would verify the fix without requiring a live provider or relying on a real cache hit.
- Dominant language
- TypeScript
- Stars
- 196k
- Forks
- 43.9k
- Avg merge
- 12h 49m
- Merged PRs (30d)
- 682
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/vscode
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
testplan-item
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
testplan-item
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day
-
testplan-item
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
All issues in microsoft/vscode
Similar issues
-
bug done
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
neavo/LinguaGacha#1124 ·
Maintainers usually reply within 1 day
-
[fullsend] E2E: backstage-microsoft-auth — catalogQuery missing error handler for network errorsPossibly taken @fullsend-ai-coder claimed this today. Opene2e-failure ready-to-code
Difficulty 2/5 Under an hour Newbie friendliness 78/100
redhat-developer/rhdh-plugin-export-overlays#4821 · 1 comment ·
Maintainers usually reply within 1 day
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
brylie/mission-island#225 ·
Maintainers usually reply within 1 day
-
status/need-triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
google-gemini/gemini-cli#30412 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
sagemathinc/sagebrush#1683 ·
Maintainers usually reply within 1 day