Skip to content

fix: strip thinking blocks from qwen-code completePrompt responses#12103

Draft
roomote-v0[bot] wants to merge 1 commit intomainfrom
fix/qwen-code-prompt-enhancement-thinking-blocks
Draft

fix: strip thinking blocks from qwen-code completePrompt responses#12103
roomote-v0[bot] wants to merge 1 commit intomainfrom
fix/qwen-code-prompt-enhancement-thinking-blocks

Conversation

@roomote-v0
Copy link
Copy Markdown
Contributor

@roomote-v0 roomote-v0 bot commented Apr 13, 2026

Related GitHub Issue

Closes: #12102

Description

This PR attempts to address Issue #12102 where prompt enhancement fails on qwen3-coder models with a "Failed to enhance prompt" toast.

Root cause: The QwenCodeHandler.completePrompt() method returns raw response content without any post-processing. qwen3-coder models are thinking/reasoning models that include <think>...</think> blocks in their responses. This causes either:

  1. The content field to be mostly thinking markup, producing garbled enhanced prompts
  2. The actual useful text to be buried inside thinking blocks

Fix: Added a regex strip of <think>...</think> blocks from the completePrompt() response, consistent with how createMessage() already handles thinking blocks during streaming (lines 257-283 in qwen-code.ts).

The approach mirrors how other providers handle thinking models in their completePrompt methods (e.g., Mistral filters out thinking content).

Feedback and guidance are welcome.

Test Procedure

  • Added new test file src/api/providers/__tests__/qwen-code-complete-prompt.spec.ts with 6 tests covering:
    • Plain text responses returned as-is
    • Single <think> block stripped from response
    • Multiple <think> blocks stripped
    • Multiline <think> blocks handled
    • Response that is only a think block returns empty string
    • Null content returns empty string
  • All existing qwen-code tests continue to pass
  • Run tests: cd src && pnpm exec vitest run api/providers/__tests__/qwen-code-complete-prompt.spec.ts

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes.
  • Documentation Impact: No documentation updates are required.
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Documentation Updates

  • No documentation updates are required.

Additional Notes

This is a minimal, targeted fix. The change is a single line addition to completePrompt() that strips thinking blocks via regex before returning the response text.

Interactively review PR in Roo Code Cloud

qwen3-coder models include <think>...</think> blocks in their responses.
The completePrompt() method (used for prompt enhancement) was returning
these blocks as-is, causing the enhanced prompt to either be empty
(triggering "Failed to enhance prompt" toast) or contain raw thinking
markup.

This strips <think> blocks from the response content before returning,
consistent with how createMessage() already handles them for streaming.

Closes #12102
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.

[BUG] Prompt enhancement broken on qwen3-coder models

1 participant