Fix Qwen3 content extraction breaking code formatting #661
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.
Summary
Fixes a bug in Qwen3 content extraction where aggressive whitespace cleanup was breaking proper code formatting in non-tool-call streaming output.
Problem
The
qwen3::extract_content_during_parsing()
function was using an aggressive regex pattern that collapsed multiple newlines:This broke:
Root Cause
The regex
R"(\n\s*\n)"
replaces any sequence of newline + whitespace + newline with a single newline, which is overly aggressive for content that should preserve formatting.Solution
✅ Replace aggressive cleanup with gentle trimming
std::regex_replace(content, std::regex(R"(\n\s*\n)"), "\n")
string_strip(content)
following original llama.cpp patterns✅ Add proper include
#include "../../common/common.h"
forstring_strip
access✅ Add regression test
test_qwen3_whitespace_preservation()
validates PEP 8 complianceTesting
Example
Before (broken):
After (fixed):
Files Changed
examples/server/parsers/qwen3_parser.hpp
- Fix whitespace handlingtests/test-function-calls.cpp
- Add regression testTest Results