Repository navigation
fix: only separate streamed text that follows earlier text and a tool result - #482
Open
pcbeingused33 wants to merge 6 commits into
Open
pcbeingused33 wants to merge 6 commits into
pcbeingused33 wants to merge 6 commits into
Conversation
… result The previous commit yielded "\n\n" after every tool result in the sync loop, as the async loop did. That made a response whose first round is only tool calls start with blank lines, in both loops, and broke tests comparing the exact text. Drop the per-result separator in both loops and put "\n\n" before the first text of a later round only when text was already emitted. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
pcbeingused33
force-pushed
the
fix/stream-text-separator
branch
from
October 21, 2026 16:44
375d7ee to
b986b7d
Compare
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Separator insertion also affects content="all", adding an unintended chunk to rich-content streams; both sync and async paths need text-only gating and regression tests.
1 open issue
What changed in this PR
This PR aligns synchronous and asynchronous text output around tool calls, separating successive text rounds without adding leading blank lines to tool-first responses.
Changes:
- Introduces a shared
_TextSeparatorfor both chat loops. - Adds fake-provider regression tests for streaming and chat responses.
- Documents the formatting correction in the changelog.
| File | Description |
|---|---|
tests/test_stream_tool_separator.py |
Tests sync and async text separation and tool-first responses. |
chatlas/_chat.py |
Adds shared separator state and replaces unconditional async separators. |
CHANGELOG.md |
Describes the text-formatting correction. |
Review effort: Balanced
This branch has not been deployed
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.

.stream(content="text")and.chat()ran the text before and after a tool call together, while.stream_async(content="text")and.chat_async()put a blank line between them:_chat_impl_asyncyielded"\n\n"after each tool result, and_chat_implhad no such branch. For a model that says "Checking." before calling a tool and "Done." after, the sync stream producedChecking.Done.and the async oneChecking.\n\nDone.. The async rule also had a flaw: a response whose first round is only tool calls started with blank lines (\n\nDone.).Both loops now share one rule (
_TextSeparator): a"\n\n"goes before the first text of a round that follows tool results, only when text was already emitted. The result isChecking.\n\nDone.for text, tool, text;Done.when the first round is only tool calls; sync and async agree.content="all"is unchanged. Existing tests that comparestr(chat.chat(...))exactly (test_chat_tool_request_rejectandreject2) pass unchanged.Tests:
tests/test_stream_tool_separator.pydrives a fake two-round provider through.stream(),.stream_async(),.chat()and.chat_async(), with a first round of text plus a tool request, and with a first round of only a tool request. Four of the six fail onmain. The rest oftests/test_chat.pyis unchanged; its 5 failures in my environment (optional dependencies missing) are the same onmain. A CHANGELOG entry is included.This change was made with Claude Code; the tests above were run before opening the PR.
🤖 Generated with Claude Code