Skip to content

fix(llm): parse DeepSeek cache metrics + honest 'n/a' when unreported#95

Merged
jkyberneees merged 1 commit into
mainfrom
fix/cache-metrics
Jul 22, 2026
Merged

fix(llm): parse DeepSeek cache metrics + honest 'n/a' when unreported#95
jkyberneees merged 1 commit into
mainfrom
fix/cache-metrics

Conversation

@jkyberneees

Copy link
Copy Markdown
Contributor

Follow-up to the "I do not see cached values" report: the Telegram stats line showed cache: 0 write / 0 read / 0 total on every turn. Investigation found two real gaps (not a display bug — the zeros were truthful but wrong-looking):

1. DeepSeek's native cache fields weren't parsed

The LLM client parsed Anthropic (cache_creation/read_input_tokens) and OpenAI (prompt_tokens_details.cached_tokens) — but not DeepSeek's prompt_cache_hit_tokens / prompt_cache_miss_tokens, which DeepSeek endpoints and gateways return instead of (or alongside) the OpenAI-style details. Mapping: hit → cache read, miss → cache write (DeepSeek caches missed prefixes automatically, so a miss becomes cached content for the next turn). A DeepSeek-backed bot now shows real cache numbers.

2. Fake zeros when the provider reports nothing

Providers that return no cache metrics at all got 0 write / 0 read / 0 total — implying caching ran and missed. A new CacheReported flag (llm.CallResult → loop totals → IterationInfo) distinguishes "no data" from "0 tokens", and the stats line now says cache: n/a (provider reports no cache metrics) instead.

Tests

  • TestParseResponse_DeepSeekCacheMetrics (hit/miss mapping + flag), TestParseResponse_CacheNotReported
  • TestFormatTelegramStats_CacheNotReported (n/a display, no fake numbers); existing stats test updated with CacheReported: true
  • go test ./internal/llm ./internal/loop ./cmd/odek green, golangci-lint 0 issues

The Telegram stats line showed 'cache: 0 write / 0 read / 0 total' on
every turn. Two issues:

1. odek parsed Anthropic (cache_creation/read_input_tokens) and OpenAI
   (prompt_tokens_details.cached_tokens) cache fields, but not
   DeepSeek's native prompt_cache_hit_tokens / prompt_cache_miss_tokens,
   which many DeepSeek endpoints and gateways return INSTEAD of the
   OpenAI-style details. DeepSeek hits now map to cache read, misses to
   cache write (DeepSeek caches missed prefixes automatically).

2. Zeros were displayed even when the provider returned NO cache
   metrics at all, falsely implying caching ran and missed. A new
   CacheReported flag (llm.CallResult -> loop totals -> IterationInfo)
   distinguishes 'no data' from '0 tokens', and the Telegram stats line
   now shows 'cache: n/a (provider reports no cache metrics)' instead of
   fake zeros.
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
odek da63aff Commit Preview URL

Branch Preview URL
Jul 22 2026, 07:51 PM

@jkyberneees
jkyberneees merged commit b35af71 into main Jul 22, 2026
8 checks passed
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.

1 participant