Repository navigation
[BUG] Historical tool-call messages missing reasoning_content on multi-turn interleaved models (KV cache invalidation)Â #28333
Description
Description
Description
When using reasoning models (like Qwen/Qwen3.6-27B or Qwen3.6-35B-A3B) natively with local backends like llama-swap/llama.cpp or via providers like DeepInfra, the KV cache completely invalidates and forces a slow, full prompt re-evaluation on Turn 2 if tool calls were executed in Turn 1.
This happens because OpenCodeâs message compiler is stripping or failing to forward the historical reasoning_content blocks inside older assistant tool-call messages when compiling the chat history array. Because the text history passed back to the local runner diverges from what was originally evaluated, prefix-matching fails, causing a total KV cache eviction.
To make matters worse, removing "interleaved" to preserve raw text as a workaround causes a critical race condition where OpenCode accidentally executes tool calls the model was merely "thinking about" inside its reasoning block.
Configuration (opencode.json)
{
"$schema": "https://opencode.ai/config.json",
"lsp": true,
"model": "local/qwen3.6-27b",
"provider": {
"local": {
"npm": "@ai-sdk/openai-compatible",
"name": "Llama-Swap",
"options": {
"baseURL": "http://127.0.0.1:8000/v1"
},
"models": {
"qwen3.6-27b": {
"name": "Qwen3.6-27B",
"reasoning": true,
"temperature": true,
"tool_call": true,
"interleaved": {
"field": "reasoning_content"
},
"limit": {
"context": 245760
}
}
}
}
}
}
Expected Behavior
OpenCode should preserve and bundle reasoning_content in historical assistant blocks passed to the API. When an assistant message has tool calls, its payload should maintain exact history parity:
{
"role": "assistant",
"tool_calls": [...],
"content": "...",
"reasoning_content": "..." // This must be preserved, or fallback to "" instead of being stripped
}
Actual Behavior
Historical reasoning_content fields are dropped or set to undefined on prior turns that include tool_calls. This breaks OpenAI-compatible streaming schemas expecting interleaved structure continuity, ruining prefix-matching optimization for high-context local inference setups.
Environment Information
- OpenCode Version: 1.15.3
- Local Runner Platform:
llama-swap/llama.cpp/ Intel Arc Backend - Operating System: Linux (nixos)
Plugins
none
OpenCode version
1.15.3
Steps to reproduce
Steps to Reproduce
- Configure an OpenAI-compatible provider with
interleavedtracking for reasoning models (e.g.,Qwen3.6-27Bwith"field": "reasoning_content"). - Start an OpenCode workspace session and issue a task that requires agentic tool usage (e.g., asking the model to find a bug in a local file or search a workspace directory using an internal tool).
- Allow the model to step through its thinking process (the TUI will cleanly display the collapsing "Thinking..." dropdown block) and subsequently generate a tool call.
- Allow OpenCode to execute the workspace tool, collect the return payload, and dispatch it back to the provider.
- On the subsequent follow-up turn (Turn 2), inspect the network payload or local server logs (e.g., running
llama-swaporllama.cppwith verbose tracking):- Observed Result: The server logs show a
0%KV cache prefix-match/reuse rate, resulting in a full prompt evaluation lag. Checking the exact incoming array schema reveals that OpenCode sent the historicalassistantmessage with itscontentstring andtool_callsarray intact, but completely stripped or dropped thereasoning_contentfield from that message's history block.
- Observed Result: The server logs show a
Screenshot and/or share link
No response
Operating System
Linux (nixos 25.11)
Terminal
No response
Activity
nilo85 commentedon May 19, 2026
this is probably a "duplicate" of #23833 which got rejected, howver this bug makes opencode usless for local LLM with Qwen 3.6
github-actions commentedon May 19, 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 inferencereasoning_contentmissing in assistant tool call message (same root cause)reasoning_contentnot passed back for tool call turns (DeepSeek, same underlying bug)reasoning_content400 error on multi-turn with tool calls, fix PRs referencedPlease review these issues to see if your report is already covered. If so, consider adding a comment there with your specific setup details (llama-swap / Intel Arc) rather than opening a new issue.
nilo85 commentedon May 19, 2026
Closing as its a duplicate of #19081