dsh-cache-doctor: Diagnosing the Root Cause of DeepSeek Cache Misses and Quantifying the Loss

Introduction

DeepSeek Harness (dsh) supports plugin-based extensions, allowing agent developers to dynamically assemble system prompts, tool definitions, and conversation history through configuration or plugins. DeepSeek’s prompt caching mechanism caches the prefix portion of a request that matches the previous request, and the input cost for cached hits is only a fraction of the non-cached cost. In normal usage, the Agent resends the entire conversation at every step, and most of the input should hit the cache.

However, if even a single piece of content near the beginning of the system prompt changes every time—for example, a plugin writes in the current time, a random number, or a real-time status—everything after that point will fail to hit the cache. Your bill will quietly multiply several times over, and it’s hard to tell who’s responsible. dsh-cache-doctor is a DeepSeek Harness sidebar plugin that helps you figure out why the cache isn’t hitting, identifies which plugin and which section of the system prompt is breaking the cache, and calculates how much extra you’re spending because of it.

What Is This

dsh-cache-doctor is a plugin for DeepSeek Harness, maintained by qinghuidaqzp, categorized under model inference. It does not modify any requests; it only displays cache hit rates, costs, root causes, and the last 7 days of data in the sidebar, helping developers troubleshoot fragments in system prompts or conversation history that break cache hit rates.

Core Features

Cache Statistics & Cost Calculation

The plugin tracks today’s cache hit rate, how much the cache saved you, how much you could have avoided spending, and your total spending for today. Built-in DeepSeek official pricing (verified on api-docs.deepseek.com on 2026-11-19), unit: CNY per million tokens, off-peak hours:

  • deepseek-flash: cached input 0.02, non-cached input 1, output 4
  • deepseek-v4-pro: cached input 0.15, non-cached input 4.5, output 13.5

Weekdays 9–12 and 14–18 (Beijing Time) are peak hours, with prices doubled; statutory holiday workdays are also treated as peak.

Root Cause Identification

The plugin generates a card for each cause that broke the cache, including how many times it occurred, how much extra it cost, and when it last happened. Common causes include:

  • A section of the system prompt changes every time: most likely a plugin is writing volatile content like the current time into the system prompt
  • A section was added/removed mid-conversation: a plugin was enabled or disabled during the session, or a plugin intermittently adds content
  • The tool list changed mid-conversation: an MCP server was toggled, or a plugin dynamically registered tools
  • Previous conversation content was rewritten: a plugin modified history messages before sending
  • Cache expiration: the prompt didn’t change, but DeepSeek has already evicted that cache segment (this happens when there’s a long gap between requests)
  • Context compression: when the conversation is too long, dsh compresses the context; the first request after compression naturally can’t hit the cache

If the root cause is in the system prompt, it will list which section it is, display the previous and current content side by side with changed characters highlighted, and provide suggestions on how to fix it.

Request Visualization

Each model request is represented as a bar: green for hits, red for misses that could have been hits, gray for new content. This gives an intuitive view of which requests didn’t hit the cache as expected.

7-Day Trend

The plugin provides daily hit rates, costs, and avoidable costs for the last 7 days, making it easy to observe cache usage trends.

How It Determines This

The plugin only observes two hooks without modifying any requests:

  • system-prompt/assemble: records which named sections make up each assembled system prompt, e.g., tool:bash, some-plugin:now
  • llm/stream: after each model call completes, reads the request content and usage, including cache hit count

For each request, it decomposes it into “system prompt → tool definitions → individual messages” and compares segment by segment with the previous request in the same conversation, finding the first difference:

  • If it’s only new messages appended at the end, the preceding portion should have all hit; if it didn’t, it’s counted as cache expiration
  • If something changed in the middle, it identifies which section the change falls in and records that section as the root cause

” Avoidable miss” is calculated as follows: if the prefix hadn’t changed, the maximum hit this time would be the full length of the previous request (rounded to DeepSeek’s 64-token cache units); the portion where actual hits fall short of that is avoidable. Remainders under 256 tokens are not counted. The first request in a new session is compared with the system prompt and tool definitions of the previous request for the same model.

Installation & Activation

Requires dsh ≥ 0.2.0, tested on 0.2.2-rc.1.

dsh plugin --profile web add github:qinghuidaqzp/dsh-cache-doctor

After installation, restart dsh and click Cache Doctor in the sidebar onboarding page.

Configuration

- id: cache-doctor
  config:
    peakPricing: true
    minTokens: 256
    prices:                                      # leave empty to use built-in prices
      - match: flash
        label: deepseek-flash
        hit: 0.02
        miss: 1
        output: 4

Configuration options:

Key Default Description
stateFile cache-doctor/stats.json under dsh home directory Where statistics are saved; if empty, stored in memory only
peakPricing true Whether to calculate using peak/off-peak pricing
minTokens 256 Misses below this token count are not counted as “avoidable”
prices [] Custom prices, matched in order by match (regex) against model id; off-peak prices

Use Cases & Caveats

Suitable for use during development or debugging of DeepSeek agents, to troubleshoot fragments in system prompts, tool definitions, or history messages that break cache hit rates. The plugin runs with the current dsh process permissions; it is recommended to review the source code and license before installing.

Plugin limitations include:

  • The “avoidable” count is estimated based on the previous request’s length. DeepSeek’s caching is also best-effort, so this is a close but not exact number
  • Only analyzes model requests within dsh. Portion of traffic using the same API key via other clients is not visible
  • The UI is only displayed in the Web interface (including desktop); dsh headless will still log statistics as usual

Regarding privacy, all data stays on your machine; the plugin does not make network connections. The statistics file stores token counts, monetary amounts, section names, and a small snippet of system prompt text (about 100 characters around the change location) used in root cause cards. It does not store your conversation content.

Tips for Plugin Authors

If you don’t want to be called out by Cache Doctor:

  • Only put static content in system prompt sections (ctx.systemPrompt.section)
  • For volatile content like current time or real-time status, inject it via ctx.systemPrompt.context(): dsh will append it as a message at the end of the conversation, preserving the cache for everything before it
  • Do not add or remove tool definitions mid-conversation

Development

npm install
npm test

test/mockseek.mjs is a local DeepSeek stand-in that simulates prefix caching according to DeepSeek’s rules, no API key required. test/fixtures/clock-breaker.mjs is a plugin that deliberately writes the current time into the system prompt. The end-to-end test runs two rounds of conversation with a real dsh instance, confirming it can identify this plugin, and that no false positives occur after removing it:

DSH_BIN=$(which dsh) node test/integration/run.mjs

Plugin license: MIT.

Summary

dsh-cache-doctor is a practical tool that helps developers quickly identify the root cause of DeepSeek prompt cache misses and quantify the resulting cost impact. Through sidebar visualization, you can intuitively see cache hit rates, root causes, and trends, enabling you to optimize system prompt and conversation history design.

For more details, refer to:
- Plugin directory page: https://www.skillhub.cn/plugins/qinghuidaqzp/dsh-cache-doctor
- GitHub repository: https://github.com/qinghuidaqzp/dsh-cache-doctor

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye