Skip to content

fix(mattermost): bound null-body error response reads - #97851

Merged
vincentkoc merged 1 commit into
openclaw:mainfrom
Pick-cat:fix/mattermost-bound-error-null-body-reads
Jul 1, 2026
Merged

vincentkoc merged 1 commit into
openclaw:mainfrom
Pick-cat:fix/mattermost-bound-error-null-body-reads

Conversation

@Pick-cat

@Pick-cat Pick-cat commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

readMattermostError() had a !res.body fallback that bypassed the bounded reader and called native res.json() / res.text() directly. For a null-body error response with a JSON content-type (a 401/503 with content-type: application/json and an empty body — common from reverse proxies and gateways), await res.json() throws SyntaxError: Unexpected end of JSON input. That rejection propagates out of readMattermostError(), so the caller's intended Mattermost API <status>: unknown error is replaced by a confusing JSON-parse crash. It was also the last remaining unbounded json() / text() read in this error path after #96033 bounded the success path.

Affected surface: extensions/mattermost/src/mattermost/client.ts — readMattermostError(), reached by client.request(), the file-upload path, and probe.ts.

Why This Change Was Made

The !res.body special-case is removed entirely, so every error read goes through the existing bounded readResponseTextLimited (8 KiB) and the JSON message is parsed from that bounded text. readResponseTextLimited returns "" when there is no readable body, so a null-body response now yields an empty detail instead of throwing — and all three callers already coalesce that to a clean message (detail || "unknown error" / detail || res.statusText). One canonical read path, no second buffering strategy.

Net change is a deletion (client.ts +0/−10): removes the divergent branch rather than adding code.

User Impact

Operators and agents talking to self-hosted or misbehaving Mattermost servers get a clean, accurate API error (Mattermost API 503 Service Unavailable: unknown error) on null-body JSON error responses, instead of an internal Unexpected end of JSON input crash — and every error read now goes through the bounded reader.

Evidence

1. Real-behavior proof with a negative control (real HTTP). A harness drives the real exported readMattermostError and the real createMattermostClient().request() (through the real fetchWithSsrFGuard SSRF path, allowPrivateNetwork: true for localhost) against a real node:http server returning 503 Service Unavailable with content-type: application/json and no body. The negative control runs the deleted branch's exact logic (await res.json()) on the same response.

$ tsx mm-proof.mts
Server returns 503 Service Unavailable, content-type application/json, NO body

[NEGATIVE CONTROL] old `!res.body` json branch: await res.json()
PASS: old branch crashes on null-body JSON error — THREW SyntaxError: Unexpected end of JSON input

[WITH FIX] readMattermostError(real null-body 503 json response)
PASS: returns empty string, no throw — detail=""

[WITH FIX] createMattermostClient().request() against null-body 503
PASS: clean bounded API error (no JSON crash) — "Mattermost API 503 Service Unavailable: unknown error"

ALL PROOF ASSERTIONS PASSED

Without the fix the null-body JSON error path throws SyntaxError: Unexpected end of JSON input; with the fix readMattermostError returns "" and the client surfaces the clean ... 503 Service Unavailable: unknown error.

2. Committed regression tests (extensions/mattermost/src/mattermost/client.test.ts) cover: null-body JSON errors never call response.json() / response.text(); bounded JSON message fields still parse from normal bodies; and a guarded null-body failure surfaced end-to-end through createMattermostClient().request().

$ node scripts/run-vitest.mjs extensions/mattermost/src/mattermost/client.test.ts
 Test Files  1 passed (1)
      Tests  27 passed (27)

3. Lint on the changed file:

$ node scripts/run-oxlint.mjs extensions/mattermost/src/mattermost/client.ts   # exit 0

What was NOT tested: I did not run against a live production Mattermost server. The null-body JSON error condition is reproduced with a real local HTTP server over the real SSRF-guarded fetch path, including the negative control showing the pre-fix crash.

AI-assisted: implementation, tests, and the proof harness were drafted with agent assistance; all commands above were run locally.

@openclaw-barnacle openclaw-barnacle Bot added channel: mattermost Channel integration: mattermost size: S labels Jun 29, 2026
@clawsweeper

clawsweeper Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed June 29, 2026, 12:16 PM ET / 16:16 UTC.

Summary
The branch removes Mattermost readMattermostError()'s null-body native json()/text() branch and adds regression tests for empty-body JSON errors and guarded client error handling.

PR surface: Source -10, Tests +56. Total +46 across 2 files.

Reproducibility: yes. source-reproducible: current main calls res.json() on a null-body JSON error response, and a focused Node fetch probe shows that call throws SyntaxError. The PR body also includes terminal negative-control proof and after-fix output.

Review metrics: none identified.

Stored data model
Persistent data-model change detected: serialized state: extensions/mattermost/src/mattermost/client.test.ts, serialized state: extensions/mattermost/src/mattermost/client.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: canonical
Canonical: #97851
Summary: This is the current open canonical branch for the Mattermost null-body error-reader cleanup; the older same-title branch is closed unmerged, and the merged success-read hardening PR is adjacent.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🦞 diamond lobster
Proof: 🦞 diamond lobster
Patch quality: 🦞 diamond lobster
Result: ready for maintainer review.

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

Next step before merge

  • [P2] No repair lane is needed because the exact-head PR has no actionable findings; existing automerge should gate mergeability and checks.

Security
Cleared: Cleared: the diff removes an alternate native body-reader path and adds focused tests without dependency, workflow, permission, package, or secret-handling changes.

Review details

Best possible solution:

Land this narrow branch through the existing automerge or maintainer gates so current main returns to one bounded Mattermost error-reader path.

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

Yes, source-reproducible: current main calls res.json() on a null-body JSON error response, and a focused Node fetch probe shows that call throws SyntaxError. The PR body also includes terminal negative-control proof and after-fix output.

Is this the best way to solve the issue?

Yes. Removing the null-body special case is the narrowest maintainable fix because it reuses the existing bounded reader and avoids adding a second catch-or-buffering path.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 6de357ad4772.

Label changes

Label changes:

  • add status: 🚀 automerge armed: This PR is in ClawSweeper's automerge lane. Sufficient (terminal): Sufficient terminal proof: the PR body shows a real local HTTP server negative control for the deleted json() branch and the fixed exported Mattermost client path returning a clean API error.
  • remove status: 👀 ready for maintainer look: Current PR status label is status: 🚀 automerge armed.

Label justifications:

  • P2: This is normal-priority Mattermost plugin hardening with limited blast radius and no evidence of a widespread broken workflow.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 🚀 automerge armed: This PR is in ClawSweeper's automerge lane. Sufficient (terminal): Sufficient terminal proof: the PR body shows a real local HTTP server negative control for the deleted json() branch and the fixed exported Mattermost client path returning a clean API error.
  • proof: sufficient: Contributor real behavior proof is sufficient. Sufficient terminal proof: the PR body shows a real local HTTP server negative control for the deleted json() branch and the fixed exported Mattermost client path returning a clean API error.
Evidence reviewed

PR surface:

Source -10, Tests +56. Total +46 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 0 10 -10
Tests 1 56 0 +56
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 56 10 +46

What I checked:

Likely related people:

  • Alix-007: Current-line blame and the merged Mattermost success-response hardening work both touch the same client and test surface this PR follows up on. (role: recent adjacent response-limit contributor; confidence: high; commits: 5f86c3a90f69, 9241b9701d9c; files: extensions/mattermost/src/mattermost/client.ts, extensions/mattermost/src/mattermost/client.test.ts)
  • jacobtomlinson: Merged the SSRF guarded-fetch change that added Mattermost response wrapping and null-body status handling around this client path. (role: introduced guarded client response path; confidence: high; commits: f92c92515bd4; files: extensions/mattermost/src/mattermost/client.ts, extensions/mattermost/src/mattermost/probe.ts)
  • damoahdominic: Introduced the Mattermost plugin surface and extracted the client module into extensions/mattermost. (role: original feature contributor; confidence: medium; commits: 495a39b5a989, fac21e6eb4d7; files: extensions/mattermost/src/mattermost/client.ts, extensions/mattermost/src/mattermost/probe.ts, docs/channels/mattermost.md)
  • sallyom: Live PR metadata shows they merged the adjacent Mattermost response-limit PR, which is useful routing context for this follow-up. (role: reviewer and merger of adjacent hardening; confidence: medium; commits: 9241b9701d9c; files: extensions/mattermost/src/mattermost/client.ts, extensions/mattermost/src/mattermost/client.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.

@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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor 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 Jun 29, 2026
@Takhoffman

Copy link
Copy Markdown
Contributor

@clawsweeper automerge

@clawsweeper

clawsweeper Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper automerge is enabled.

  • Head: cca9f191a936
  • Label: clawsweeper:automerge
  • Action: exact-head review queued (workflow sweep.yml, event repository_dispatch).
  • Flow: review this head, repair/rebase only if needed, then re-review the exact repaired head before merge.

Draft PRs stay fix-only until GitHub marks them ready for review. Pause with /clawsweeper stop.

Automerge progress:

  • 2026-06-29 16:08:10 UTC review queued cca9f191a936 (queued)

@clawsweeper clawsweeper Bot added clawsweeper:automerge Maintainer opted this PR into bounded ClawSweeper-reviewed automerge status: 🚀 automerge armed This PR is in ClawSweeper's automerge lane. clawsweeper:human-review Needs maintainer review before ClawSweeper can continue and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jun 29, 2026
@clawsweeper

clawsweeper Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

🦞✅
ClawSweeper is pausing this repair loop for human review.

Source: clawsweeper[bot]
Reason: - [P2] No repair lane is needed because the exact-head PR has no actionable findings; existing automerge should gate mergeability and checks.; Cleared: Cleared: the diff removes an alternate native body-reader path and adds focused tests without dependency, workflow, permission, package, or secret-handling changes. (sha=cca9f191a93649d20f5179cd09d41ed2411848a7)

Why human review is needed:
This item has security-sensitive risk. ClawSweeper is pausing instead of making an autonomous change that could affect trust, credentials, permissions, or exposure.

What the maintainer can do as a next step:
If the maintainer accepts the current risk and wants ClawSweeper to continue merge gates, comment @clawsweeper approve. If the security-sensitive detail still needs changes, describe the safe path or push the fix, then comment @clawsweeper automerge. If the risk should not be automated, keep the PR paused for manual review or comment @clawsweeper stop.

I added clawsweeper:human-review and left the final call with a maintainer.

@vincentkoc
vincentkoc merged commit 54d2fa2 into openclaw:main Jul 1, 2026
408 of 470 checks passed
chenyangjun-xy pushed a commit to chenyangjun-xy/openclaw that referenced this pull request Jul 1, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 2, 2026
Rorqualx pushed a commit to Rorqualx/cortex that referenced this pull request Jul 8, 2026
Rorqualx pushed a commit to Rorqualx/cortex that referenced this pull request Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: mattermost Channel integration: mattermost clawsweeper:automerge Maintainer opted this PR into bounded ClawSweeper-reviewed automerge clawsweeper:human-review Needs maintainer review before ClawSweeper can continue P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S status: 🚀 automerge armed This PR is in ClawSweeper's automerge lane.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants