Repository navigation
fix(ollama): bound native streaming 200 success-body NDJSON reads at 16 MiB - #99585
wangmiao0668000666 wants to merge 1 commit into
Conversation
|
Codex review: needs maintainer review before merge. Reviewed July 9, 2026, 8:03 AM ET / 12:03 UTC. Summary PR surface: Source +100, Tests +230. Total +330 across 5 files. Reproducibility: yes. Source inspection on current main shows both native Ollama success-stream readers append decoded chunks into unbounded buffers before newline framing, and the PR body adds loopback oversized-stream proof for the fixed behavior. Review metrics: 2 noteworthy metrics.
Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Next step before merge
Maintainer decision needed
Security Review detailsBest possible solution: Land the plugin-local bounded-reader fix after maintainers accept the 16 MiB Ollama fail-fast boundary, and handle any future shared helper/API promotion in a separate dedicated Plugin SDK PR. Do we have a high-confidence way to reproduce the issue? Yes. Source inspection on current main shows both native Ollama success-stream readers append decoded chunks into unbounded buffers before newline framing, and the PR body adds loopback oversized-stream proof for the fixed behavior. Is this the best way to solve the issue? Yes, with a maintainer compatibility call. Wrapping the readers before parser accumulation is the narrow fix, and v2 avoids publishing a new Plugin SDK subpath while leaving shared API promotion for a separate PR. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against c9b3358d43f7. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +100, Tests +230. Total +330 across 5 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
Review history (4 earlier review cycles)
|
|
@clawsweeper re-review Sibling fix added in commit 89d3d52ff0: extensions/ollama/src/setup.ts:254 (Ollama model-pull NDJSON path) had the same unbounded Changes in this re-review:
|
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
@vincentkoc ready for your look on this one. This PR now bounds both first-party Ollama native NDJSON success consumers at 16 MiB:
Both use the same State:
The only P1 left is your call (per ClawSweeper): explicitly accept or reject
If you would rather not add a new public SDK subpath right now, I can drop the SDK promotion and inline-import Thanks! |
89d3d52 to
e4d3bff
Compare
|
@clawsweeper re-review Just rebased onto latest Code itself is unchanged. The rebase only refreshed metadata hashes;
Rating regression observed. History went 🦐 → 🐚 → 🦞 → 🐚. The 🦞 → 🐚 step happened ~7 minutes after my force-push (02:44) with no new comment from ClawSweeper — looks like a QA Smoke CI failure is not PR-side. Job failed with |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
@clawsweeper re-review |
…16 MiB (v2, no SDK subpath) Version 2 of openclaw#99585 — removes the Plugin SDK subpath (`openclaw/plugin-sdk/stream-reader-with-limit`) based on ClawSweeper feedback (merge-risk: compatibility). Changes: - Bounds Ollama chat (/api/chat) NDJSON success-stream reads at 16 MiB with reader cancellation on overflow - Bounds Ollama model-pull (/api/pull) NDJSON success-stream reads at 16 MiB with reader cancellation on overflow - Plugin-local `createSseByteGuard` helper in `extensions/ollama/src/sse-byte-guard.ts` (internal seam, no new SDK subpath) - Full test coverage: deterministic overflow, negative control, real TCP loopback proof - No new Plugin SDK entrypoint, no config/env changes, no public API changes Diff: +249/-4 across 5 files (4 modified + 1 new)
5d5818d to
d54968a
Compare
|
@clawsweeper re-review This is a significant v2 change — the PR was rewritten to use a plugin-local seam instead of a new Plugin SDK subpath, addressing the previous Changes from v1 to v2:
Files now touched:
Branch updated: |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
Closing this PR to re-prioritize the active queue; the surface is partially covered by merged siblings and a smaller follow-up can reopen the unique part if still needed. Why closing now:
Supported alternative: if a maintainer confirms the ollama-local 16 MiB bound is still needed on top of the proxy-layer coverage, I will reopen a smaller PR scoped to just the local bound (no SDK surface change) based on the latest What evidence would change this decision: a maintainer asking to keep it open, or proof that |
What Problem This Solves
Two sibling sites in
extensions/ollama/src/accumulate an unbounded NDJSON byte stream into a string buffer while waiting for\nline delimiters. The companion error-body path was bounded at 8 KiB by an earlier PR; the symmetric 200 success-body paths were left open. A hostile, buggy, or misconfigured Ollama-compatible endpoint can cause OpenClaw to grow the string buffer until the gateway OOMs.Site 1 (chat, /api/chat):
extensions/ollama/src/stream.ts(parseNdjsonStream) — used by every native Ollama chat / tool-call flow.Site 2 (model download, /api/pull):
extensions/ollama/src/setup.ts— used byensureOllamaModelPulledfor pulling Ollama model blobs.Why This Change Was Made
Both sites now wrap their
ReadableStreamDefaultReaderwith a plugin-localcreateSseByteGuardthat tracks accumulated bytes against a 16 MiB cap and cancels the reader on overflow. The helper (extensions/ollama/src/sse-byte-guard.ts) is a plugin-local seam; the canonical implementation lives inpackages/ai/src/utils/streaming-byte-guard.tsand will be promoted to a Plugin SDK subpath in a future PR.User Impact
Ollama streaming body exceeded 16777216 bytes (received <size>)(chat) andOllama pull body exceeded 16777216 bytes (received <size>)(model download) when a streaming endpoint emits >16 MiB before newline-delimited framing.Evidence
Real behavior proof
Three-runs of the inline
bounds real TCP-streamed NDJSON body without content-lengthtest (Layer 3 inline loopback):Invariant holds:
receivedBytes > cap > totalRead,bytesSent > totalRead.Inline test coverage (4 tests across 2 test files)
stream-runtime.test.ts(3 tests): deterministic overflow via 32 × 1 MiB pull stream; negative control with small valid NDJSON; real TCP loopback proofsetup.test.ts(1 test): bounds oversized pull body and cancels the streamTypecheck & lint
Clean via
tsgo:core.Risk checklist
Closes / siblings