Skip to content

fix(ollama): use truncateUtf16Safe for malformed NDJSON log truncation#102593

Merged
steipete merged 3 commits into
openclaw:mainfrom
Pandah97:fix/truncateUtf16Safe-ollama
Jul 9, 2026
Merged

fix(ollama): use truncateUtf16Safe for malformed NDJSON log truncation#102593
steipete merged 3 commits into
openclaw:mainfrom
Pandah97:fix/truncateUtf16Safe-ollama

Conversation

@Pandah97

@Pandah97 Pandah97 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

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:

  • a complete malformed NDJSON line terminated by a newline;
  • malformed trailing data when the stream ends without a newline.

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.
  • oxfmt and git diff --check passed for the touched files.
  • Live local Ollama 0.31.2 validation on 2026-07-09: /api/chat with qwen3:0.6b returned HTTP 200, Content-Type: application/x-ndjson, a streamed content record, and a final done: true record.
  • Ollama's official streaming contract documents newline-delimited JSON with the application/x-ndjson content type: https://docs.ollama.com/api/streaming

The 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.

The parseNdjsonStream function uses naive .slice(0, 120) on malformed
NDJSON data in log warnings which can split surrogate pairs. Replace
with truncateUtf16Safe().
@openclaw-barnacle openclaw-barnacle Bot added extensions: ollama size: XS triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Jul 9, 2026
@clawsweeper

clawsweeper Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Codex review: stale review; fresh review needed.

Summary
The latest durable ClawSweeper review was for head 88f264910c632267d42ea524fb790172d5d21fb2, but the PR head is now 7b379708406f2ce2a8cb5b9c1b85758d929df390. Its old verdict and PR readiness labels are no longer current.

Next step
Run or wait for a fresh ClawSweeper review on the current PR head.

Review history (1 earlier review cycle)
  • reviewed 2026-07-09T09:30:45.412Z sha 9ea6a4e :: needs real behavior proof before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. labels Jul 9, 2026
@clawsweeper clawsweeper Bot removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 9, 2026
@steipete

steipete commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Land-ready proof for exact head 7b379708406f2ce2a8cb5b9c1b85758d929df390:

  • Reviewed both malformed Ollama NDJSON branches: complete newline-terminated lines and the trailing unterminated buffer now share the UTF-16-safe 120-code-unit preview boundary.
  • Added exact parser-level regression coverage for an emoji crossing each boundary; the focused Ollama provider file passes all 104 tests.
  • Live Ollama 0.31.2 proof on 2026-07-09: /api/chat with qwen3:0.6b returned HTTP 200, Content-Type: application/x-ndjson, a streamed content record, and a final done: true record, matching the official streaming contract at https://docs.ollama.com/api/streaming.
  • oxfmt, focused oxlint, git diff --check, and a fresh branch autoreview pass clean with no actionable findings.
  • Native OPENCLAW_TESTBOX=1 scripts/pr prepare-run 102593 accepted exact-head hosted CI/Testbox.

No changelog entry is required because this only repairs malformed-stream diagnostic previews. No known proof gaps.

@steipete
steipete merged commit 29d2a1e into openclaw:main Jul 9, 2026
93 of 95 checks passed
@steipete

steipete commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: ollama P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants