Repository navigation
fix: decode streamed text across chunk boundaries - #493
Merged
Merged
Conversation
The SDK event stream, the MCP HTTP/SSE reader and the TUI remote chat decoded every HTTP chunk on its own with from_utf8_lossy. A chunk cut inside a multi-byte character (any non-ASCII text) turned it into two replacement characters, garbling assistant text and tool results. Add whycodes_core::Utf8Stream, which holds back an incomplete trailing character until the next chunk completes it, and use it in all three readers. The SDK reaches it through whycodes-protocol so it keeps its single dependency, and now folds a `\r\n` split across chunks too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
mrnasil
enabled auto-merge (squash)
November 25, 2026 15:17
Merged
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.
Three readers decoded each HTTP chunk on its own with
from_utf8_lossy:A chunk boundary inside a multi-byte character (
ç,日, an emoji) turned that character into twoU+FFFDs, garbling assistant text and tool results.The fix:
whycodes_core::Utf8Stream. It holds back an incomplete trailing character until the next chunk completes it, and still turns invalid bytes intoU+FFFDimmediately.whycodes-protocolre-export, so it still depends only onwhycodes-protocol.\r\nthat is split across two chunks.Tests:
aç日😀;çand\r\nboth straddle chunks;SseParser::push_bytesfed one byte at a time.utf8_stream.rsandsdk/src/client.rshave 100% line coverage. The lines still missed in the mcp crate are also missed on main.🤖 Generated with Claude Code