Skip to content

Matrix: resolve mention patterns per routed agent#33028

Closed
webdevtodayjason wants to merge 1 commit into
openclaw:mainfrom
webdevtodayjason:codex/heartbeat-model-override
Closed

Matrix: resolve mention patterns per routed agent#33028
webdevtodayjason wants to merge 1 commit into
openclaw:mainfrom
webdevtodayjason:codex/heartbeat-model-override

Conversation

@webdevtodayjason

Copy link
Copy Markdown
Contributor

Summary

  • resolve the agent route before mention detection in the Matrix monitor handler
  • build mention regexes per message using the routed agentId
  • remove startup-time mention regex caching that ignored agent context
  • add a regression assertion proving buildMentionRegexes receives the routed agent

Testing

  • pnpm test -- extensions/matrix/src/matrix/monitor

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

greptile-apps Bot commented Mar 3, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a bug where mention regexes were built once at startup without agent context, meaning multi-agent deployments would always use the default agent's mention patterns regardless of which agent a message was routed to. The fix resolves the agent route before mention detection on every incoming message, then builds regexes using the correct agentId.

Key changes:

  • resolveAgentRoute is moved earlier in handler.ts (before resolveMentions), so buildMentionRegexes(cfg, baseRoute.agentId) can be called with the correct per-message agent context.
  • The startup-time buildMentionRegexes(cfg) call in index.ts and the corresponding mentionRegexes handler parameter are removed, eliminating the stale cached regexes.
  • A regression test assertion is added confirming buildMentionRegexes receives the routed agentId ("main") rather than being called with no agent context.

Trade-off to note: resolveAgentRoute is now called for every message that passes pre-mention-check filtering (DM policy, room gating, etc.), including messages that will subsequently be dropped due to no-mention. This is a minor performance consideration but is unavoidable to support agent-aware regex building at the correct point in the pipeline.

Confidence Score: 5/5

  • This PR is safe to merge — it is a targeted correctness fix with no regressions introduced.
  • The change is narrow in scope: it moves one existing function call (resolveAgentRoute) earlier in the handler to enable per-message agent-aware mention regex building. All required variables are in scope at the new call site. The result is reused later (for route construction), so there is no duplicated work. The startup-time cached regexes are cleanly removed, and a new regression assertion confirms the agent ID flows through correctly. No new error paths are introduced.
  • No files require special attention

Last reviewed commit: e33e504

@webdevtodayjason

Copy link
Copy Markdown
Contributor Author

Maintainer-ready summary:

  • Scope: Matrix mention routing fix for multi-agent setups.
  • Behavior: mention regexes are now built with the resolved agentId per message, not once globally at startup.
  • Risk: low; localized to Matrix monitor mention detection flow.
  • Coverage: adds/updates regression assertion that buildMentionRegexes is called with the routed agent.
  • CI: running.

If this shape looks right, this should be safe to merge as a targeted behavior fix.

@webdevtodayjason

Copy link
Copy Markdown
Contributor Author

Friendly ping: this PR is currently clean with required checks green. If the scope looks good, this should be ready for maintainer merge.

@webdevtodayjason

Copy link
Copy Markdown
Contributor Author

Closing this to reduce stale PR inventory and reset on smaller, higher-signal work. If needed, I can reopen or resubmit a tighter replacement later.

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: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant