Agent host: BYOK Chat Completions adapter records cached input tokens as zero in Copilot session history

Open Beginner friendly
#349,634 0 comments 0 reactions 0 assignees View on GitHub

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
  1. Configure a custom OpenAI-compatible Chat Completions model in VS Code and use it in a Copilot agent-host session.
  2. Send a streaming request with usage reporting enabled. Use a provider or mock that returns a known nonzero usage.prompt_tokens_details.cached_tokens value in the final usage chunk.
  3. Compare that value with data.usage.cacheReadTokens in the saved session.usage_record for 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

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/vscode

All issues in microsoft/vscode

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.