Repository navigation
fix(matrix): crafted formatted_body stalls the Gateway in the mention check - #184432
Conversation
… check Every admitted room message runs the matrix.to anchor regex over its formatted_body to decide whether the bot was mentioned. In a configured room without a sender allowlist that is any room member, and the check runs whether or not the message mentions the bot. The regex retried every href= from every <a start, so a formatted_body of repeated unterminated <a href="https://matrix.to/# stalled the Gateway event loop for about 2.6 s at 16 KB, 18 s at 32 KB and 116 s at 60 KB, which still fits in one Matrix event. The label tag strip had the same shape on a label made of unterminated < characters. Anchors are now read with one forward scan over precomputed next->, next-quote and next-</a> positions that returns the same href and label as the former regex, and the label tag strip only runs up to the last >.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesReplace backtracking Matrix formatted-message mention parsing with bounded scans while preserving mention matching. Example: A joined room member sends a 33,600-byte formatted message containing repeated unterminated matrix.to anchors.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it fixes a demonstrated Gateway stall that remains on current main, with no introduced correctness defect found. Priority: P1 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe Matrix plugin passes admitted room content into mention detection, whose results feed the shared inbound mention gate before agent dispatch. flowchart TD
A[Matrix sync client] --> B[Matrix room ingress]
B --> C[Formatted mention scanner]
C --> D[Inbound mention gate]
D --> E[Skip or dispatch]
Technical reviewBest possible solution: Use bounded scanning in the existing Matrix mention owner while retaining exact target matching and visible-label requirements. Do we have a high-confidence way to reproduce the issue? Current-main source exposes the reported repeated-scan mechanism, and the collaborator's pinned baseline/candidate Gateway run demonstrates the stall; this review executed no target code. Is this the best way to solve the issue? The patch removes repeated scanning at its existing owner without adding another policy path, configuration, dependency, or persisted state. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 88217c925994. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +76, Tests 0, Docs +1. Total +77 across 3 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReviewed October 31, 2026, 6:36 PM ET / 22:36 UTC (Revision 3). |
Each opening <a> tag ran a fresh binary search over all href candidates, so k empty <a> tags followed by k non-bot anchors cost O(k log k). The last usable index of an opening tag never decreases from one <a> to the next, so a cursor that only moves forward finds the same candidate and keeps the whole scan linear in the formatted_body length.
|
Addressed the P3 finding on head Each Behavior is unchanged. I compared the old regex, the previous binary-search scan and the cursor scan on 1,000,000 generated inputs built from anchor fragments (520,004 contain at least one anchor) and got 0 differences between any two of them. A new test covers the reported shape (5,000 empty
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Built Gateway Matrix proofCompared main The real built Gateway started its Matrix plugin and real Matrix sync client against a local HTTP homeserver fixture implementing account identity, room state/membership, sync and send endpoints. The room required mentions, with no sender allowlist. A joined ordinary member sent the same repeated unterminated matrix.to anchor shape as the contributor regression: 33,600 bytes of formatted HTML, twice on each ref. A separate driver probed The malformed messages were actually consumed and reached the normal no-mention skip decision on both refs. Before and after them, ordinary messages were skipped without mentioning the bot. A normal formatted matrix.to bot mention still produced the bot's acknowledgement reaction on both refs. Both Gateways shut down cleanly. All state/config/database paths were resolved by each native CLI into task-owned profiles; no live account or credentials were used. The first setup attempt watched console output for a structured file-only ingress log; it was corrected before collecting these measurements. An intermediate keep-alive probe campaign observed 7.6/7.3-second connection failures on main and fast candidate responses; the table above uses fresh connections and completed HTTP responses instead, avoiding that transport artifact. The inherited Matrix test command selected the extension suite rather than just the requested file. It completed successfully, including all mention cases; the final test batch reported 536 passed / 3 skipped. Changed-file oxlint and oxfmt passed. No broader local checks were repeated. Source checksums bound the built candidate's changed source/test/docs to the exact candidate checkout, and main's mention source to the pinned baseline. The same two changed test cases preserve last-href, case/quote and label-boundary behavior without adding test lines. No matching policy, room access rule or mention requirement was changed. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Landed in dfb6454. Thanks @LeizhenZhang. Long Matrix messages no longer stall the Gateway. |
… check (#184432) fix(matrix): keep the Gateway responsive while parsing mentions in long messages Matrix mention detection used a regular expression that backtracked heavily on some long, malformed messages. Parsing one such message blocked the Gateway's event loop for seconds, so health checks and other work stalled. Mention detection now uses an anchored scan with the same matching results. Normal mentions and ordinary messages behave as before. Evidence: a built Gateway with a real Matrix sync client against a local homeserver fixture, in secretless Docker, with two 33,600-byte malformed messages. Main's slowest health response was 7,513 ms and 7,274 ms; with this change it was 35 ms and 0.9 ms. Every probe returned HTTP 200. Both refs skipped the events as unmentioned. Normal formatted mentions still got acknowledgement reactions, and ordinary messages were unchanged. Details: openclaw/openclaw#184432 (comment). Thanks @LeizhenZhang. Co-authored-by: Ayaan Zaidi <[email protected]>
… check (openclaw#184432) fix(matrix): keep the Gateway responsive while parsing mentions in long messages Matrix mention detection used a regular expression that backtracked heavily on some long, malformed messages. Parsing one such message blocked the Gateway's event loop for seconds, so health checks and other work stalled. Mention detection now uses an anchored scan with the same matching results. Normal mentions and ordinary messages behave as before. Evidence: a built Gateway with a real Matrix sync client against a local homeserver fixture, in secretless Docker, with two 33,600-byte malformed messages. Main's slowest health response was 7,513 ms and 7,274 ms; with this change it was 35 ms and 0.9 ms. Every probe returned HTTP 200. Both refs skipped the events as unmentioned. Normal formatted mentions still got acknowledgement reactions, and ordinary messages were unchanged. Details: openclaw#184432 (comment). Thanks @LeizhenZhang. Co-authored-by: Ayaan Zaidi <[email protected]>
… check (#184432) fix(matrix): keep the Gateway responsive while parsing mentions in long messages Matrix mention detection used a regular expression that backtracked heavily on some long, malformed messages. Parsing one such message blocked the Gateway's event loop for seconds, so health checks and other work stalled. Mention detection now uses an anchored scan with the same matching results. Normal mentions and ordinary messages behave as before. Evidence: a built Gateway with a real Matrix sync client against a local homeserver fixture, in secretless Docker, with two 33,600-byte malformed messages. Main's slowest health response was 7,513 ms and 7,274 ms; with this change it was 35 ms and 0.9 ms. Every probe returned HTTP 200. Both refs skipped the events as unmentioned. Normal formatted mentions still got acknowledgement reactions, and ordinary messages were unchanged. Details: #184432 (comment). Thanks @LeizhenZhang. Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit dfb6454) Release adaptation: Apply the upstream linear scanners in the release-local extracted formatted-body mention helper, preserving existing account and visible-label checks. Co-authored-by: RomneyDa <[email protected]>
Adapt approved source fixes to the September extended-stable owners. Preserve original APIs and custody; include review-driven regressions. Backport-of: a19f1bf — Agustin Rivera — fix(agents): fail closed when sandboxed spawned children resolve CLI-backed models (#178742) Backport-of: c9f3f82 — Peter Steinberger — fix(agents): release restart-recovery fences for killed runs (#181992) Backport-of: dfb6454 — Leizhen Zhang — fix(matrix): crafted formatted_body stalls the Gateway in the mention check (#184432) Validation: independent source review, exact patch/file identity and git diff --check. Runtime tests, types and builds deferred to authorized remote CI; not run locally. Co-authored-by: RomneyDa <[email protected]>
* fix(gateway): publish node reapproval with committed pairing facts Adapt main commit 94f180d to the extended-stable worker dispatcher, retaining cleanup admission and stale-session fencing. Co-authored-by: RomneyDa <[email protected]> * test(gateway): clarify CLI announcement tool-only phase Keep exact token, barrier, and completion ordering assertions intact while explicitly excluding narration before the barrier. Co-authored-by: RomneyDa <[email protected]> * style(gateway): format node reapproval regression Reflow the spy chain reported by hosted CI; no behavioral changes. Co-authored-by: RomneyDa <[email protected]> * test(secrets): decouple Telegram fixture from plugin discovery Import the real public Telegram secret collector directly so collection does not depend on Gateway discovery environment. Exercise collection with bundled plugins disabled while retaining existing token assertions. Gateway timeout attribution remains unresolved; no production behavior or timeout changes. Co-authored-by: RomneyDa <[email protected]> * test(secrets): load Telegram fixture through public resolver Replace the static extension import rejected by core type and boundary checks with the existing test public-artifact resolver. Keep the real collector in the Vitest module graph and preserve the disabled-discovery regression. Independent source review accepted; local test, typecheck, build, install, and performance execution remain excluded by operator instruction. Hosted CI must validate the correction. Co-authored-by: RomneyDa <[email protected]> * style(secrets): format Telegram fixture import Co-authored-by: RomneyDa <[email protected]> * fix(ui): honor recovery holds before initial chat history Keep drafting available while the existing send owner holds recovery or a retained initial turn. Restore Send when that hold clears without waiting for initial history or submitting the draft automatically. Add renderer regressions for both holds and clarify the pre-history outbox contract. Controlled real-Gateway red/green evidence: 42523861169 / 42526889715. Diagnostic branch is not merged. Co-authored-by: RomneyDa <[email protected]> * fix(ui): preserve startup status presentation while holding send Restore the existing connected startup/history status suppression without reopening Send admission. Extend both durable hold regressions to reject the duplicate composer status band. Existing cloud E2E assertions remain unchanged. Co-authored-by: RomneyDa <[email protected]> * fix(release): backport installer, service, path and telemetry repairs Adapt approved source fixes to the September extended-stable owners. Preserve original APIs and custody; include review-driven regressions. Backport-of: eb5d0cb — Javier MV — fix(install): keep the installed runtime private under umask 0002 (#186782) Backport-of: b079019 — Sukhdeep — fix(daemon): Gateway repair stops the Gateway and fails when macOS denies the Trash (#189321) Backport-of: 558e2f3 — YangManBOBO — fix(cli): compare gateway state dirs case-insensitively on Windows (#185917) Backport-of: b7ce1c3 — Peter Steinberger — test(windows): keep ordinary CLI coverage in one partition Backport-of: ba75cf7 — Juan Buhagiar Duijst — fix(diagnostics-otel): gateway stalls after model calls on large sessions with content capture on (#186666) Validation: independent source review, exact patch/file identity and git diff --check. Runtime tests, types and builds deferred to authorized remote CI; not run locally. Co-authored-by: RomneyDa <[email protected]> * fix(release): preserve notes and harden messaging and exec approval Adapt approved source fixes to the September extended-stable owners. Preserve original APIs and custody; include review-driven regressions. Backport-of: 0a171b4 — Leizhen Zhang — fix(auto-reply): long punctuation runs stall abort-trigger detection (#184433) Backport-of: 49600b5 — Long Jin — fix(memory): preserve inline notes during MEMORY.md compaction (#164089) Backport-of: 982f3b1 — RoboClaw — fix(imessage): report Automation failures after Gateway updates (#186117) Backport-of: 3f7ee38 — art22s — fix: require approval for dynamic shell predicates (#187884) Validation: independent source review, exact patch/file identity and git diff --check. Runtime tests, types and builds deferred to authorized remote CI; not run locally. Co-authored-by: RomneyDa <[email protected]> * fix(release): retain sandbox, recovery lease and Matrix boundaries Adapt approved source fixes to the September extended-stable owners. Preserve original APIs and custody; include review-driven regressions. Backport-of: a19f1bf — Agustin Rivera — fix(agents): fail closed when sandboxed spawned children resolve CLI-backed models (#178742) Backport-of: c9f3f82 — Peter Steinberger — fix(agents): release restart-recovery fences for killed runs (#181992) Backport-of: dfb6454 — Leizhen Zhang — fix(matrix): crafted formatted_body stalls the Gateway in the mention check (#184432) Validation: independent source review, exact patch/file identity and git diff --check. Runtime tests, types and builds deferred to authorized remote CI; not run locally. Co-authored-by: RomneyDa <[email protected]> * fix(config): preserve last-good state through writes and rollback Adapt approved source fixes to the September extended-stable owners. Preserve original APIs and custody; include review-driven regressions. Backport-of: 99418fc — weiqinl — fix(config): keep last-known-good when the observer flags the config as truncated (#152565) Validation: independent source review, exact patch/file identity and git diff --check. Runtime tests, types and builds deferred to authorized remote CI; not run locally. Co-authored-by: RomneyDa <[email protected]> * fix(sessions): preserve history when relocating relative stores Adapt approved source fixes to the September extended-stable owners. Preserve original APIs and custody; include review-driven regressions. Backport-of: a64daf7 — Peter Steinberger — fix(sessions): resolve relative session stores against the state dir, not the working directory (#182444) Validation: independent source review, exact patch/file identity and git diff --check. Runtime tests, types and builds deferred to authorized remote CI; not run locally. Co-authored-by: RomneyDa <[email protected]> * fix(release): repair September backport type contracts Split terminal recovery actions into distinct discriminants without changing behavior. Use the branch-native Doctor import signature, checking held maintenance authority before and after the awaited import. Validation: independent exact-diff source review, formatter and git diff --check passed. Local tests, typechecks and builds not run per operator restriction; fresh exact-head remote qualification required. Repairs CI 42643973970 attempt 1. Co-authored-by: RomneyDa <[email protected]> * fix(release): align backport regressions with September contracts Preserve uncertain config-write outcomes while correcting branch-native fixture APIs and lint errors found by hosted CI. Co-authored-by: RomneyDa <[email protected]> * test(ci): separate Windows capacity from growing inventory Keep package coverage and the five-job limit independent of a historical timing snapshot. Preserve the rounded capacity boundary and exercise the documented bounded-growth fallback with fixed estimates. Co-authored-by: RomneyDa <[email protected]> * test(node-host): keep launcher cleanup with its invoke owner Wait for a positive launcher PID before probing liveness, and cancel through the existing invocation owner on every exit path. Never send SIGKILL to file-derived PID zero. Co-authored-by: RomneyDa <[email protected]> * test(release): observe owned Gateway reservation cleanup Verify the real reservation closes before relaunch instead of rebinding an already-released port that another socket can acquire. Preserve all seven packaged startup recovery scenarios. Co-authored-by: RomneyDa <[email protected]> * test(release): capture native compiler busy-executable evidence Preserve real API execution and errors while recording failure-only executable inode and writable descriptor metadata. Add a Linux kernel-path diagnostic regression; no retry or copy change. Co-authored-by: RomneyDa <[email protected]> * test(release): repair stability regression fixtures Register CLI admission metadata through the runtime registry, observe the rollback health baseline, and preserve exact SQLite byte expectations. Co-authored-by: RomneyDa <[email protected]> --------- Co-authored-by: Peter Steinberger <[email protected]> Co-authored-by: RomneyDa <[email protected]>
Port Telegram callbacks, hook session keys, private-topic approvals and interactive widgets with complete send/edit/route security companions. Include Feishu captioned media, iOS permission Sendable callbacks, WebKit animation/menu retirement and pending automations props handling. Keep Matrix malformed formatted-mention parsing linear-time. Adapt the 11.4 equivalents to the fixed beta baseline where available. Source PRs: #196217, #191585, #196822, #194027, #197519, #198038, #196991, #198380, #198658, #184432. Companion scope: #191647, #192162, #198022, #197271, #194146; #197670 is folded into #197519 equivalent. (cherry picked from commit 928c118) (cherry picked from commit 569ca48) (cherry picked from commit efa744e) (cherry picked from commit c301da9) (cherry picked from commit 641c4d5) (cherry picked from commit b9d3fb4) (cherry picked from commit a213a51) (cherry picked from commit ec46689) (cherry picked from commit 779d22e) (cherry picked from commit 129ccc3) (cherry picked from commit 849c050) (cherry picked from commit b22f35f) (cherry picked from commit 8b414e9) (cherry picked from commit 01ecda4) (cherry picked from commit f978e54) (cherry picked from commit 6e60479) (cherry picked from commit ec7b49a) (cherry picked from commit 1d72ad0) (cherry picked from commit 5e2c66f) (cherry picked from commit dfb6454) Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit f7c581c7f8bf0e57c7d8799e928a121b24462450) Co-authored-by: vincentkoc <[email protected]>
What Problem This Solves
A long Matrix
formatted_bodycontaining repeated unterminated matrix.to anchor starts makes mention parsing backtrack for seconds on the Gateway event loop. An admitted room member can delay unrelated Gateway health requests even when the message does not mention the bot.Change
Preserve Leizhen Zhang's linear anchor scanner and forward-only candidate cursor. Bound visible-label tag stripping to the last closing angle bracket. These replace the expensive scans at their existing owner while preserving the old regex's href/label captures and mention visibility rules.
Consolidate duplicate matching examples into existing regression cases, retaining last-href, quote/case and closing-label coverage; keep tests net zero. Document bounded scanning in the Matrix channel guide. Necessary production growth is +76 lines for the bounded parser; tests net 0 and documentation +1 against the merge base.
Evidence
On exact candidate
4c079c7007a1e44861e7ca0cb4c115cfd7a2dc90, a real built Gateway and Matrix sync client consumed two 33,600-byte malformed room messages from a local homeserver fixture in secretless Node 24.22.1 Docker. Main's maximum successful/healthzresponse latencies were 7512.96 ms and 7274.15 ms; candidate's were 34.76 ms and 0.89 ms, with no probe timeouts. Ordinary messages remained unmentioned and normal formatted bot mentions produced acknowledgement reactions on both refs.The Matrix extension test command completed successfully, including all mention cases. Changed-file oxlint and oxfmt passed. The contributor also reports large randomized old/new matching comparisons with no differences; those comparisons were not rerun for this maintainer pass.
Observed runtime evidence and controls.
Merge Danger
Two-way door: revert restores the former parser; no persisted state, configuration, dependency or public API migration is involved. Blast radius is Matrix formatted-body mention detection. Incorrect matching could miss a valid mention or recognize a malformed one, so existing visibility/spoofing controls and actual ingress controls remain covered. No access or mention policy changes.