Skip to content

feat(provider): add preserveReasoningInContent config option to fix Qwen preserve_thinking interoperability#25357

Open
jgrcic wants to merge 2 commits intoanomalyco:devfrom
jgrcic:qwen_preserve_think
Open

feat(provider): add preserveReasoningInContent config option to fix Qwen preserve_thinking interoperability#25357
jgrcic wants to merge 2 commits intoanomalyco:devfrom
jgrcic:qwen_preserve_think

Conversation

@jgrcic
Copy link
Copy Markdown

@jgrcic jgrcic commented May 1, 2026

Issue for this PR

Closes # (No existing issue)

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

This adds a preserveReasoningInContent config flag to solve an interoperability issue with the preserve_thinking feature on Qwen models (specifically tested with Qwen3.6-35B-A3B-FP8 running on vLLM).

Currently, OpenCode automatically extracts historical reasoning into a separate reasoning_content property. However, for Qwen to successfully access its previous reasoning turns in vLLM, the historical reasoning must be embedded directly within the assistant's content string, wrapped in explicit <thinking>...</thinking> tags. When OpenCode strips these out, the model loses its chain of thought in subsequent prompts.

To fix this:

  1. I added preserveReasoningInContent to the Model schema in src/config/provider.ts.
  2. Updated src/provider/transform.ts so that when this flag is enabled, it correctly transforms the reasoning history into <thinking> tags within the content body and unsets reasoning_content.

How did you verify your code works?

I tested this locally against my own vLLM instance running Qwen3.6-35B-A3B-FP8.
I prompted the model to mentally generate two random numbers, but only output one. In the next turn, I asked it for the second number.
Without this flag, the model fails to recall the second number because the reasoning is stripped. With the flag enabled in my opencode.json, I verified via mitmproxy that the payload correctly contains the <thinking> tags, and the model successfully recalled the second number.

Screenshots / recordings

No UI changes.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels May 1, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2026

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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