fix(llm): parse DeepSeek cache metrics + honest 'n/a' when unreported#95
Merged
Conversation
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.
Deploying with
|
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to the "I do not see cached values" report: the Telegram stats line showed
cache: 0 write / 0 read / 0 totalon 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'sprompt_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 newCacheReportedflag (llm.CallResult→ loop totals →IterationInfo) distinguishes "no data" from "0 tokens", and the stats line now sayscache: n/a (provider reports no cache metrics)instead.Tests
TestParseResponse_DeepSeekCacheMetrics(hit/miss mapping + flag),TestParseResponse_CacheNotReportedTestFormatTelegramStats_CacheNotReported(n/a display, no fake numbers); existing stats test updated withCacheReported: truego test ./internal/llm ./internal/loop ./cmd/odekgreen,golangci-lint0 issues