fix(ollama): use truncateUtf16Safe for malformed NDJSON log truncation#102593
Merged
Conversation
The parseNdjsonStream function uses naive .slice(0, 120) on malformed NDJSON data in log warnings which can split surrogate pairs. Replace with truncateUtf16Safe().
Contributor
|
Codex review: stale review; fresh review needed. Summary Next step Review history (1 earlier review cycle)
|
9 tasks
Contributor
|
Land-ready proof for exact head
No changelog entry is required because this only repairs malformed-stream diagnostic previews. No known proof gaps. |
Contributor
|
Merged via squash.
|
This was referenced Jul 9, 2026
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Jul 10, 2026
openclaw#102593) * fix(ollama): use truncateUtf16Safe for malformed NDJSON log warning The parseNdjsonStream function uses naive .slice(0, 120) on malformed NDJSON data in log warnings which can split surrogate pairs. Replace with truncateUtf16Safe(). * test(ollama): cover UTF-16-safe NDJSON warnings * test(ollama): satisfy lint in NDJSON coverage --------- Co-authored-by: Peter Steinberger <[email protected]>
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.
What Problem This Solves
parseNdjsonStream()included malformed Ollama response data in two warning messages using.slice(0, 120). When an emoji or another supplementary Unicode character straddled that UTF-16 boundary, the preview ended with a dangling surrogate and could render as corrupted text.Why This Change Was Made
Both malformed-input branches now use the existing
truncateUtf16Safe(..., 120)helper exported by the plugin SDK. This preserves the existing 120-code-unit bound and warning text while ensuring the preview never ends in half of a surrogate pair.The focused tests exercise both parser states rather than testing the helper in isolation:
Each input places an emoji exactly across the truncation boundary and asserts the complete warning string.
User Impact
Ollama diagnostic warnings remain readable when malformed streamed data contains supplementary Unicode near the preview boundary. Valid stream parsing, API behavior, configuration, and dependencies are unchanged.
Evidence
node ../../node_modules/vitest/vitest.mjs run --config test/vitest/vitest.extension-providers.config.ts extensions/ollama/src/stream-runtime.test.ts— 104 tests passed.oxfmtandgit diff --checkpassed for the touched files./api/chatwithqwen3:0.6breturned HTTP 200,Content-Type: application/x-ndjson, a streamed content record, and a finaldone: truerecord.application/x-ndjsoncontent type: https://docs.ollama.com/api/streamingThe live service correctly produced valid NDJSON; malformed-wire behavior was therefore injected at the exported parser boundary in the focused tests. No API, config, or dependency surface changes.
AI-assisted
This PR was generated with Claude Code and improved/reviewed with Codex.