You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
LM Studio + Qwen: prompt prefix is not byte-stable across turns, breaks prefix cache #26750
LM Studio prefix caching requires the tokenized prompt prefix to remain identical across turns. With Qwen / QwQ-family chat templates served via LM Studio's OpenAI-compatible endpoint, two things make the prefix unstable across turns when OpenCode replays the conversation history as-is:
Assistant reasoning content is replayed. Qwen chat templates render historical assistant reasoning (think) blocks differently on later turns once a new user message is appended, so the same historical assistant turn tokenizes differently the next time it appears in the prompt.
Raw role: "tool" messages are tokenized non-deterministically. Qwen-style chat templates render past tool results inconsistently when they sit as standalone role: "tool" messages, but render them stably when they appear as <tool_response>...</tool_response> blocks inside the preceding user/assistant text.
Either behavior breaks LM Studio prefix caching even though the underlying conversation history has not meaningfully changed, so a long context can fully re-tokenize on every turn.
Expected: when OpenCode replays the same conversation history through LM Studio's OpenAI-compatible endpoint with a Qwen-family model, the prompt prefix is byte-stable, so the prefix cache hits on every turn after the first.
Actual: the prefix changes turn-over-turn, causing a large or full prompt-cache miss against LM Studio.
This is provider/model compatibility behavior specific to LM Studio + Qwen-style templates and should not affect Anthropic, OpenAI, or non-Qwen OpenAI-compatible backends.
Plugins
None
OpenCode version
1.14.46
Steps to reproduce
Run a Qwen / QwQ-family model under LM Studio (any model whose chat template uses the Qwen <tool_response> convention).
Configure OpenCode to use LM Studio's OpenAI-compatible endpoint as the provider.
Have at least one tool-using turn in the session, then send another user message so the previous tool result becomes history.
Observe LM Studio's prefix-cache stats on the second model request (and any later turn): cache hit on the prefix is much smaller than the actual unchanged history would imply, often near zero, because the rendered prompt prefix is not byte-stable.
(Optional) Compare against a non-Qwen OpenAI-compatible LM Studio model — prefix cache behaves normally.
This issue might be a duplicate of existing issues. Please check:
reasoning_content stripped from assistant messages on replay, causing KV cache invalidation on local inference #19081: reasoning_content stripped from assistant messages on replay, causing KV cache invalidation on local inference — covers the same root cause (assistant reasoning blocks not preserved in history, breaking prefix/KV cache on local inference backends including Qwen models). The tool-response rendering aspect in your report may be an additional angle, but the core prefix-cache instability from reasoning content replay is already tracked there.
If your issue adds meaningfully new information (e.g. the role: "tool" serialization instability as a second independent source of cache misses), please comment on #19081 with that detail or clarify how your report differs.
Activity
github-actions commentedon May 10, 2026
This issue might be a duplicate of existing issues. Please check:
reasoning_contentstripped from assistant messages on replay, causing KV cache invalidation on local inference — covers the same root cause (assistant reasoning blocks not preserved in history, breaking prefix/KV cache on local inference backends including Qwen models). The tool-response rendering aspect in your report may be an additional angle, but the core prefix-cache instability from reasoning content replay is already tracked there.If your issue adds meaningfully new information (e.g. the
role: "tool"serialization instability as a second independent source of cache misses), please comment on #19081 with that detail or clarify how your report differs.github-actions commentedon Jul 10, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.