Repository navigation
fix(ollama): stop oversized stream records from growing memory - #107473
Conversation
296d1e0 to
0baca03
Compare
|
Codex review: needs maintainer review before merge. Reviewed July 31, 2026, 5:54 AM ET / 09:54 UTC. ClawSweeper reviewWhat this changesThis PR adds a shared 16 MiB cap for each individual Ollama NDJSON stream record, cancelling newline-free oversized responses in native chat streaming and onboarding model pulls. Merge readinessThis remains a useful, narrowly scoped Ollama safety fix. The branch has maintainer-confirmed acceptance of the intentional 16 MiB compatibility boundary and strong exact-head localhost proof, but it is behind current Priority: P2 Review scores
Verification
How this fits togetherThe bundled Ollama extension consumes newline-delimited JSON from Ollama endpoints for model chat responses and onboarding download progress. Incoming byte chunks are accumulated into records, then parsed into agent output or setup progress; this patch rejects one oversized record before that accumulation can grow without a delimiter. flowchart LR
A[Ollama endpoint] --> B[NDJSON response bytes]
B --> C[Per-record byte cap]
C -->|within 16 MiB| D[NDJSON record parser]
C -->|oversized| E[Cancel response reader]
D --> F[Chat response stream]
D --> G[Onboarding pull progress]
E --> H[Actionable error]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +31, Tests +71. Total +102 across 5 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Rebase onto current Do we have a high-confidence way to reproduce the issue? Yes for the proposed fix path: the PR documents a deterministic real localhost HTTP reproduction using the production stream function and reports an exact-head overflow result. This review did not independently execute that harness in the read-only checkout. Is this the best way to solve the issue? Yes. A shared raw-byte check before text decoding is the narrowest maintainable way to bound the undelimited-record buffer across both Ollama consumers, and the maintainer has explicitly accepted the compatibility limit. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against f943a94a3303. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (5 earlier review cycles)
|
59c2bb2 to
04db57a
Compare
04db57a to
b959065
Compare
|
This pull request has been automatically marked as stale due to inactivity. |
Co-authored-by: wangmiao0668000666 <[email protected]>
* preserve/pr-107473-ollama-stream-ndjson-cap: (5598 commits) chore(changelog): remove release-owned entry fix(agents): resume interrupted turns past progress commentary (openclaw#116725) fix(gateway): sign device proofs with challenge time (openclaw#116679) fix(testing): load relay smoke through UI Vite config test(testing): guard realtime relay smoke module path fix(testing): repair realtime relay live smoke import test: type session request parameters (openclaw#116713) fix: retain event invalidation for pagination docs: note queued session refresh fix fix: preserve queued session refresh options fix(exec): require approval for abbreviated inline eval flags [AI] (openclaw#116529) fix: keep owner-only tools out of non-owner skill commands [AI] (openclaw#116532) fix(ui): bound Talk relay microphone uplink fix(tui): require a fresh agent roster (openclaw#116715) fix(memory-wiki): preserve user edits when rolling back ChatGPT imports (openclaw#116517) fix(agents): cron failures preserve timeout and cancellation reasons (openclaw#116566) fix(release): unblock beta validation workflows (openclaw#116708) fix(ci): discover frozen target startup benchmark cases (openclaw#116711) fix(session): preserve reset message payloads (openclaw#116195) fix(qa): tolerate loaded-runner bus delivery stalls (openclaw#116448) ...
* origin/main: fix(googlechat): record canonical receipt thread (openclaw#116717) fix(edit): restore UTF-16 difference offsets fix(openai): share GPT-Live browser broker ownership fix(voice-call): cancel consults on bridge replacement fix(voice-call): recheck consult owner after await fix(voice-call): cancel pending replacement consults fix(voice-call): isolate replacement consult handoff test(voice-call): cover late forced consult teardown fix(voice-call): cancel forced consults on teardown fix(edit): prefer-for-of loop in firstDifferenceIndex fix(openai): return undefined from cleanup on non-disable reasons fix(openai): restrict GPT-Live broker cleanup to plugin disable only
|
Maintainer decision: accept 16 MiB as the maximum supported individual Ollama NDJSON record. This keeps more than 2x headroom over the current Ollama Go client scanner cap while bounding hostile newline-free responses. On exact head ae3d3ec, a real localhost HTTP server sent a 20,971,631-byte record; the production stream aborted after 18,874,368 bytes, closed the response, and emitted @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Rebased/merged current @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Merged via squash.
|
* commit 'refs/frozen/talk-pcm-output-main-refresh': fix(skills): allow autonomous sweep sync (#116755) fix(irc): recognize punctuation in nickname mentions (#116758) fix(plugins): require explicit source external startup (#116759) fix(whatsapp): keep sends running when typing presence fails (#116739) fix(cli): reject dangling config path escapes (#116738) fix(qa): authenticate summaries and bound native scenario commands (#116748) fix(bedrock): reject truncated streams and preserve audio results (#116743) docs(skill): isolate autonomous issue sweep worktrees fix(ci): retire Kova runtime deps coverage (#116760) chore(i18n): refresh native locales (#116640) fix(ollama): resolve web search secret refs (#104829) fix(ollama): honor stop sequences and async payload hooks (#116737) fix(ollama): stop oversized stream records from growing memory (#107473) fix(agents): preserve thinking for runtime-selected Ollama models (#116584)
…law#107473) * fix(ollama): bound pending NDJSON stream records * chore(changelog): remove release-owned entry --------- Co-authored-by: wangmiao0668000666 <[email protected]> Co-authored-by: Vincent Koc <[email protected]>
* commit 'refs/frozen/talk-pcm-output-main-refresh': fix(skills): allow autonomous sweep sync (openclaw#116755) fix(irc): recognize punctuation in nickname mentions (openclaw#116758) fix(plugins): require explicit source external startup (openclaw#116759) fix(whatsapp): keep sends running when typing presence fails (openclaw#116739) fix(cli): reject dangling config path escapes (openclaw#116738) fix(qa): authenticate summaries and bound native scenario commands (openclaw#116748) fix(bedrock): reject truncated streams and preserve audio results (openclaw#116743) docs(skill): isolate autonomous issue sweep worktrees fix(ci): retire Kova runtime deps coverage (openclaw#116760) chore(i18n): refresh native locales (openclaw#116640) fix(ollama): resolve web search secret refs (openclaw#104829) fix(ollama): honor stop sequences and async payload hooks (openclaw#116737) fix(ollama): stop oversized stream records from growing memory (openclaw#107473) fix(agents): preserve thinking for runtime-selected Ollama models (openclaw#116584)
What Problem This Solves
Fixes an issue where users connected to a malfunctioning or hostile Ollama endpoint could see OpenClaw memory keep growing when the endpoint streamed an arbitrarily large NDJSON record without a newline.
Why This Change Was Made
The native Ollama parser now caps each pending NDJSON record at 16 MiB using the original response bytes, resets the count at every newline, and cancels the reader before reporting an overflow. The risk is bounded to individual records larger than 16 MiB; long streams made of valid smaller records remain supported, and this does not change request timeout behavior addressed by #96635.
User Impact
OpenClaw now stops an oversized Ollama stream record with an actionable error instead of retaining unbounded response data in memory. Normal multi-record Ollama responses continue to stream as before.
Evidence
AI-assisted.
Premise: Ollama documents streamed REST responses as newline-delimited JSON with the
application/x-ndjsoncontent type: https://docs.ollama.com/api/streaming. A request timeout does not bound a continuously arriving record that never reaches its newline delimiter.Real machine / production-path proof used Linux 6.8.0-134-generic x86_64, Node v24.18.0, a real localhost
node:httpserver exposing/api/chat, and the exported productioncreateOllamaStreamFn. The server sent one 20 MiB JSON record in 1 MiB writes. The same temporary harness was run with:Negative control / before, latest
upstream/main(d6fc3d34e2010997d4f67807b30c336347808f31) in a detached worktree: the client accepted the complete 20,971,644-byte record and returned itsokcontent.{"node":"v24.18.0","recordBytes":20971644,"bytesWritten":20971645,"responseClosed":true,"terminal":{"type":"done","content":[{"type":"text","text":"ok"}]}}After, commit
296d1e03: the same production path stopped at the 16 MiB record cap, surfaced the overflow, and closed the live HTTP response before the server finished its payload.{"node":"v24.18.0","recordBytes":20971644,"bytesWritten":19923066,"responseClosed":true,"terminal":{"type":"error","errorMessage":"Ollama NDJSON record exceeds 16777216 bytes"}}Focused regression and controls:
The focused tests prove overflow cancels the reader and that two separate 9 MiB newline-delimited records do not trip a total-stream cap. Targeted oxfmt, oxlint, and
git diff --checkalso passed.autoreview --mode local --stream-engine-outputreported no accepted/actionable findings (patch correct, confidence 0.96).Not tested: a live Ollama daemon/model or remote host; the real HTTP proof uses an Ollama-compatible localhost endpoint so it can deterministically exercise the malformed-record condition without model credentials.