Skip to content

fix(matrix): preserve escaped characters, links, and image labels - #128382

Merged
steipete merged 1 commit into
mainfrom
codex/autoqa-matrix-marker-collision-20260823
Aug 24, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/autoqa-matrix-marker-collision-20260823

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where Matrix users sending messages with private-use Unicode characters, escaped mentions, links, or image fallback labels would see corrupted text, broken destinations, leaked formatting markers, or <> instead of the intended characters.

Three symptoms shared the same Markdown token-ownership boundary:

  • A fixed escaped-mention marker collided with literal and numerically encoded private-use characters, replacing real message content with @.
  • Escaped mentions were incorrectly masked inside link destinations and left unresolved in nested image-label tokens.
  • Markdown image-label escapes and character entities became <> because special text tokens had no renderer.

Why This Change Was Made

The Matrix formatter now lazily reserves a collision-free marker using its existing private-marker owner, keeps Markdown link metadata outside mention masking, restores owned markers in nested tokens, and HTML-escapes special image-label text through the normal renderer. The change stays within private Matrix formatting; mention notification policy, authorization, public interfaces, configuration, and persistence do not change.

The production delta is +16 lines because marker ownership must follow each individual message through ordinary text, block code, links, and nested image tokens; this replaces the unsafe global marker and reuses the existing collision-aware allocator and Markdown metadata-range owner instead of adding parallel formatting paths.

User Impact

Matrix messages preserve their actual characters, escaped mentions remain visible without triggering notifications, link destinations stay intact, and image fallback labels display decoded entities and escaped punctuation correctly.

Examples verified against the real production renderer:

  • Literal or encoded private-use characters remain unchanged instead of becoming @.
  • An escaped mention inside an image label renders as @room instead of exposing a private formatting marker.
  • A link containing an escaped @ keeps its /@alice destination instead of being rewritten to a percent-encoded marker.
  • Image labels containing &#65;, private-use entities, or \*literal render as A, the intended Unicode character, or *literal instead of <>.

Evidence

  • Three authentic regression stages reproduced 10, 3, and 3 failing owner-boundary cases before their respective fixes.
  • Exact committed head: e39fa7ae429d32536481d2b50cb0decfa2bc7289.
  • 213 passing owner and sibling tests across Matrix formatting, outbound delivery, media, drafts, replies, and threaded media.
  • Separate independent review: 583 passing tests and 2,700 actual production-renderer scenarios covering literal/decimal/hexadecimal private-use characters, escaped mentions, links, images, spoilers, self/room mentions, and HTML escaping.
  • Exhausted-pool proof: all 6,400 private-use characters survive unchanged when a message contains no escaped mention.
  • Fresh authenticated full committed-branch review: clean; secret scan: clean.
  • Targeted formatting, lint, max-lines ratchet, assertion-safety ratchet, plugin-boundary/dependency guards, and five doctor-contract checks pass.
  • The local full extension type lanes currently report only the independently verified, unchanged ACPX dependency-skew diagnostics already present on current main; there are zero Matrix diagnostics.

@clawsweeper

clawsweeper Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added channel: matrix Channel integration: matrix size: S maintainer Maintainer-authored PR labels Aug 23, 2026
@steipete
steipete marked this pull request as ready for review August 23, 2026 21:58
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 23, 2026
@clawsweeper

clawsweeper Bot commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 23, 2026, 6:48 PM ET / 22:48 UTC.

ClawSweeper review

What this changes

The PR replaces a fixed escaped-mention marker in Matrix Markdown rendering with a per-message collision-free marker, preserves link metadata, and renders special image-label text safely.

Regression provenance

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

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

No source-backed blocking defect was found. Keep this protected maintainer PR open for a final dependency-contract check and normal maintainer landing review.

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

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The repair is focused and has strong stated renderer coverage, with the direct pinned-dependency contract check remaining as the material confidence gap.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: This protected maintainer PR is exempt from the external-contributor proof gate; its body reports after-fix production-renderer scenarios, but this read-only review did not execute them.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This protected maintainer PR is exempt from the external-contributor proof gate; its body reports after-fix production-renderer scenarios, but this read-only review did not execute them.
Evidence reviewed 7 items Current-main defect: Current main still uses a fixed U+E000 escaped-mention sentinel, so literal or entity-encoded U+E000 text can be restored as an at-sign.
Owner-boundary repair: The PR lazily allocates a marker from the existing collision-aware Matrix marker owner, excludes Markdown metadata, and restores the marker through block and nested inline tokens.
Shared marker contract: The existing Matrix marker allocator reserves characters absent from both literal input and numeric character entities, which matches the collision being repaired.
Findings None None.
Security None None.

Live Verification

Command: pnpm test extensions/matrix/src/matrix/format.test.ts

Result: PASS (completed)

pnpm test extensions/matrix/src/matrix/format.test.ts
runner@runnervm76f27:/tmp/clawsweeper-live-proof-128382-rN0i9r/target$ pnpm test extensions/matrix/src/matrix/format.test.ts
$ node --import tsx scripts/test-projects.mts extensions/matrix/src/matrix/format.test.ts
pnpm test extensions/matrix/src/matrix/format.test.ts
[test] starting test/vitest/vitest.extension-matrix.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-128382-rN0i9r/target

 ✓  extension-matrix  extensions/matrix/src/matrix/format.test.ts (72 tests) 455ms

 Test Files  1 passed (1)
      Tests  72 passed (72)
   Start at  22:48:57
   Duration  2.23s (transform 1.40s, setup 981ms, import 426ms, tests 455ms, environment 0ms)

[test] passed 1 Vitest shard in 8.14s
runner@runnervm76f27:/tmp/clawsweeper-live-proof-128382-rN0i9r/target$ pnpm test extensions/matrix/src/matrix/format.test.ts


































Assertions:

  • PASS expect_output: format.test.ts

How this fits together

The Matrix extension converts Markdown into Matrix-safe HTML and mention metadata before sending room events. Its formatter must preserve literal user text while distinguishing escaped mentions, links, and image fallback labels.

flowchart LR
A[Markdown message] --> B[Escaped mention masking]
B --> C[Markdown token parsing]
C --> D[Matrix HTML rendering]
D --> E[Matrix room event]
C --> F[Link and image metadata]
F --> D
Loading

Decision needed

Question Recommendation
Should this protected Matrix PR land after a reviewer directly confirms the pinned markdown-it 14.3.0 text_special renderer contract on the exact head? Verify contract and land: Confirm the pinned renderer handles text_special as assumed, then land the focused repair with exact-head checks.

Why: The relevant dependency source was unavailable locally and external source lookup failed, so repository policy requires a maintainer-visible contract check before a merge recommendation.

Before merge

  • Resolve merge risk (P1) - The bug fix has a production delta of +16 lines; source review found each addition carries a distinct marker-ownership responsibility, but this requires maintainer acceptance under the repository’s net-neutral bug-fix preference.
  • Resolve merge risk (P1) - The pinned markdown-it renderer contract for text_special could not be directly inspected in this read-only environment because the dependency source is absent and network lookup failed.
  • Complete next step (P2) - The protected maintainer label and unavailable direct dependency contract require a maintainer’s final exact-head review rather than automated repair.
Agent review details

Security

None.

PR surface

Source +16, Tests +81. Total +97 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 36 20 +16
Tests 1 81 0 +81
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 117 20 +97

Review metrics

Metric Value Why it matters
Production vs regression tests production +16, tests +81 The production growth carries marker allocation, metadata exclusion, nested restoration, and special-token rendering; the tests exercise the reported formatting boundaries.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Land this focused formatter repair after directly checking the pinned markdown-it 14.3.0 renderer contract and exact-head validation; retain the shared Matrix private-marker allocator as the sole collision owner.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Land this focused formatter repair after directly checking the pinned markdown-it 14.3.0 renderer contract and exact-head validation; retain the shared Matrix private-marker allocator as the sole collision owner.

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

Yes. Current main’s fixed sentinel at extensions/matrix/src/matrix/format.ts:57 demonstrably collides with literal U+E000 when an escaped mention is masked; the added formatter cases specify the failing visible output, though no test was executed in this read-only review.

Is this the best way to solve the issue?

Yes, with one dependency-proof gap. Reusing the Matrix marker allocator and metadata-range owner is preferable to another fixed placeholder or a downstream rendering workaround.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This repairs visible Matrix message formatting in one bundled channel extension with limited blast radius.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This protected maintainer PR is exempt from the external-contributor proof gate; its body reports after-fix production-renderer scenarios, but this read-only review did not execute them.

Evidence

What I checked:

Likely related people:

  • steipete: Blame attributes the current fixed-sentinel line to steipete's merged formatter introduction, and steipete authored this focused repair. (role: introduced the affected formatter path and recent area contributor; confidence: high; commits: 90a9027688b7, e39fa7ae429d; files: extensions/matrix/src/matrix/format.ts, extensions/matrix/src/matrix/format-profile.ts)

Rank-up moves

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

  • Inspect the installed pinned markdown-it 14.3.0 renderer implementation to confirm the text_special rule contract before landing.

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 (1 earlier review cycle)
  • reviewed 2026-08-23T22:05:12.183Z sha e39fa7a :: needs maintainer review before merge. :: none

@steipete
steipete merged commit 8646b06 into main Aug 24, 2026
184 checks passed
@steipete
steipete deleted the codex/autoqa-matrix-marker-collision-20260823 branch August 24, 2026 01:06
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

Labels

channel: matrix Channel integration: matrix maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant