fix(llm): strip dangling XML tool call closing tags from text content#27984
Open
sghaskell wants to merge 1 commit into
Open
fix(llm): strip dangling XML tool call closing tags from text content#27984sghaskell wants to merge 1 commit into
sghaskell wants to merge 1 commit into
Conversation
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Author
|
PR updated to follow the required template. Body now includes proper issue reference, checkboxes, and explanation of why the fix works. |
|
THANK YOU |
|
Tested against an over-complex web-based project with 103037 tokens used in Qwen 3.6 27B NVFP4 without any pause. Thanks for the fix. |
|
Works.. please opencode team.. pull this in |
6 tasks
|
After some testing, I'm reaching the same point as @amahteletrac. I'm proposing a proper working solution in #30633. |
|
I am not able to reproduce with |
|
A tad bit slower, but in my personal experience incredibly capable local model. |
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.

Issue for this PR
Closes #24316
Type of change
What does this PR do?
Qwen3 via vLLM/llama.cpp with the hermes tool call parser occasionally appends raw XML tool call closing tags (
</parameter>,</function>,</parameter,␐) as a response termination artifact after natural language text. These leak into the assistant message content and appear as naked XML in the TUI, halting progress.This adds a
stripDanglingXmlArtifacts()helper that strips trailing XML artifacts from streaming text deltas at thestep()level inopenai-chat.tsbefore content reaches the consumer. Only trailing artifacts are stripped; mid-text occurrences are preserved.I understand why this works: the artifacts always appear at the end of a streaming delta chunk, so iterating and stripping trailing matches is sufficient without risking damage to legitimate content.
How did you verify your code works?
bun testinpackages/llm— 16/16 passbun typecheck— cleanScreenshots / recordings
N/A — this is a backend streaming fix.
Checklist