Skip to content

fix: decode streamed responses with an incremental UTF-8 decoder - #374

Merged
velaraptor-runpod merged 1 commit into
runpod-workers:mainfrom
irisfield:fix/stream-multibyte-utf8
Nov 16, 2026
Merged

velaraptor-runpod merged 1 commit into
runpod-workers:mainfrom
irisfield:fix/stream-multibyte-utf8

Conversation

@irisfield

Copy link
Copy Markdown
Contributor

Closes #373

handler decoded every iter_any() chunk on its own with chunk.decode("utf-8", errors="replace"). A multibyte character split across two chunks therefore became U+FFFD in both halves.

The streaming branch now decodes with codecs.getincrementaldecoder("utf-8")(errors="replace"), which keeps the incomplete bytes of a character until the next chunk. Empty pieces are not yielded, and the decoder is flushed after the loop so a stream that ends mid-character yields one replacement character instead of dropping the bytes.

New tests in TestStreamingUtf8 run handler against a local aiohttp server that writes the response in separate chunks: a 2-byte character split in two, a 4-byte emoji split after 1, 2 and 3 bytes, an ASCII-only stream, a stream ending mid-character, and mixed text sent one byte per chunk.

@velaraptor-runpod
velaraptor-runpod self-requested a review November 16, 2026 19:43
@velaraptor-runpod
velaraptor-runpod merged commit 4511c96 into runpod-workers:main Nov 16, 2026
5 of 8 checks passed
@irisfield
irisfield deleted the fix/stream-multibyte-utf8 branch November 24, 2026 06:47
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.

Streamed responses contain replacement characters when a multibyte character is split across reads

2 participants