Skip to content

fix: preserve UTF-8 in SageMaker streaming decode - #13181

Open
pacocartones wants to merge 1 commit into
continuedev:mainfrom
pacocartones:fix/sagemaker-utf8-stream-decode
Open

fix: preserve UTF-8 in SageMaker streaming decode#13181
pacocartones wants to merge 1 commit into
continuedev:mainfrom
pacocartones:fix/sagemaker-utf8-stream-decode

Conversation

@pacocartones

Copy link
Copy Markdown

_streamComplete and _streamChat in core/llm/llms/SageMaker.ts decoded each streamed binary chunk with a fresh new TextDecoder().decode(chunk) and no streaming flag. A multibyte UTF-8 character split across two network chunks was emitted as U+FFFD replacement characters, corrupting any non-ASCII model output (emoji, accents, CJK). The chunk content and boundaries come from the remote SageMaker endpoint, so this triggers on ordinary response fragmentation.

Reuse a single TextDecoder per stream and decode with { stream: true }, so partial sequences at chunk boundaries are buffered until complete.

Added regression tests for a split emoji and a split two-byte character (vitest): they fail before the fix (replacement chars) and pass after.

The SageMaker _streamComplete and _streamChat generators decoded each
streamed binary chunk with a fresh TextDecoder and no streaming flag.
A multibyte UTF-8 character split across two network chunks was decoded
as U+FFFD replacement characters, corrupting non-ASCII model output.

Reuse a single TextDecoder per stream and decode with { stream: true }
so partial multibyte sequences at chunk boundaries are buffered until
completed. Adds regression tests covering a split emoji and a split
two-byte character.
@pacocartones
pacocartones requested a review from a team as a code owner August 24, 2026 04:56
@pacocartones
pacocartones requested review from sestinj and removed request for a team August 24, 2026 04:56
@github-actions

github-actions Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@pacocartones

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

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.

1 participant