Skip to content

fix(matrix): bot ignores valid plain-text room mentions - #117764

Merged
steipete merged 4 commits into
mainfrom
codex/qa-matrix-native-mentions-0801
Aug 2, 2026
Merged

steipete merged 4 commits into
mainfrom
codex/qa-matrix-native-mentions-0801

Conversation

@steipete

@steipete steipete commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where Matrix operators mentioning their bot with native m.mentions metadata and visible plain text would receive no reply when the message had no HTML formatting and no custom mention patterns.

Why This Change Was Made

Recognize a visible exact Matrix account ID or safely bounded localpart only when native mention metadata names the exact bot account. Preserve HTML mentions, custom patterns, homeserver and port identity, and defenses against forged metadata or invisible Unicode separators.

User Impact

Bots now respond to legitimate plain-text room mentions with default settings while rejecting spoofed cross-server and hidden mentions.

Evidence

  • 182 passing focused tests: 136 actual Matrix room-handler tests and 46 native mention owner tests, including default-room delivery and forged account/Unicode cases.
  • Exact three-path remote changed gate passed extensions and extensionTests typechecking, lint, formatting, plugin boundaries, SDK and security guards.
  • Two independent dependency/security reviews and fresh full dirty and committed-branch Sol/high autoreviews passed; Matrix SDK 41.9.0 and official protocol contracts inspected directly.
  • Remote proof and verified Testbox cleanup: https://github.com/openclaw/openclaw/actions/runs/30729156807
  • Existing Matrix live scenarios automatically inject formatted HTML, so no plaintext-only live end-to-end result is claimed.

Final exact-head live Matrix proof: bb0004e

  • Exact reviewed head: bb0004e48bf05cc971327076816e7fd09484fb10.
  • Real pinned Tuwunel Matrix homeserver + real ephemeral Gateway + mock provider, with actual native Matrix events and no HTML: https://github.com/openclaw/openclaw/actions/runs/30733079526.
  • Bare plaintext bot localpart with exact m.mentions.user_ids: exactly one bot reply $EfoR4xEghoo00SeaurTkfY4JeVf2COdbVp3kMKW1eR0, marker MATRIX_NATIVE_PLAIN_C60D26C8.
  • Exact full Matrix user ID followed by colon plus Unicode U+2003 whitespace: exactly one bot reply $1YHyHLrY06cuiiRgisfXBeW8YpjiqxMhP5NztrKGEOQ, marker MATRIX_FULL_MXID_C60D26C8.
  • Historical punctuation/account spoof: no reply; observed event $y9LLqwl0AxcHAtgD5I35CypGrdP7Jkv3pP7c5kB5tp0.
  • 364/364 actual resolver and room-handler tests plus complete exact-three-path production/test typecheck, lint, and security gates: https://github.com/openclaw/openclaw/actions/runs/30733197734.
  • Strict shorthand policy is unchanged; DNS homeservers, explicit numeric ports, bracketed IPv6, Unicode whitespace, full-ID command separators, hostile ports/domains, BOM/zero-width/bidi controls, room aliases, and account-prefix spoofs are explicitly covered.
  • Independent security reviewers exercised 584 and 178 adversarial/compatibility probes. Fresh full committed-branch P0/P1 Sol/high review and TruffleHog are clean; both owned remote leases were independently confirmed completed. The latest ClawSweeper full-ID separator finding is repaired at its owner without adding production lines in the follow-up.

@openclaw-barnacle openclaw-barnacle Bot added channel: matrix Channel integration: matrix size: S maintainer Maintainer-authored PR labels Aug 2, 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. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Aug 2, 2026
@clawsweeper

clawsweeper Bot commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 2, 2026, 1:14 AM ET / 05:14 UTC.

ClawSweeper review

What this changes

The PR lets Matrix room messages with exact native m.mentions metadata trigger the bot when the visible plain-text body contains the exact Matrix ID or a safely bounded localpart, while retaining spoof rejection.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

This PR is still necessary: current main accepts metadata-backed user mentions only when HTML contains a validated Matrix link or configured mention patterns match, so valid plain-text native mentions remain ignored. The patch repairs that owner boundary with exact metadata ownership plus visible-account checks, resolves all prior ClawSweeper findings, and supplies exact-head runtime proof; it remains open because the maintainer protected label makes the final merge decision human-owned.

Priority: P1
Reviewed head: bb0004e48bf05cc971327076816e7fd09484fb10
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused owner-boundary repair with strong exact-head runtime proof, targeted handler coverage, and no remaining actionable correctness finding.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body provides exact-head real Matrix-event proof from a pinned Tuwunel homeserver and ephemeral Gateway, including positive plaintext deliveries and a spoofed negative case; redact any private data if this evidence is reposted.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body provides exact-head real Matrix-event proof from a pinned Tuwunel homeserver and ephemeral Gateway, including positive plaintext deliveries and a spoofed negative case; redact any private data if this evidence is reposted.
Evidence reviewed 7 items Current-main gap: Current main requires an exact native metadata entry plus either a validated formatted-body mention or configured text pattern; a plain @bot body with native metadata but no HTML/pattern is therefore not an explicit mention.
Owner-boundary repair: The PR changes the mention resolver itself, adding a visible plain-text check only after exact m.mentions.user_ids ownership succeeds; it does not weaken the metadata-only spoof guard downstream.
Handler-level regression coverage: The PR exercises the real room-handler boundary for full IDs, colon-plus-Unicode-whitespace commands, and localpart shorthand, then checks that forged account, Unicode, Markdown, and room-alias forms do not record an inbound session.
Findings None None.
Security None None.

How this fits together

The Matrix plugin converts incoming room events into an agent-session decision. Its mention resolver combines native Matrix metadata with visible message content before the room handler decides whether a group message may invoke the bot.

flowchart LR
  A[Matrix room event] --> B[Native mention metadata]
  A --> C[Visible plain text or HTML]
  B --> D[Mention resolver]
  C --> D
  D --> E[Group-message invocation decision]
  E --> F[Agent session and bot reply]
Loading

Decision needed

Question Recommendation
Should the Matrix owner accept the PR’s intentionally strict plain-text shorthand grammar for native m.mentions events and merge the exact-head fix? Accept the bounded matcher: Merge the resolver change with its exact metadata requirement, visible-text requirement, and full negative boundary suite.

Why: The patch is source-backed and proof-positive, but the protected maintainer label requires an explicit human decision on the channel’s delivery-versus-spoofing boundary.

Before merge

  • Resolve merge risk (P1) - This changes the group-message delivery and anti-spoof boundary: a Matrix owner should affirm the deliberately strict punctuation and Unicode shorthand grammar before merge, even though the exact metadata, negative tests, and runtime proof are positive.
Agent review details

Security

None.

PR surface

Source +16, Tests +311. Total +327 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 20 4 +16
Tests 2 311 0 +311
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 331 4 +327

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Accept the bounded Matrix mention grammar (recommended)
    After Matrix owner review, merge the exact-metadata and visible-text matcher because the real-event proof and adversarial negative cases cover the changed delivery boundary.
  2. Pause for a policy change
    Keep this PR open only if maintainers want to broaden or narrow the supported plain-text shorthand syntax beyond the tested security boundary.

Technical review

Best possible solution:

Merge the narrow resolver change after Matrix ownership review confirms the protected delivery and spoofing boundary, preserving exact m.mentions ownership and the existing metadata-only rejection invariant.

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

Yes—source establishes the current-main path: exact native metadata plus a visible plain @bot body has neither formatted-body recognition nor a configured pattern, so it is rejected. The PR also supplies an exact-head real Matrix-event transcript for the repaired positive and spoof-negative cases.

Is this the best way to solve the issue?

Yes. The resolver owns the combined metadata-and-visibility decision, and this patch extends that canonical check instead of adding a handler-side exception or trusting metadata alone.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides exact-head real Matrix-event proof from a pinned Tuwunel homeserver and ephemeral Gateway, including positive plaintext deliveries and a spoofed negative case; redact any private data if this evidence is reposted.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body provides exact-head real Matrix-event proof from a pinned Tuwunel homeserver and ephemeral Gateway, including positive plaintext deliveries and a spoofed negative case; redact any private data if this evidence is reposted.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: Without this repair, ordinary Matrix room mentions can produce no bot reply on a supported default-style native mention path.
  • merge-risk: 🚨 message-delivery: The changed resolver determines whether a Matrix room message reaches an agent session and receives a bot reply.
  • merge-risk: 🚨 security-boundary: The patch deliberately changes the anti-spoof gate for untrusted native metadata and visible account text.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body provides exact-head real Matrix-event proof from a pinned Tuwunel homeserver and ephemeral Gateway, including positive plaintext deliveries and a spoofed negative case; redact any private data if this evidence is reposted.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides exact-head real Matrix-event proof from a pinned Tuwunel homeserver and ephemeral Gateway, including positive plaintext deliveries and a spoofed negative case; redact any private data if this evidence is reposted.

Evidence

What I checked:

  • Current-main gap: Current main requires an exact native metadata entry plus either a validated formatted-body mention or configured text pattern; a plain @bot body with native metadata but no HTML/pattern is therefore not an explicit mention. (extensions/matrix/src/matrix/monitor/mentions.ts:219, ceb8a8b3a198)
  • Owner-boundary repair: The PR changes the mention resolver itself, adding a visible plain-text check only after exact m.mentions.user_ids ownership succeeds; it does not weaken the metadata-only spoof guard downstream. (extensions/matrix/src/matrix/monitor/mentions.ts:41, bb0004e48bf0)
  • Handler-level regression coverage: The PR exercises the real room-handler boundary for full IDs, colon-plus-Unicode-whitespace commands, and localpart shorthand, then checks that forged account, Unicode, Markdown, and room-alias forms do not record an inbound session. (extensions/matrix/src/matrix/monitor/handler.test.ts:955, bb0004e48bf0)
  • Existing anti-spoof invariant: Current handler coverage already proves metadata alone must not invoke the bot, so preserving a visible-body requirement is the correct invariant rather than trusting native metadata by itself. (extensions/matrix/src/matrix/monitor/handler.test.ts:1047, ceb8a8b3a198)
  • Feature provenance: History identifies the native m.mentions.user_ids behavior as an established Matrix mention surface, with later work covering HTML labels and prefix stripping; this patch extends that same resolver rather than creating a parallel path. (extensions/matrix/src/matrix/monitor/mentions.ts:192, cd33ac293ee0)
  • Exact-head real behavior proof: The PR body and follow-up comment document a real pinned Tuwunel homeserver, ephemeral Gateway, actual unformatted Matrix events, one-reply positive cases, and a no-reply spoof case for head bb0004e48bf; the supplied check context also reports successful Real behavior proof checks. (bb0004e48bf0)

Likely related people:

  • steipete: Feature history shows repeated authored work on this resolver and related plugin-runtime ownership, in addition to the current focused repair. (role: recent Matrix mention contributor; confidence: high; commits: bb0004e48bf0, 84500db379ef, ee6e534ccbaa; files: extensions/matrix/src/matrix/monitor/mentions.ts)
  • hcl: History attributes the earlier authoritative m.mentions.user_ids behavior to this contributor, making them a useful routing contact for the retained metadata invariant. (role: introduced native metadata behavior; confidence: medium; commits: cd33ac293ee0; files: extensions/matrix/src/matrix/monitor/mentions.ts)
  • Nick Ludlam: Prior Matrix work covered display-name mention labels in the same resolver, an adjacent visible-mention contract. (role: adjacent mention-behavior contributor; confidence: medium; commits: 5d82534af763; files: extensions/matrix/src/matrix/monitor/mentions.ts)

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 (3 earlier review cycles)
  • reviewed 2026-08-02T03:02:26.770Z sha f5b4278 :: needs real behavior proof before merge. :: [P1] Reject Unicode localpart continuations
  • reviewed 2026-08-02T03:33:21.349Z sha c13ef1f :: needs real behavior proof before merge. :: [P1] Reject punctuation localpart continuations
  • reviewed 2026-08-02T04:26:40.422Z sha 4da7051 :: needs real behavior proof before merge. :: [P1] Accept the full-ID colon command separator

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 2, 2026
@steipete

steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

Maintainer security decision and exact-head runtime proof for 4da7051: historical Matrix localparts can legally contain punctuation and Unicode, so bare shorthand now starts only at message start or Unicode White_Space and ends only at message end, Unicode White_Space, or colon followed by Unicode White_Space. Ambiguous punctuation/Markdown shorthand is intentionally rejected; exact native mention ownership and exact full Matrix IDs remain supported. A real pinned Tuwunel homeserver plus a real ephemeral Gateway and mock provider received visible bare @localpart with exact m.mentions.user_ids and no format/formatted_body, producing exactly one actual bot reply; punctuation-suffixed account spoof produced no reply. Sanitized marker MATRIX_NATIVE_PLAIN_11683285; driver event $L3aY-KXDcRzAVlPtFefKSYFJ-06k4Y8SwQNWAdDJWiQ; reply event $1YzUjLudcA34PYioLn3zn2lyowVulJVNBj_wdOWnKdo; spoof event $oL9jZztCXID144DyrXTtx5hLYtkilA9ThxFJI2a00Rc. Live proof https://github.com/openclaw/openclaw/actions/runs/30731236764. All 347 owner/handler tests and the exact-three-path changed gate passed on the frozen source: https://github.com/openclaw/openclaw/actions/runs/30731633656. Independent adversarial security review and fresh committed-branch P0/P1 structured review found no issues; TruffleHog clean; all remote leases stopped.

@steipete

steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

Final exact-head proof and previous P1 resolution: bb0004e adds the safe full-MXID colon+Unicode-whitespace command separator without weakening shorthand or spoof boundaries. Genuine pinned Tuwunel homeserver + real Gateway + mock provider exercised actual plaintext native Matrix events with NO HTML: bare @localpart => exactly one reply $EfoR4xEghoo00SeaurTkfY4JeVf2COdbVp3kMKW1eR0; exact full @bot:server followed colon+U+2003 => exactly one reply $1YHyHLrY06cuiiRgisfXBeW8YpjiqxMhP5NztrKGEOQ; punctuation/account spoof => no reply, event $y9LLqwl0AxcHAtgD5I35CypGrdP7Jkv3pP7c5kB5tp0. Live evidence https://github.com/openclaw/openclaw/actions/runs/30733079526. Expanded actual resolver+room-handler suites 364/364 and complete exact-three-file gate pass: https://github.com/openclaw/openclaw/actions/runs/30733197734. 762 independent security probes, clean full-branch P0/P1 review, clean TruffleHog, and both leases independently completed. PR body now contains full inspectable exact-head evidence.

@clawsweeper clawsweeper Bot added 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 Aug 2, 2026
@steipete

steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

Explicit Matrix owner/maintainer security-boundary decision for exact head bb0004e: ACCEPT the deliberately strict native plain-text grammar. Invocation requires both exact trusted m.mentions user ownership and a visible exact full Matrix ID or safely bounded bare localpart; shorthand punctuation/Markdown/account continuations remain intentionally unsupported, full-ID colon plus genuine Unicode whitespace is permitted, and hostile Unicode/invisible controls, room aliases, alternate accounts/domains/ports, and metadata-only spoofing remain denied. The exact-head real Tuwunel/Gateway positive+negative events, 364 owner/handler tests, full remote gate, adversarial security reviews, latest 5/6 ClawSweeper proof-sufficient/no-findings verdict, and green hosted required openclaw/ci-gate satisfy both message-delivery and security-boundary merge risks. As the owning maintainer I approve this exact protected-boundary change for native landing.

@steipete
steipete merged commit 03c2879 into main Aug 2, 2026
104 of 111 checks passed
@steipete
steipete deleted the codex/qa-matrix-native-mentions-0801 branch August 2, 2026 05:18
@steipete

steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 2, 2026
)

* fix(matrix): recognize native plain-text room mentions

* fix(matrix): reject Unicode account-prefix mention spoofing

* fix(matrix): enforce complete native mention account boundaries

* fix(matrix): recognize full user ID command mentions
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 merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: M 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