fix: strip thinking blocks from qwen-code completePrompt responses#12103
Draft
roomote-v0[bot] wants to merge 1 commit intomainfrom
Draft
fix: strip thinking blocks from qwen-code completePrompt responses#12103roomote-v0[bot] wants to merge 1 commit intomainfrom
roomote-v0[bot] wants to merge 1 commit intomainfrom
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:Fix: Added a regex strip of
<think>...</think>blocks from thecompletePrompt()response, consistent with howcreateMessage()already handles thinking blocks during streaming (lines 257-283 in qwen-code.ts).The approach mirrors how other providers handle thinking models in their
completePromptmethods (e.g., Mistral filters out thinking content).Feedback and guidance are welcome.
Test Procedure
src/api/providers/__tests__/qwen-code-complete-prompt.spec.tswith 6 tests covering:<think>block stripped from response<think>blocks stripped<think>blocks handledcd src && pnpm exec vitest run api/providers/__tests__/qwen-code-complete-prompt.spec.tsPre-Submission Checklist
Documentation Updates
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