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
Open
Conversation
…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>
|
|
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.
The 6
lines().map_while(Result::ok)sites instream.rssilently 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 withU+FFFDand 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\xFEmid-stream to verify all lines are preserved.Free to use as-is.