Skip to content

fix(web-shared): bound response.text() fallback to honor maxBytes - #99884

Merged
steipete merged 6 commits into
openclaw:mainfrom
zenglingbiao:fix/mcp-http-fetch-bounded-text
Jul 6, 2026
Merged

steipete merged 6 commits into
openclaw:mainfrom
zenglingbiao:fix/mcp-http-fetch-bounded-text

Conversation

@zenglingbiao

@zenglingbiao zenglingbiao commented Jul 4, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

readResponseText enforces maxBytes while reading a Web ReadableStream, but its fallback methods called arrayBuffer() or text(). Both methods materialize the entire body before returning, so truncating their result cannot provide the requested memory bound.

Why This Change Was Made

When a byte cap is requested and the response has no readable stream, the helper now fails closed without invoking either whole-body fallback. It returns an empty, truncated result; a native bodyless Response remains an empty, non-truncated result. Uncapped callers retain the existing arrayBuffer() and text() compatibility paths, with UTF-8 byte accounting for text-only response-like objects.

This keeps the public helper's maxBytes contract honest: capped calls either read a bounded stream or avoid an unbounded allocation.

User Impact

Normal Fetch responses continue through the bounded stream path. Nonstandard or mocked response-like objects without a readable stream no longer risk an unbounded whole-body allocation when a caller asks for a cap; callers receive the existing truncated signal instead.

Evidence

  • Regression coverage asserts that neither arrayBuffer() nor text() is called when maxBytes is set without a bounded stream source.
  • A native 204/bodyless response remains an empty, non-truncated result.
  • The uncapped text-only fallback still works and reports UTF-8 bytes for multibyte text.
  • Focused worktree fallback passed 45 tests across web-shared, web-fetch.cf-markdown, and web-tools.fetch; the fixtures now use native streaming Response objects.
  • Fresh full-branch autoreview on exact head 0db4df3fbc85bc4c0e05506569524985f836c28d: no accepted/actionable findings.
  • Exact-head scheduled CI 28829746771 passed 43/43 jobs.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Jul 4, 2026
@clawsweeper

clawsweeper Bot commented Jul 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 6, 2026, 6:45 PM ET / 22:45 UTC.

Summary
The branch changes shared web response reading to fail closed for capped non-stream fallback responses and updates web-fetch tests to use native streaming Response fixtures.

PR surface: Source +10, Tests +17. Total +27 across 4 files.

Reproducibility: yes. source-reproducible. Current main and v2026.6.11 can fall through to whole-body arrayBuffer() or text() after a maxBytes request when no readable stream is available; I did not run a live repro in this read-only review.

Review metrics: 1 noteworthy metric.

  • Exported fallback branch changed: 1 changed. readResponseText is exported through web-provider SDK barrels, so fallback behavior is plugin-visible and worth maintainer attention before merge.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🦞 diamond lobster
Result: blocked until real behavior proof from a real setup is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P2] Add or link a short redacted terminal/live-output transcript or logs exercising the capped no-stream fallback and native bodyless response case on the latest head.
  • [P1] After proof is added, update the PR body or ask for a fresh ClawSweeper re-review so the stale needs-proof label can be re-evaluated.

Proof guidance:

  • [P1] Needs real behavior proof before merge: The visible proof is focused tests, CI/release-gate evidence, and a maintainer proof summary; add or link a redacted terminal/live-output transcript or logs for the capped no-stream and native bodyless cases before clearing the external-PR proof gate. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Risk before merge

  • [P1] The fail-closed branch intentionally changes behavior for capped response-like objects without readable streams; plugin/provider code using the SDK-exported helper may now receive an empty truncated result instead of fallback text.
  • [P1] The live PR still carries a needs-proof label and one failed default PR CI shard even though the maintainer-linked exact-head release gate succeeded; maintainers should reconcile those gates before merge.

Maintainer options:

  1. Accept fail-closed capped fallback (recommended)
    Keep the latest behavior so capped calls without a bounded stream return an empty truncated result instead of invoking whole-body fallbacks.
  2. Preserve fallback compatibility first
    Revise the helper to keep a documented compatibility path only if maintainers decide existing response-like fallback behavior is more important than strict memory bounding.
  3. Pause for SDK contract review
    Hold the PR if the exported helper contract needs broader provider/plugin owner agreement before changing fallback behavior.

Next step before merge

  • [P1] No automated repair is queued because the latest head has no supported code finding; remaining work is maintainer merge handling for compatibility, proof, and check state.

Security
Cleared: No concrete security or supply-chain regression was found; the diff changes a shared response-reading helper and tests without new dependencies, workflows, permissions, secrets, or install scripts.

Review details

Best possible solution:

Keep the shared fail-closed bounded-read contract if maintainers accept the plugin-visible compatibility change, then clear proof/check state before landing.

Do we have a high-confidence way to reproduce the issue?

Yes, source-reproducible. Current main and v2026.6.11 can fall through to whole-body arrayBuffer() or text() after a maxBytes request when no readable stream is available; I did not run a live repro in this read-only review.

Is this the best way to solve the issue?

Yes, with maintainer acceptance of the compatibility change. Failing closed before whole-body fallbacks is the narrowest maintainable fix for the memory-bound contract, and the PR preserves uncapped fallback behavior.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 8d469711294a.

Label changes

Label justifications:

  • P2: This is a normal-priority bounded-read bug fix in a shared web helper with limited blast radius and no active outage evidence.
  • merge-risk: 🚨 compatibility: The diff changes capped fallback behavior for response-like objects without readable streams, and the helper is exported through plugin SDK web-provider surfaces.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦞 diamond lobster.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The visible proof is focused tests, CI/release-gate evidence, and a maintainer proof summary; add or link a redacted terminal/live-output transcript or logs for the capped no-stream and native bodyless cases before clearing the external-PR proof gate. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +10, Tests +17. Total +27 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 1 11 1 +10
Tests 3 94 77 +17
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 105 78 +27

What I checked:

  • Current main fallback path: Current main normalizes positive maxBytes and uses the bounded stream path only when body.getReader exists; otherwise it can still call whole-body arrayBuffer() and text() fallbacks. (src/agents/tools/web-shared.ts:300, 8d469711294a)
  • Latest release still has fallback gap: The latest release tag v2026.6.11 has the same arrayBuffer() and text() fallback sequence after the bounded stream path, so the fix is not already shipped. (src/agents/tools/web-shared.ts:297, e085fa1a3ffd)
  • PR head fail-closes capped fallback: At PR head, readResponseText returns empty truncated output before arrayBuffer() or text() when a positive maxBytes is set and no bounded stream source is available, while treating native bodyless responses as empty and non-truncated. (src/agents/tools/web-shared.ts:300, 570736cc6494)
  • Regression coverage: The PR adds tests for capped response-like objects not invoking arrayBuffer()/text(), native bodyless responses, and uncapped UTF-8 byte accounting. (src/agents/tools/web-shared.test.ts:150, 570736cc6494)
  • Runtime caller: web_fetch uses readResponseText for non-OK error detail bodies and successful response bodies with configured byte caps. (src/agents/tools/web-fetch.ts:628, 8d469711294a)
  • Plugin-visible export: readResponseText is exported from the web fetch and web search plugin SDK helper barrels, making fallback behavior compatibility-sensitive for provider/plugin code. (src/plugin-sdk/provider-web-fetch.ts:15, 8d469711294a)

Likely related people:

  • steipete: Peter Steinberger introduced the bounded web-fetch response helper in 166cf6a, is assigned to this PR, authored the latest fail-closed and streaming-fixture commits, and posted the maintainer proof comment. (role: introduced bounded behavior and likely follow-up owner; confidence: high; commits: 166cf6a3e04c, 3bb967d11507, 570736cc6494; files: src/agents/tools/web-shared.ts, src/agents/tools/web-fetch.ts, src/agents/tools/web-shared.test.ts)
  • amknight: Alex Knight authored merged PR fix: decode web fetch legacy charsets #73513, which changed the same web-shared decoding helper and adjacent web fetch tests. (role: recent adjacent contributor; confidence: medium; commits: d4822a83afb3, a6943a0208c8; files: src/agents/tools/web-shared.ts, src/agents/tools/web-tools.fetch.test.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
Review history (10 earlier review cycles; latest 8 shown)
  • reviewed 2026-07-04T08:31:52.107Z sha cd5f3bd :: needs changes before merge. :: [P1] Avoid calling text() on capped fallback responses | [P2] Measure the fallback cap in bytes
  • reviewed 2026-07-04T08:59:18.506Z sha 8d5b5df :: needs changes before merge. :: [P1] Avoid text() when enforcing a byte cap
  • reviewed 2026-07-04T09:05:08.829Z sha 8d5b5df :: found issues before merge. :: [P1] Avoid text() when enforcing a byte cap
  • reviewed 2026-07-04T09:34:48.681Z sha 558116c41bf011c73b615242780527ebf950132e :: needs real behavior proof before merge. :: [P1] Avoid text() before enforcing maxBytes
  • reviewed 2026-07-04T09:52:15.654Z sha 558116c41bf011c73b615242780527ebf950132e :: found issues before merge. :: [P1] Avoid text() before enforcing maxBytes
  • reviewed 2026-07-04T12:02:32.414Z sha 558116c41bf011c73b615242780527ebf950132e :: found issues before merge. :: [P1] Avoid text() before enforcing maxBytes
  • reviewed 2026-07-06T22:01:00.936Z sha 3bb967d115070c24bf56a888b1cf55dd0a3ba439 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-06T22:37:06.371Z sha 570736cc6494f888f56e5f36c76d3671cd5f3f38 :: needs real behavior proof before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. labels Jul 4, 2026
@zenglingbiao
zenglingbiao force-pushed the fix/mcp-http-fetch-bounded-text branch from 8f53e90 to 5eb780a Compare July 4, 2026 08:16
@zenglingbiao zenglingbiao changed the title fix(mcp-http): bound foreign response text() reads to prevent OOM fix(web-shared): bound response.text() fallback to honor maxBytes Jul 4, 2026
@zenglingbiao
zenglingbiao force-pushed the fix/mcp-http-fetch-bounded-text branch from 5eb780a to cd5f3bd Compare July 4, 2026 08:23
@zenglingbiao

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 4, 2026
@zenglingbiao

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. label Jul 4, 2026
@zenglingbiao

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@zenglingbiao

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jul 4, 2026
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Jul 6, 2026
@steipete

steipete commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

Maintainer land-ready proof

Reviewed exact head: 0db4df3fbc85bc4c0e05506569524985f836c28d

The original patch truncated only after text() had materialized the full response. The final implementation instead requires a bounded stream whenever maxBytes is requested; without one it fails closed and invokes neither whole-body fallback. Native bodyless responses remain empty/non-truncated, and uncapped compatibility still reports accurate UTF-8 byte counts.

Evidence:

  • Focused fallback proof: node scripts/run-vitest.mjs src/agents/tools/web-shared.test.ts src/agents/tools/web-fetch.cf-markdown.test.ts src/agents/tools/web-tools.fetch.test.ts — 3 files, 45 tests passed.
  • The first exact gate exposed text-only fake response objects. The fixtures now use native streaming Response objects, including a byte-body case that keeps Content-Type genuinely absent; the previously failing checks-node-agentic-agents-tools shard is green.
  • Exact-head scheduled CI: https://github.com/openclaw/openclaw/actions/runs/28829746771 — 43/43 jobs successful.
  • Fresh structured autoreview on the rebased complete branch: no accepted/actionable findings; overall correctness confidence 0.86.

Review commands:

  • git diff --check origin/main...0db4df3fbc85bc4c0e05506569524985f836c28d
  • .agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main --engine codex --model gpt-5.5 --thinking high
  • scripts/pr review-validate-artifacts 99884

Sanitized direct AWS Crabbox was unavailable because the broker returned HTTP 500 code 1101. No contributor code ran on a credential-hydrated Testbox; exact-head scheduled CI is the execution proof backend.

Best-fix judgment: the shared helper is the right owner because all capped callers need the same pre-read contract. Post-read slicing, downstream guards, or per-caller fallbacks would retain or duplicate the allocation bug. The caller set, public SDK barrels, adjacent helper, and current main behavior were audited.

No screenshot applies: this is a response-stream memory-boundary change.

zenglingbiao and others added 6 commits July 6, 2026 18:50
readResponseText's .text() fallback path ignored the maxBytes option,
reading the full body unbounded. When a foreign Response lacks a body
stream (no getReader) and no arrayBuffer(), the .text() call was the
last resort — but maxBytes was never applied.

- Honor maxBytes in the .text() fallback: truncate + set truncated=true
- Under-cap responses pass through unchanged
- No maxBytes set → original behavior preserved (regression safe)
Replace text.length/text.slice (character-level) with TextEncoder/
TextDecoder (byte-level) so the maxBytes cap is respected at byte
granularity, consistent with the bounded-stream path at lines 240-298.

- bytes.byteLength > maxBytes instead of text.length > maxBytes
- TextDecoder().decode(bytes.slice(0, maxBytes)) for byte-safe truncation
- bytesRead reports actual bytes, not character count
When maxBytes is set the caller expects bounded memory. The .text()
fallback path buffers the full body before any post-read check,
defeating the cap. Fail-closed by returning empty with truncated=true
instead of calling .text() unbounded.

Without maxBytes .text() is safe — the caller accepts full allocation.
The .text() fallback used text.length (characters) and text.slice
(char-level) against a byte-level maxBytes cap. Use TextEncoder/
TextDecoder for byte-accurate comparison and truncation.

- bytes.byteLength > maxBytes instead of text.length > maxBytes
- TextDecoder().decode(bytes.slice(0, maxBytes)) for byte-safe truncation
- bytesRead reports actual byte count, not character count
@steipete
steipete force-pushed the fix/mcp-http-fetch-bounded-text branch from 570736c to 0db4df3 Compare July 6, 2026 23:14
@steipete
steipete merged commit db25e9e into openclaw:main Jul 6, 2026
102 of 103 checks passed
@steipete

steipete commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 7, 2026
…enclaw#99884)

* fix(web-shared): bound response.text() fallback to honor maxBytes

readResponseText's .text() fallback path ignored the maxBytes option,
reading the full body unbounded. When a foreign Response lacks a body
stream (no getReader) and no arrayBuffer(), the .text() call was the
last resort — but maxBytes was never applied.

- Honor maxBytes in the .text() fallback: truncate + set truncated=true
- Under-cap responses pass through unchanged
- No maxBytes set → original behavior preserved (regression safe)

* fix(web-shared): use byte-level truncation in .text() fallback

Replace text.length/text.slice (character-level) with TextEncoder/
TextDecoder (byte-level) so the maxBytes cap is respected at byte
granularity, consistent with the bounded-stream path at lines 240-298.

- bytes.byteLength > maxBytes instead of text.length > maxBytes
- TextDecoder().decode(bytes.slice(0, maxBytes)) for byte-safe truncation
- bytesRead reports actual bytes, not character count

* fix(web-shared): refuse unbounded .text() when maxBytes is set

When maxBytes is set the caller expects bounded memory. The .text()
fallback path buffers the full body before any post-read check,
defeating the cap. Fail-closed by returning empty with truncated=true
instead of calling .text() unbounded.

Without maxBytes .text() is safe — the caller accepts full allocation.

* fix(web-shared): byte-level truncation in .text() fallback with maxBytes

The .text() fallback used text.length (characters) and text.slice
(char-level) against a byte-level maxBytes cap. Use TextEncoder/
TextDecoder for byte-accurate comparison and truncation.

- bytes.byteLength > maxBytes instead of text.length > maxBytes
- TextDecoder().decode(bytes.slice(0, maxBytes)) for byte-safe truncation
- bytesRead reports actual byte count, not character count

* fix(web): fail closed on unbounded response fallbacks

* test(web): use streaming response fixtures

---------

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

agents Agent runtime and tooling merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants