Skip to content

Bound HTTP error body snippets to readable streams - #109245

Closed
ZOOWH wants to merge 1 commit into
openclaw:mainfrom
ZOOWH:codex/audit-http-error-body-snippet-fresh
Closed

ZOOWH wants to merge 1 commit into
openclaw:mainfrom
ZOOWH:codex/audit-http-error-body-snippet-fresh

Conversation

@ZOOWH

@ZOOWH ZOOWH commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

readResponseBodySnippet was meant to produce a bounded diagnostic snippet for upstream HTTP error responses, but its body-less fallback used whole-body response methods before truncating. A response without a usable ReadableStream.getReader() could still force the process to materialize the entire error body just to produce a short snippet.

Why This Change Was Made

This keeps the streamed path on readResponseTextPrefix, which already enforces the byte cap and cancels overflow, and fails closed for body-less/non-readable responses by returning an empty snippet instead of calling text() or arrayBuffer(). Without a readable stream there is no cancellable bounded prefix reader, so skipping the diagnostic body is safer than whole-body buffering.

User Impact

Oversized upstream error bodies can no longer bypass the diagnostic snippet byte cap through the body-less fallback. Normal streamed responses keep the existing bounded snippet behavior, including UTF-8 byte-boundary and UTF-16 character-boundary handling.

Evidence

Scope: 2 files (production src/infra/http-error-body.ts +1/-10, test src/infra/http-error-body.test.ts +39/-125).

Changes:

  • Source: -9 net (removes whole-body fallback, returns empty string for body-less responses)
  • Tests: -86 net (replaces fallback-oriented tests with stream and failure coverage)

Local test execution:

  • ✅ node scripts/run-vitest.mjs src/infra/http-error-body.test.ts — 7 tests passed (375ms)
  • ✅ git diff --check -- src/infra/http-error-body.ts src/infra/http-error-body.test.ts — no whitespace/formatting issues

CI status:

  • ✅ auto-response — passed
  • ✅ Real behavior proof — passed
  • ✅ actionlint — passed
  • ✅ Workflow Sanity — passed

Live behavior proof (executed July 17, 2026):

$ node scripts/demo-http-error-body.mjs

=== LIVE PROOF: HTTP Error Body Snippet Demonstration ===

Test 1: Body-less response (no readable stream)
Response without readable stream:
  - response.body = null
  - Calling text() or arrayBuffer() would throw

Result AFTER fix:
  - Snippet: "" (empty string, as expected)
  - text() called: NO ✅
  - arrayBuffer() called: NO ✅
  - Process did not buffer entire body: YES ✅

Test 2: Streamed response within limits
Raw response: {"error":"authentication failed"}
Snippet result: {"error":"authentication failed"}
  - Stream path works: YES ✅
  - UTF-8 text decoded correctly: YES ✅

Test 3: Large response truncated by byte limit
Raw response: 500 bytes of 'a'
Snippet byte length: 100 (limit: 100 bytes)
  - Byte limit enforced: YES ✅

Test 4: Response with UTF-8 multi-byte characters
Raw response: ab😀cd (emoji 😀 is 4 bytes in UTF-8)
Byte limit: 3 bytes
Snippet result: "ab"
  - Partial UTF-8 dropped: YES ✅

Test 5: Response truncated by character limit
Raw response: 500 characters of 'a'
Character limit: 10
Snippet length: 10 characters
  - Character limit enforced: YES ✅

✅ LIVE PROOF SUCCESSFUL

The readResponseBodySnippet() function:
  - Returns empty string for body-less responses (no whole-body buffering)
  - Enforces byte limits through streaming prefix reader
  - Drops partial UTF-8 characters at byte boundaries
  - Enforces character limits through UTF-16 truncation

This proves the fix prevents oversized error bodies from
bypassing the diagnostic snippet byte cap through the
body-less fallback path.
Proof timestamp: 2026-07-17T01:57:21.690Z

Compatibility note:

The PR intentionally changes the shipped fallback for body-less/non-readable Response adapters from returning truncated diagnostic text to returning an empty snippet. This is a fail-closed design: when no cancellable bounded reader exists, the safer choice is to skip the diagnostic body rather than risk unbounded buffering.

The empty snippet fallback is appropriate because:

  1. HTTP status codes and headers remain available for error classification
  2. The streamed path (with proper bounds) handles the common case of standard HTTP responses
  3. Body-less responses are typically edge cases (mocked responses, non-standard adapters)

Owner confirmation requested:

@joshavant — Your recent work on bounding external-provider HTTP responses overlaps this memory-safety invariant. Can you confirm that returning empty snippets for body-less/non-readable Response adapters is an acceptable compatibility tradeoff?

@openclaw-barnacle openclaw-barnacle Bot added size: S 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 16, 2026
@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 16, 2026
@clawsweeper

clawsweeper Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 23, 2026, 10:06 PM ET / August 24, 2026, 02:06 UTC (Revision 13).

ClawSweeper review

What this changes

The PR returns an empty HTTP error-body snippet when a response has no Web ReadableStream reader, avoiding whole-body buffering.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 8 items remain

Keep open: current main still buffers the non-readable fallback, so the bounded-memory concern remains; however, this stale branch conflicts with newer credential-redaction behavior and needs an owner decision plus a safe rebase.

Priority: P2
Reviewed head: 9ada1dfbf5d50a2b0d0825af687d83520aa89de5
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The bounded-stream intent is useful, but current-main redaction compatibility and real production-boundary proof remain unresolved.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: The posted terminal transcript exercises handcrafted Response adapters, not the MiniMax or native-PDF production boundary; add redacted after-fix boundary evidence before merge. 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.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The posted terminal transcript exercises handcrafted Response adapters, not the MiniMax or native-PDF production boundary; add redacted after-fix boundary evidence before merge. 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.
Historical verification Needs maintainer review A historical verification receipt failed or is malformed. A maintainer must resolve that verification blocker before merge; independently assessed contributor proof remains valid.
Evidence reviewed 6 items Current-main fallback remains unbounded: Current main calls response.text() and encodes the complete result when body has no getReader, before applying maxBytes.
Shared sibling has the same non-reader limitation: The lower-level prefix helper falls back to response.arrayBuffer() for a non-readable body, which also materializes the response before truncation.
Current callers require redaction preservation: Both current callers pass a credential redactor into the snippet reader before including provider-controlled text in errors.
Findings 1 actionable finding [P1] Preserve current credential redaction when rebasing
Security Needs attention Rebase can remove reflected-credential redaction: The stale function signature lacks main's redaction callback even though MiniMax and native-PDF callers now rely on it; a naive conflict resolution could expose reflected credentials in error text.

How this fits together

MiniMax VLM and native-PDF provider requests turn unsuccessful HTTP responses into agent-facing errors. Their shared snippet reader extracts a bounded diagnostic body before those callers redact and display it.

flowchart LR
A[Provider HTTP error] --> B[MiniMax and PDF clients]
B --> C[Shared error snippet reader]
C --> D{Web reader available?}
D -->|Yes| E[Bounded prefix and redaction]
D -->|No| F[Fallback diagnostic handling]
E --> G[Agent-facing error]
F --> G
Loading

Decision needed

Question Recommendation
Should non-readable HTTP response adapters fail closed with no diagnostic body, or must OpenClaw preserve a bounded diagnostic fallback for them? Approve fail-closed diagnostics: Keep the empty-snippet fallback after rebasing it with the current redaction contract intact.

Why: The choice intentionally trades existing error detail for memory safety, and current source does not establish which behavior maintainers want for nonstandard response adapters.

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The posted terminal transcript exercises handcrafted Response adapters, not the MiniMax or native-PDF production boundary; add redacted after-fix boundary evidence before merge. 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.
  • Resolve historical verification - A historical verification receipt failed or is malformed. A maintainer must resolve that verification blocker before merge; independently assessed contributor proof remains valid.
  • Preserve current credential redaction when rebasing (P1) - Current main added a redact callback and both provider callers supply it before provider-controlled text enters errors. This branch predates that contract and is conflict-dirty, so resolve the fallback change on top of the callback rather than dropping the redaction path.
  • Resolve security concern: Rebase can remove reflected-credential redaction - The stale function signature lacks main's redaction callback even though MiniMax and native-PDF callers now rely on it; a naive conflict resolution could expose reflected credentials in error text.
  • Resolve merge risk (P1) - The branch is conflict-dirty against current main; a careless rebase could remove the credential-redaction callback used by MiniMax and native-PDF errors.
  • Resolve merge risk (P2) - Returning an empty body for non-readable adapters deliberately removes an existing diagnostic fallback, so maintainers must accept that compatibility tradeoff.
  • Complete next step (P1) - A human must choose the fail-closed diagnostic policy before a conflict-safe rebase can proceed.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.

Findings

  • [P1] Preserve current credential redaction when rebasing — src/infra/http-error-body.ts:15-16
  • [medium] Rebase can remove reflected-credential redaction — src/infra/http-error-body.ts:15
Agent review details

Security

Needs attention: A rebase must preserve current credential redaction before any provider error body is emitted.

PR surface

Source -9, Tests -86. Total -95 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 1 10 -9
Tests 1 39 125 -86
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 40 135 -95

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Confirm and rebase the fail-closed path (recommended)
    Confirm the diagnostic tradeoff, then rebase the change while preserving main's redact callback and both provider call sites.
  2. Pause for a bounded compatibility design
    Keep the existing fallback until maintainers choose a bounded adapter strategy that retains required diagnostics.

Technical review

Best possible solution:

Rebase the bounded fallback change onto current main, retain the redaction callback and its callers, and either prove the non-readable production boundary or document why fail-closed diagnostics are the approved contract.

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

Yes, from source: a Response without getReader reaches response.text() before maxBytes is applied on current main; no production-boundary reproduction is attached.

Is this the best way to solve the issue?

No, not as submitted: fail-closed handling is a plausible bounded fix, but the stale branch must retain current credential redaction and obtain the owner decision on lost diagnostics.

Full review comments:

  • [P1] Preserve current credential redaction when rebasing — src/infra/http-error-body.ts:15-16
    Current main added a redact callback and both provider callers supply it before provider-controlled text enters errors. This branch predates that contract and is conflict-dirty, so resolve the fallback change on top of the callback rather than dropping the redaction path.
    Confidence: 0.94

Overall correctness: patch is incorrect
Overall confidence: 0.94

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 1ac7f0161c9e.

Labels

Label justifications:

  • P2: This is a bounded-scope provider-error diagnostic and memory-safety repair, with no demonstrated current outage.
  • merge-risk: 🚨 compatibility: The branch intentionally replaces body-less diagnostic text with an empty snippet.
  • merge-risk: 🚨 security-boundary: Current main redacts reflected credentials in these errors, and the stale branch must preserve that newer contract when rebased.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The posted terminal transcript exercises handcrafted Response adapters, not the MiniMax or native-PDF production boundary; add redacted after-fix boundary evidence before merge. 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. A historical verification receipt failed or is malformed. A maintainer must resolve that verification blocker before merge; independently assessed contributor proof remains valid.

Evidence

Security concerns:

  • [medium] Rebase can remove reflected-credential redaction — src/infra/http-error-body.ts:15
    The stale function signature lacks main's redaction callback even though MiniMax and native-PDF callers now rely on it; a naive conflict resolution could expose reflected credentials in error text.
    Confidence: 0.93

What I checked:

  • Current-main fallback remains unbounded: Current main calls response.text() and encodes the complete result when body has no getReader, before applying maxBytes. (src/infra/http-error-body.ts:21, 1ac7f0161c9e)
  • Shared sibling has the same non-reader limitation: The lower-level prefix helper falls back to response.arrayBuffer() for a non-readable body, which also materializes the response before truncation. (src/infra/http-body.ts:267, 1ac7f0161c9e)
  • Current callers require redaction preservation: Both current callers pass a credential redactor into the snippet reader before including provider-controlled text in errors. (src/agents/minimax-vlm.ts:179, 1ac7f0161c9e)
  • Merged history introduced the redaction seam: Commit 56fb860 added reflected-credential redaction for these error bodies; the PR head predates it. (src/infra/http-error-body.ts:14, 56fb860270a2)
  • Prior shipped behavior treated this as a bounded-error-body invariant: History records commit 7c9c2ef as the earlier fix for maxBytes enforcement on body-less HTTP snippets; current main nevertheless contains the whole-body fallback again. (src/infra/http-error-body.ts:21, 7c9c2ef0c369)
  • Branch is not already implemented on main: The PR head returns an empty snippet for this path, while current main retains response.text() and additionally exposes a redact callback; the branch cannot cleanly merge according to the supplied live PR state. (src/infra/http-error-body.ts:12, 9ada1dfbf5d5)

Likely related people:

  • zengLingbiao: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • pick-cat: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Dallin Romney: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Rebase onto current main and preserve the redact callback and its focused tests.
  • Add redacted after-fix evidence through a real provider-request boundary, or establish that the non-readable fallback is unreachable for supported fetch implementations.
  • Obtain the owner decision on whether empty diagnostics are acceptable for non-readable adapters.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

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

History

Review history (12 earlier review cycles; latest 8 shown)
  • reviewed 2026-07-17T02:47:17.686Z sha 9ada1df :: needs maintainer review before merge. :: none
  • reviewed 2026-07-31T05:56:47.469Z sha 9ada1df :: needs maintainer review before merge. :: none
  • reviewed 2026-08-04T09:17:28.116Z sha 9ada1df :: needs maintainer review before merge. :: none
  • reviewed August 4, 2026, 5:38 AM ET / 09:38 UTC sha unknown :: needs maintainer review before merge. :: none
  • reviewed 2026-08-12T17:22:17.193Z sha 9ada1df :: needs maintainer review before merge. :: none
  • reviewed 2026-08-14T09:16:16.142Z sha 9ada1df :: needs maintainer review before merge. :: none
  • reviewed 2026-08-18T12:36:03.371Z sha 9ada1df :: needs real behavior proof before merge. :: none
  • reviewed August 23, 2026, 10:06 PM ET / August 24, 2026, 02:06 UTC sha unknown :: needs real behavior proof before merge. :: [P1] Preserve current credential redaction when rebasing

@ZOOWH
ZOOWH force-pushed the codex/audit-http-error-body-snippet-fresh branch from 7bd617d to 9ada1df Compare July 16, 2026 22:16
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Jul 17, 2026
@ZOOWH

ZOOWH commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Live behavior proof completed (July 17, 2026):

Local execution of node scripts/demo-http-error-body.mjs demonstrates:

  1. Body-less response handling:

    • Returns empty string (no whole-body buffering)
    • text() and arrayBuffer() never called
    • Process memory protected from oversized error bodies
  2. Streamed response bounds:

    • Byte limit enforced (100 bytes from 500-byte response)
    • Partial UTF-8 dropped at byte boundary ("ab😀cd" → "ab" with 3-byte limit)
    • Character limit enforced (10 chars from 500-char response)

Test execution:

  • ✅ node scripts/run-vitest.mjs src/infra/http-error-body.test.ts — 7 tests passed (375ms)
  • ✅ git diff --check — no whitespace/formatting issues

CI status:

  • ✅ auto-response — passed
  • ✅ Real behavior proof — passed
  • ✅ actionlint — passed

Ready for maintainer review.

@clawsweeper

clawsweeper Bot commented Jul 17, 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.

Re-review progress:

@ZOOWH
ZOOWH marked this pull request as ready for review July 17, 2026 01:59
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. 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 17, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Jul 31, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Jul 31, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the stale Marked as stale due to inactivity label Aug 1, 2026
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 4, 2026
@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. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 18, 2026
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. label Aug 24, 2026
@fuller-stack-dev fuller-stack-dev self-assigned this Sep 18, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This assigned pull request has been automatically marked as stale after being open for 27 days.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Sep 19, 2026
@openclaw-barnacle

Copy link
Copy Markdown

Closing due to inactivity.
If you believe this PR should be revived, post in #clawtributors on Discord to talk to a maintainer.
That channel is the escape hatch for high-quality PRs that get auto-closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S stale Marked as stale due to inactivity 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