Skip to content

fix(stream): replace map_while(Result::ok) with from_utf8_lossy to prevent silent output truncation#2049

Open
rosschurchill wants to merge 1 commit into
rtk-ai:developfrom
rosschurchill:fix/c06-utf8-lossy-stream
Open

fix(stream): replace map_while(Result::ok) with from_utf8_lossy to prevent silent output truncation#2049
rosschurchill wants to merge 1 commit into
rtk-ai:developfrom
rosschurchill:fix/c06-utf8-lossy-stream

Conversation

@rosschurchill
Copy link
Copy Markdown

The 6 lines().map_while(Result::ok) sites in stream.rs silently terminate iteration on the first non-UTF-8 byte. A single bad byte in tool output means everything after it is silently dropped — the LLM never sees it, with no warning.

Replaced all 6 sites with BufRead::read_until + String::from_utf8_lossy, which replaces invalid bytes with U+FFFD and continues. The LLM sees a replacement character instead of losing the rest of the output.

Includes a regression test with a byte sequence containing \xFF\xFE mid-stream to verify all lines are preserved.

Free to use as-is.

…tes in stream.rs

lines().map_while(Result::ok) silently terminates the iterator on the first
non-UTF-8 byte, causing all output after a bad byte to disappear from the
LLM's view with no warning. Replaced all 6 sites with BufRead::read_until +
String::from_utf8_lossy so invalid bytes become U+FFFD replacement chars and
subsequent lines continue to flow through. Adds regression test with a
\xFF\xFE fixture asserting all 3 lines are preserved.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants