Repository navigation
fix: close unclosed think tags around agent tool calls - #41764
Merged
crazywoola merged 2 commits intoSep 4, 2026
Merged
crazywoola merged 2 commits into
crazywoola merged 2 commits into
Conversation
Reasoning models often omit </think> when a tool call interrupts the stream, so a later think block or the answer is nested in thinking HTML. Close dangling tags on tool logs, nested opens, and stream end, and apply the same fallback in markdown preprocessing.
Souravrajvi0
requested review from
QuantumGhost,
iamjoel,
laipz8200 and
zxhlyh
as code owners
September 3, 2026 19:52
Contributor
Pyrefly Type Coverage
|
crazywoola
approved these changes
Sep 4, 2026
3 of 6 tasks
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.
Fixes #41558
Summary
Reasoning models (GLM-5.3 and similar) wrap chain-of-thought in
<think>tags. A tool call often interrupts generation before</think>is emitted, so a later<think>block or the answer stays nested in the still-open tag. Markdown then turns that into an unclosed<details data-think>, and the reply is rendered as thinking.This PR adds a fallback that inserts the missing close tag:
<think>when a tool log (or link) interrupts the stream, when a new<think>starts after real content, and at stream end.Screenshots
</think>is dropped around a tool callChecklist
make lint && make type-check(backend) andvp staged(frontend) to appease the lint gods