fix(ollama): preserve multi-byte UTF-8 content split across stream chunks - #11921
Merged
diegosouzapw merged 1 commit intoAug 30, 2026
Conversation
pacocartones
added a commit
to pacocartones/OmniRoute
that referenced
this pull request
Aug 28, 2026
pacocartones
force-pushed
the
fix/ollama-multibyte-utf8-boundary
branch
from
August 28, 2026 16:34
ef259df to
25d8074
Compare
…unks
transformToOllama decoded each network chunk with a fresh, non-streaming
TextDecoder, so a multi-byte UTF-8 sequence (CJK, emoji) split across a chunk
boundary was corrupted into U+FFFD. Use one persistent decoder with
{ stream: true }, matching every other streaming transform in open-sse/.
pacocartones
force-pushed
the
fix/ollama-multibyte-utf8-boundary
branch
from
August 29, 2026 02:48
25d8074 to
0c2a36d
Compare
Contributor
Author
|
CI note — none of the red checks are introduced by this change (an ollama stream-decoder fix touching open-sse/utils/ollamaTransform.ts + its test). |
diegosouzapw
merged commit Aug 30, 2026
41c6135
into
diegosouzapw:release/v3.8.51
34 of 39 checks passed
muhamadgalihsaputra
pushed a commit
to niyatna/NiyatnaRoute
that referenced
this pull request
Sep 27, 2026
…unks (diegosouzapw#11921) Boarded with 8 other PRs in one combined worktree: typecheck:core, check:file-size, check:changelog-integrity, check:complexity, check:cognitive-complexity, check:cycles, check-native-deps all green. Retargeted from main to release/v3.8.51. Confirmed ollamaTransform.ts was the only streaming transform not using a persistent { stream: true } decoder — matches the pattern already established in responsesTransformer.ts. TDD repro included. Thanks for finding an unreported bug.
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.
Summary
transformToOllamainopen-sse/utils/ollamaTransform.ts) decoded every upstream network chunk with a freshnew TextDecoder().decode(chunk)and no{ stream: true }. A multi-byte UTF-8 character (CJK, emoji) split across a chunk boundary was decoded as two incomplete halves and turned intoU+FFFDreplacement characters in the NDJSON delivered to Ollama-format clients. The line-levelbufferreassembles split SSE lines, but the corruption happens one layer below at byte decode, so it cannot recover it.TextDecoderand decoding with{ stream: true }, so pending bytes carry across chunks. This matches the pattern already used by every other streaming transform/executor inopen-sse/— e.g.responsesTransformer.ts(which comments "persistent decoder with { stream: true } carries pending bytes between chunks"),stream.ts, and the*-webexecutors.ollamaTransform.tswas the only streaming transform not doing this.Related Issues
Validation
tests/unit/ollama-transform.test.ts— the new case fails on the pre-fix code ('���好世界🌍',AssertionError) and passes after; full file 10/10 with the fix.npm run lint/ full unit suite / coverage / build — not run locally (dependencies not installed); CI (docs: official 'golden path' contribution guide by change type #8329) runs them on this PR. The change is a 3-line decoder hoist with no new imports.maintipd5dfcff); focused test rerun afterward.Tests Added Or Updated
tests/unit/ollama-transform.test.ts— new test "transformToOllama preserves multi-byte UTF-8 content split across chunks": splits a CJK+emoji delta at a UTF-8 continuation byte (0x80–0xBF) across two enqueued chunks and asserts exact reassembly with noU+FFFD. Verified failing on the pre-fix code and passing after.Coverage Notes
open-sse/utils/ollamaTransform.ts; the new test exercises the changed decode path (chunk-boundary reassembly) directly.Reviewer Notes