Skip to content

server: fix prompt-cache miss on whitespace-only thinking channels - #856

Open
maxness wants to merge 1 commit into
antirez:mainfrom
maxness:fix/cache-miss-thinking-whitespace
Open

server: fix prompt-cache miss on whitespace-only thinking channels#856
maxness wants to merge 1 commit into
antirez:mainfrom
maxness:fix/cache-miss-thinking-whitespace

Conversation

@maxness

@maxness maxness commented Aug 23, 2026

Copy link
Copy Markdown

Summary

Fixes a prompt-cache miss that hit every turn of a DeepSeek thinking-mode conversation when the assistant produced an empty reasoning channel.

Root cause

Thinking-mode clients pad an empty reasoning channel with a single space so the echoed reasoning_content isn't rejected as an empty string. On the next request the conversation is re-rendered as:

 thinking<space> response

but the model actually samples the opening tag immediately followed by the closing tag, with no space between them. That extra space token desyncs the byte-prefix match, so the live KV prefix is invalidated and the server falls back to a full re-prefill on every turn.

Fix

Render a whitespace-only thinking channel back as empty, so the reconstituted prompt matches the clean thinking response boundary the live KV was sampled from. Added a regression test (test_thinking_whitespace_renders_empty).

Also dropped the verbose --trace cache-miss diagnostics block: the trace files it produced weren't enough to diagnose these misses, and the live server warning already reports the relevant numbers.

Testing

  • make ds4-server builds clean.
  • Server unit-test suite passes (incl. the new regression test): ds4-server tests: ok.

DeepSeek thinking-mode clients pad an empty reasoning channel with a
single space so the echo of reasoning_content is not rejected as an
empty string. On replay the prompt is re-rendered as
" thinking<space> response", but the model actually samples the
opening tag immediately followed by the closing one with no space.
That extra space token desyncs the byte-prefix match and invalidates
the whole live KV prefix, forcing a full re-prefill on every turn.

Render a whitespace-only thinking channel back as empty so the
reconstituted prompt matches the clean tag boundary the live KV was
sampled from. Add a regression test.

While here, drop the verbose --trace cache-miss diagnostics block:
the trace files it produced were not enough to diagnose these misses
and the live server warning already reports the relevant numbers.

Also remove the mistaken AGENT.md (superseded by local, gitignored
AGENTS.md) and ignore local agent/KV-investigation/ops cruft.
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