Fix spurious </think> tags caused by empty string reasoning_content in streaming #7025
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.
The streaming response from
OpenAIChatCompletionClient.create_stream()
was generating many spurious<think>
and</think>
tags when models returned empty string reasoning content chunks.Problem
When using models like Qwen3-30B-A3B-Thinking that emit reasoning content during streaming, the API sometimes sends chunks with empty string
reasoning_content
values (""
). The original logic incorrectly treated these empty strings as a signal to exit reasoning mode:This caused the streaming output to contain many unwanted tag pairs like:
Instead of the expected:
Solution
Modified the exit condition to only trigger when
reasoning_content
is explicitlyNone
:Now empty string reasoning content is ignored (no action taken), and reasoning mode only exits when the API sends
None
as the proper termination signal.Testing
Validated the fix with comprehensive tests showing:
</think>
tags generated for each empty string chunk</think>
tag generated only when reasoning actually endsThis minimal change preserves all existing functionality while fixing the reported streaming issue.
Fixes #7009.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.