Skip to content

[BUG] Historical tool-call messages missing reasoning_content on multi-turn interleaved models (KV cache invalidation) #28333

Closed as duplicate

Description

@nilo85

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

  1. Configure an OpenAI-compatible provider with interleaved tracking for reasoning models (e.g., Qwen3.6-27B with "field": "reasoning_content").
  2. 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).
  3. 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.
  4. Allow OpenCode to execute the workspace tool, collect the return payload, and dispatch it back to the provider.
  5. On the subsequent follow-up turn (Turn 2), inspect the network payload or local server logs (e.g., running llama-swap or llama.cpp with 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 historical assistant message with its content string and tool_calls array intact, but completely stripped or dropped the reasoning_content field from that message's history block.

Screenshot and/or share link

No response

Operating System

Linux (nixos 25.11)

Terminal

No response

Activity

  1. nilo85 commented on May 19, 2026

    @nilo85
    Author

    this is probably a "duplicate" of #23833 which got rejected, howver this bug makes opencode usless for local LLM with Qwen 3.6

  2. github-actions commented on May 19, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    Please 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.

  3. nilo85 commented on May 19, 2026

    @nilo85
    Author

    Closing as its a duplicate of #19081

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions