fix(amazon-bedrock): preserve multibyte characters in streamed event payloads - #19992
Open
wasim-builds wants to merge 2 commits into
Open
fix(amazon-bedrock): preserve multibyte characters in streamed event payloads#19992wasim-builds wants to merge 2 commits into
wasim-builds wants to merge 2 commits into
Conversation
wasim-builds
force-pushed
the
fix/13299-bedrock-gateway-multibyte-stream
branch
from
August 30, 2026 19:18
3215853 to
453a2e0
Compare
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.
Description
Fixes #13299.
When using streaming models on Amazon Bedrock (or through the AI Gateway which proxies Bedrock), multibyte characters (such as Korean, Japanese, Chinese, or emojis) were occasionally getting corrupted (``).
This happened because the raw byte stream from AWS events could be split across boundaries that truncate a multibyte character. The
TextDecoderwas initialized without the{ stream: true }option, so instead of maintaining the partial byte state for the next chunk, it immediately emitted replacement characters.This PR fixes the issue by maintaining a persistent
TextDecoderand passing{ stream: true }during decoding in both the general Bedrock event stream decoder and the Anthropic-specific Bedrock fetch implementation.Testing
TextDecoderpreserves stream byte state across chunks.