fix(streaming): prevent <think> in prose from suppressing response output#6968
Merged
Conversation
…tput When the model mentions <think> as literal text in its response (e.g. "(/think not producing <think> tags)"), the streaming display treated it as a reasoning block opener and suppressed everything after it. The response box would close with truncated content and no error — the API response was complete but the display ate it. Root cause: _stream_delta() matched <think> anywhere in the text stream regardless of position. Real reasoning blocks always start at the beginning of a line; mentions in prose appear mid-sentence. Fix: track line position across streaming deltas with a _stream_last_was_newline flag. Only enter reasoning suppression when the tag appears at a block boundary (start of stream, after a newline, or after only whitespace on the current line). Add a _flush_stream() safety net that recovers buffered content if no closing tag is found by end-of-stream. Also fixes three related issues discovered during investigation: - anthropic_adapter: _get_anthropic_max_output() now normalizes dots to hyphens so 'claude-opus-4.6' matches the 'claude-opus-4-6' table key (was returning 32K instead of 128K) - run_agent: send explicit max_tokens for Claude models on Nous Portal, same as OpenRouter — both proxy to Anthropic's API which requires it. Without it the backend defaults to a low limit that truncates responses. - run_agent: reset truncated_tool_call_retries after successful tool execution so a single truncation doesn't poison the entire conversation.
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.
Summary
Cherry-picked from PR #6958 by @jquesnelle onto current main.
Fixes a bug where the CLI streaming display treats literal
<think>text mentioned in prose (e.g. "not producing<think>tags") as a reasoning block opener, silently swallowing everything after it.Changes
_stream_deltablock-boundary matching (cli.py) — Only enter reasoning suppression when<think>appears at a block boundary (start of stream, after newline, or whitespace-only prefix). Prose mentions pass through as literal text. Adds_flush_streamsafety net to recover buffered content from false positives._get_anthropic_max_outputdot normalization (anthropic_adapter.py) — Normalizes dots to hyphens soanthropic/claude-opus-4.6matches theclaude-opus-4-6table key. Without this, Sonnet 4.6 gets 128K instead of its correct 64K limit.Nous Portal max_tokens (run_agent.py) — Extends the existing OpenRouter
max_tokensinjection to also cover Nous Portal, which proxies to Anthropic's API and requires it.Reset truncated_tool_call_retries (run_agent.py) — Resets the retry counter after successful tool execution so a single truncation doesn't prevent retries for the rest of the session.
Tests
tests/cli/test_stream_delta_think_tag.py— all pass