Skip to content

fix(llm): map DeepSeek cache miss tokens - #35979

Closed
HOYALIM wants to merge 1 commit into
anomalyco:devfrom
HOYALIM:codex/deepseek-cache-write
Closed

HOYALIM wants to merge 1 commit into
anomalyco:devfrom
HOYALIM:codex/deepseek-cache-write

Conversation

@HOYALIM

@HOYALIM HOYALIM commented Jul 8, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #35974

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

DeepSeek reports cache usage as top-level usage.prompt_cache_hit_tokens and usage.prompt_cache_miss_tokens. The OpenAI-compatible chat parser did not keep those fields, so DeepSeek cache misses always ended up as cacheWriteInputTokens: undefined.

This keeps those usage fields, maps hits to cacheReadInputTokens, maps misses to cacheWriteInputTokens, and computes fresh input tokens after subtracting both buckets. The added fixture covers a 5-token prompt with 3 cache-hit tokens and 2 cache-miss tokens.

How did you verify your code works?

The new test fails on origin/dev: read/write cache fields are missing and nonCachedInputTokens stays at 5.

After the fix:

  • cd packages/llm && bun test --timeout 30000 test/provider/openai-compatible-chat.test.ts test/provider/openai-chat.test.ts
  • bun --cwd packages/llm test
  • bun --cwd packages/llm typecheck
  • bun lint packages/llm/src/protocols/openai-chat.ts packages/llm/test/provider/openai-compatible-chat.test.ts

Screenshots / recordings

N/A, no UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Copilot AI review requested due to automatic review settings July 8, 2026 23:27

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@HOYALIM

HOYALIM commented Jul 13, 2026

Copy link
Copy Markdown
Author

Closing after re-auditing the normalized usage semantics. DeepSeek prompt_cache_miss_tokens means input tokens not served from cache, while OpenCode cacheWriteInputTokens means tokens written to cache and prices them through cache.write. Mapping misses there would remove normal input tokens from cost accounting and can undercount cost. A correct solution needs separate cache-miss accounting rather than overloading cache-write.

@HOYALIM HOYALIM closed this Jul 13, 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.

DeepSeek provider: prompt_cache_miss_tokens not mapped to cache.write

2 participants