Skip to content

fix(matrix): keep HTTP error and tool-progress truncations UTF-16 safe#102395

Merged
steipete merged 2 commits into
openclaw:mainfrom
wangmiao0668000666:fix/matrix-utf16-safe-truncation
Jul 9, 2026
Merged

fix(matrix): keep HTTP error and tool-progress truncations UTF-16 safe#102395
steipete merged 2 commits into
openclaw:mainfrom
wangmiao0668000666:fix/matrix-utf16-safe-truncation

Conversation

@wangmiao0668000666

@wangmiao0668000666 wangmiao0668000666 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Matrix truncates HTTP error bodies and long tool-progress lines by UTF-16 code-unit offsets. A raw String.prototype.slice can stop after the high surrogate of an astral character, leaving malformed text for logs and chat rendering.

Why This Change Was Made

Both Matrix-owned boundaries now use the existing truncateUtf16Safe helper from openclaw/plugin-sdk/text-utility-runtime:

  • buildHttpError keeps its 500-unit cap for parsed responses without a usable error and for invalid JSON bodies.
  • Matrix tool-progress formatting keeps its existing 299-unit prefix, trailing whitespace trim, and ... suffix.

The implementation stays inside the Matrix plugin and does not change config, protocol, public APIs, or normal short-text behavior.

User Impact

Long Matrix HTTP errors and configured long progress lines no longer acquire a dangling surrogate when an emoji crosses the truncation boundary. ASCII, BMP-only text, and text below the existing limits remain unchanged.

Evidence

  • Corrected both HTTP fixtures so the emoji's high surrogate is exactly at code-unit index 499. The tests cover valid JSON without a usable Matrix error and the invalid-JSON fallback.
  • Added production-path draft-delivery coverage for Matrix tool progress with maxLineChars: 500, which makes the Matrix-owned 299-unit cap reachable after shared progress compaction.
  • Focused fallback run after two transient Testbox provisioning 502s: node scripts/run-vitest.mjs extensions/matrix/src/matrix/sdk/event-helpers.test.ts extensions/matrix/src/matrix/monitor/handler.test.ts — 2 files, 126 tests passed.
  • git diff --check — passed.
  • Fresh structured autoreview — clean, no accepted/actionable findings; confidence 0.99.

The earlier submitted fixtures did not cross their claimed boundaries: one contained a complete surrogate pair inside the cap, and the other placed the emoji after the cap. The reviewed head replaces them with exact assertions and covers the previously untested tool-progress owner path.

@openclaw-barnacle openclaw-barnacle Bot added channel: matrix Channel integration: matrix size: XS labels Jul 9, 2026
@clawsweeper

clawsweeper Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 9, 2026, 1:12 AM ET / 05:12 UTC.

Summary
The PR replaces Matrix HTTP-error and tool-progress raw string truncation with the existing UTF-16-safe helper and adds focused Matrix regression coverage.

PR surface: Source +2, Tests +33. Total +35 across 4 files.

Reproducibility: yes. source-reproducible: current main uses raw UTF-16 slicing at both Matrix truncation boundaries, and the revised tests now place surrogate pairs exactly on the truncation boundary. I did not run a live Matrix homeserver path in this read-only review.

Review metrics: none identified.

Merge readiness
Overall: 🧂 unranked krab
Proof: 🧂 unranked krab
Patch quality: 🐚 platinum hermit
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:

  • [P1] Add redacted real behavior proof, such as a Matrix runtime transcript or a production-path terminal run that shows the fixed truncation path after this head.

Proof guidance:

  • [P1] Needs real behavior proof before merge: The PR body provides focused test output, git diff --check, and autoreview text only; the contributor should add redacted Matrix runtime or production-path terminal proof, then update the PR body to trigger re-review or ask a maintainer to comment @clawsweeper re-review.

Risk before merge

  • [P1] The real behavior proof gate remains unresolved: the PR body provides focused tests and autoreview output, but no redacted Matrix runtime transcript or production-path terminal run showing the fixed truncation path after this head.

Maintainer options:

  1. Decide the mitigation before merge
    Merge the narrow helper-based Matrix fix after the contributor adds redacted after-fix Matrix runtime or production-path terminal proof.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • [P1] Contributor follow-up is needed for the real-behavior proof gate; there is no narrow code repair for ClawSweeper to queue.

Security
Cleared: No concrete security or supply-chain concern found; the diff only changes pure Matrix string truncation calls and colocated tests.

Review details

Best possible solution:

Merge the narrow helper-based Matrix fix after the contributor adds redacted after-fix Matrix runtime or production-path terminal proof.

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

Yes, source-reproducible: current main uses raw UTF-16 slicing at both Matrix truncation boundaries, and the revised tests now place surrogate pairs exactly on the truncation boundary. I did not run a live Matrix homeserver path in this read-only review.

Is this the best way to solve the issue?

Yes for the code shape: reusing the existing UTF-16-safe SDK helper inside the Matrix plugin is the narrow owner-boundary fix and does not add config, protocol, or public API surface.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 624dfa6cf6dc.

Label changes

Label justifications:

  • P2: This is a normal-priority Matrix correctness fix with narrow user-visible text-formatting impact and limited blast radius.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body provides focused test output, git diff --check, and autoreview text only; the contributor should add redacted Matrix runtime or production-path terminal proof, then update the PR body to trigger re-review or ask a maintainer to comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +2, Tests +33. Total +35 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 5 3 +2
Tests 2 33 0 +33
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 38 3 +35

What I checked:

Likely related people:

  • shakkernerd: Current-line blame for both Matrix raw truncation sites points to commit fc05a8103b, which is authored by Shakker on GitHub. (role: introduced current behavior; confidence: medium; commits: fc05a8103b72; files: extensions/matrix/src/matrix/sdk/event-helpers.ts, extensions/matrix/src/matrix/monitor/handler.ts)
  • steipete: History shows Peter Steinberger authored the shared UTF-16 truncation helper and has the highest shortlog count across the central Matrix/helper files sampled. (role: adjacent owner; confidence: high; commits: 63f5fa47deb6; files: packages/normalization-core/src/utf16-slice.ts, src/plugin-sdk/text-utility-runtime.ts, extensions/matrix/src/matrix/monitor/handler.ts)
  • gumadeiras: History shows Matrix helper/monitor migration and review involvement near the draft-streaming path touched by the PR. (role: Matrix area contributor; confidence: medium; commits: 94693f7ff036, 7e7e45c2f3db; files: extensions/matrix/src/matrix/sdk/event-helpers.ts, extensions/matrix/src/matrix/monitor/handler.ts)
  • jrusz: The Matrix draft streaming feature that owns the tool-progress draft path was introduced in commit 7e7e45c2f3. (role: feature introducer; confidence: medium; commits: 7e7e45c2f3db; files: extensions/matrix/src/matrix/monitor/handler.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 (2 earlier review cycles)
  • reviewed 2026-07-09T03:51:05.685Z sha 166bb5b :: needs real behavior proof before merge. :: [P1] Fix the surrogate-boundary fixtures
  • reviewed 2026-07-09T03:57:16.122Z sha 166bb5b :: needs real behavior proof before merge. :: [P1] Fix the surrogate-boundary fixtures

@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 9, 2026
@steipete

steipete commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Land-ready proof for exact head 7d7aba16048596e5c6c6f8f16c72c1686a126566:

  • Replaced the submitted HTTP fixtures with exact surrogate-splitting inputs; the original fixtures did not cross the claimed 500-unit boundary.
  • Added an exact Matrix draft-delivery assertion with maxLineChars: 500, covering the configuration where the Matrix-owned 299-unit truncation is reachable after shared progress compaction.
  • Focused fallback run after two transient Testbox provisioning 502s: node scripts/run-vitest.mjs extensions/matrix/src/matrix/sdk/event-helpers.test.ts extensions/matrix/src/matrix/monitor/handler.test.ts — 2 files, 126/126 tests passed.
  • Exact-head CI run 28995531628: passed.
  • git diff --check: passed.
  • Fresh structured autoreview: clean, no accepted/actionable findings, confidence 0.99.

The reviewed implementation is the best bounded fix: existing limits and behavior remain intact, both Matrix owner paths now use the canonical helper, and no new config or compatibility path is introduced.

@steipete
steipete merged commit acac359 into openclaw:main Jul 9, 2026
98 checks passed
@steipete

steipete commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

@wangmiao0668000666

Copy link
Copy Markdown
Contributor Author

Thanks @steipete — appreciated.

This PR closes the last remaining gap in the Matrix plugin for the 2026-07 UTF-16 safe truncation wave: the 3 text-truncation sites in extensions/matrix/src/matrix/sdk/event-helpers.ts (HTTP error body) and extensions/matrix/src/matrix/monitor/handler.ts (tool-progress markdown) now use the canonical truncateUtf16Safe helper from openclaw/plugin-sdk/text-utility-runtime, joining the existing consumers across voice-call, diagnostics-otel, synology-chat, line, googlechat, memory-core, and agent-harness. Happy to extend the same pattern to the next bundled plugin that has a text-truncation site on raw .slice(0, N) whenever you want me to.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 9, 2026
openclaw#102395)

* fix(matrix): keep HTTP error and tool-progress truncations UTF-16 safe

* test(matrix): prove UTF-16 truncation boundaries

---------

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

channel: matrix Channel integration: matrix P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XS 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