Skip to content

fix(matrix): pass agentId to buildMentionRegexes for agent-level mention patterns#51272

Merged
vincentkoc merged 3 commits into
openclaw:mainfrom
dinakars777:pr/matrix-mention-patterns
Mar 21, 2026
Merged

fix(matrix): pass agentId to buildMentionRegexes for agent-level mention patterns#51272
vincentkoc merged 3 commits into
openclaw:mainfrom
dinakars777:pr/matrix-mention-patterns

Conversation

@dinakars777

Copy link
Copy Markdown
Contributor

Summary

  • Fix Matrix plugin to respect agent-level mentionPatterns configuration
  • Move route resolution earlier to get agentId before building mention regexes
  • Updated tests to reflect new control flow

Issue

Fixes #51082

Testing

  • All 34 Matrix extension tests pass

@openclaw-barnacle openclaw-barnacle Bot added channel: matrix Channel integration: matrix size: S labels Mar 20, 2026
@greptile-apps

greptile-apps Bot commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a bug where the Matrix plugin ignored agent-level mentionPatterns configuration because buildMentionRegexes was called without an agentId. The fix moves resolveMatrixInboundRoute earlier in the message-handling flow so that _route.agentId is available when building mention regexes, which are then used consistently throughout the handler.

Key changes:

  • resolveMatrixInboundRoute is now called before mention detection, providing the agentId needed for agent-scoped mention patterns.
  • agentMentionRegexes (built with agentId) replaces the previously static mentionRegexes parameter for all mention checks and canDetectMention logic.
  • Test harnesses are updated to mock core.channel.mentions.buildMentionRegexes, and assertions on resolveAgentRoute call-counts in drop-path tests are removed since route resolution now always runs before the bot-allow gating.
  • One cleanup opportunity remains: the mentionRegexes field in MatrixMonitorHandlerParams and its corresponding destructure in createMatrixRoomMessageHandler are now unused dead code — the handler never reads the value. The counterpart in index.ts (buildMentionRegexes(cfg) without an agentId and the resulting pass-through) could also be removed.

Confidence Score: 4/5

  • PR is safe to merge — the core fix is correct and all 34 tests pass. One minor dead-code cleanup (the mentionRegexes param) can be done as a follow-up.
  • The logic change is well-scoped: route resolution is moved earlier with no new side effects, and the correct agentId is now threaded into mention-pattern building. Tests are updated to match the new control flow. The only issue is that the old mentionRegexes parameter on MatrixMonitorHandlerParams (and its usage site in index.ts) is now dead code, which is a style/cleanup concern and not a functional bug.
  • extensions/matrix/src/matrix/monitor/handler.ts (line 65 & 157) and extensions/matrix/src/matrix/monitor/index.ts (line 167 & 226) — the now-unused mentionRegexes param should be cleaned up.

Comments Outside Diff (1)

  1. extensions/matrix/src/matrix/monitor/handler.ts, line 157 (link)

    P2 mentionRegexes param is now dead code

    After this PR the handler always derives mention regexes dynamically via core.channel.mentions.buildMentionRegexes(cfg, _route.agentId) (line 543) and never references the mentionRegexes value that was destructured from params. The destructured variable on this line is unused, meaning:

    1. The mentionRegexes field in MatrixMonitorHandlerParams (line 65) is now dead.
    2. The destructuring here is unused — a TypeScript noUnusedLocals check would flag it.
    3. In index.ts:167, buildMentionRegexes(cfg) is still called (without an agentId) and the result passed to the handler — that call is now a no-op from the handler's perspective.

    Consider removing the mentionRegexes field from MatrixMonitorHandlerParams, the destructuring here, and the corresponding build+pass in index.ts to avoid misleading future readers into thinking the param still affects mention matching.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: extensions/matrix/src/matrix/monitor/handler.ts
    Line: 157
    
    Comment:
    **`mentionRegexes` param is now dead code**
    
    After this PR the handler always derives mention regexes dynamically via `core.channel.mentions.buildMentionRegexes(cfg, _route.agentId)` (line 543) and never references the `mentionRegexes` value that was destructured from params. The destructured variable on this line is unused, meaning:
    
    1. The `mentionRegexes` field in `MatrixMonitorHandlerParams` (line 65) is now dead.
    2. The destructuring here is unused — a TypeScript `noUnusedLocals` check would flag it.
    3. In `index.ts:167`, `buildMentionRegexes(cfg)` is still called (without an `agentId`) and the result passed to the handler — that call is now a no-op from the handler's perspective.
    
    Consider removing the `mentionRegexes` field from `MatrixMonitorHandlerParams`, the destructuring here, and the corresponding build+pass in `index.ts` to avoid misleading future readers into thinking the param still affects mention matching.
    
    How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: extensions/matrix/src/matrix/monitor/handler.ts
Line: 157

Comment:
**`mentionRegexes` param is now dead code**

After this PR the handler always derives mention regexes dynamically via `core.channel.mentions.buildMentionRegexes(cfg, _route.agentId)` (line 543) and never references the `mentionRegexes` value that was destructured from params. The destructured variable on this line is unused, meaning:

1. The `mentionRegexes` field in `MatrixMonitorHandlerParams` (line 65) is now dead.
2. The destructuring here is unused — a TypeScript `noUnusedLocals` check would flag it.
3. In `index.ts:167`, `buildMentionRegexes(cfg)` is still called (without an `agentId`) and the result passed to the handler — that call is now a no-op from the handler's perspective.

Consider removing the `mentionRegexes` field from `MatrixMonitorHandlerParams`, the destructuring here, and the corresponding build+pass in `index.ts` to avoid misleading future readers into thinking the param still affects mention matching.

How can I resolve this? If you propose a fix, please make it concise.

Last reviewed commit: "fix(matrix): resolve..."

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 25786bbb05

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +532 to +536
const { route: _route, configuredBinding: _configuredBinding } = resolveMatrixInboundRoute({
cfg,
accountId,
roomId,
senderId,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Delay bound-route lookup until after the mention gate

In rooms that still require mentions, moving resolveMatrixInboundRoute() here changes more than pattern selection: that helper touches any matched runtime binding (extensions/matrix/src/matrix/monitor/route.ts:49-59), and Matrix bindings use lastActivityAt for idle expiry (extensions/matrix/src/matrix/thread-bindings.ts:497-557). The result is that unmentioned room chatter, unauthorized control commands, or other messages that are immediately dropped below now refresh a focused/bound thread anyway, so ACP/session bindings can stay alive indefinitely even though no message was actually routed to the agent.

Useful? React with 👍 / 👎.

@vincentkoc vincentkoc self-assigned this Mar 21, 2026
@vincentkoc vincentkoc merged commit 1643d15 into openclaw:main Mar 21, 2026
43 checks passed
frankekn pushed a commit to artwalker/openclaw that referenced this pull request Mar 23, 2026
…ion patterns (openclaw#51272)

* fix(matrix): pass agentId to buildMentionRegexes for agent-level mention patterns

* fix(matrix): resolve conflicts from main branch

* Retrigger CI

---------

Co-authored-by: Dinakar Sarbada <dinakars777@users.noreply.github.com>
furaul pushed a commit to furaul/openclaw that referenced this pull request Mar 24, 2026
…ion patterns (openclaw#51272)

* fix(matrix): pass agentId to buildMentionRegexes for agent-level mention patterns

* fix(matrix): resolve conflicts from main branch

* Retrigger CI

---------

Co-authored-by: Dinakar Sarbada <dinakars777@users.noreply.github.com>
alexey-pelykh pushed a commit to remoteclaw/remoteclaw that referenced this pull request Apr 4, 2026
…ion patterns (openclaw#51272)

* fix(matrix): pass agentId to buildMentionRegexes for agent-level mention patterns

* fix(matrix): resolve conflicts from main branch

* Retrigger CI

---------

Co-authored-by: Dinakar Sarbada <dinakars777@users.noreply.github.com>
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
…ion patterns (openclaw#51272)

* fix(matrix): pass agentId to buildMentionRegexes for agent-level mention patterns

* fix(matrix): resolve conflicts from main branch

* Retrigger CI

---------

Co-authored-by: Dinakar Sarbada <dinakars777@users.noreply.github.com>
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
…ion patterns (openclaw#51272)

* fix(matrix): pass agentId to buildMentionRegexes for agent-level mention patterns

* fix(matrix): resolve conflicts from main branch

* Retrigger CI

---------

Co-authored-by: Dinakar Sarbada <dinakars777@users.noreply.github.com>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
…ion patterns (openclaw#51272)

* fix(matrix): pass agentId to buildMentionRegexes for agent-level mention patterns

* fix(matrix): resolve conflicts from main branch

* Retrigger CI

---------

Co-authored-by: Dinakar Sarbada <dinakars777@users.noreply.github.com>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
…ion patterns (openclaw#51272)

* fix(matrix): pass agentId to buildMentionRegexes for agent-level mention patterns

* fix(matrix): resolve conflicts from main branch

* Retrigger CI

---------

Co-authored-by: Dinakar Sarbada <dinakars777@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: matrix Channel integration: matrix size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Matrix plugin ignores agent-level mentionPatterns (buildMentionRegexes called without agentId)

2 participants