Skip to content

fix(matrix): trust m.mentions.user_ids as authoritative mention signal#8673

Closed
teknium1 wants to merge 1 commit into
mainfrom
openclaw-port/matrix-mentions-user-ids
Closed

fix(matrix): trust m.mentions.user_ids as authoritative mention signal#8673
teknium1 wants to merge 1 commit into
mainfrom
openclaw-port/matrix-mentions-user-ids

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

Port of openclaw/openclaw#64796: Per MSC3952 / Matrix v1.7, m.mentions.user_ids is the authoritative mention signal in the Matrix spec.

Problem

Non-Hermes Matrix clients (Element, matrix-bot-sdk bots, etc.) commonly send messages with proper m.mentions.user_ids metadata but without duplicating the @bot text in the message body. For example:

{
  "body": "please reply",
  "m.mentions": { "user_ids": ["@hermes:matrix.org"] }
}

Before this change, _is_bot_mentioned() relied entirely on text-based detection (body string matching + HTML pill detection). These messages were silently dropped when MATRIX_REQUIRE_MENTION=true — effectively breaking mention-gating for any Matrix room receiving messages from non-Hermes clients.

Solution

  • Add mention_user_ids parameter to _is_bot_mentioned()
  • If the bot's user_id appears in m.mentions.user_ids, that alone is sufficient to register a mention
  • Extract m.mentions.user_ids from event content in _resolve_message_context() and pass it through
  • Text-based fallback remains for backwards compatibility with older clients

Architectural Differences from OpenClaw

OpenClaw's fix removed the body-text requirement from a conjunction. Our implementation adds m.mentions.user_ids as a new first-check in the detection chain, preserving the existing text-based checks unchanged as fallback.

Tests

  • 5 new unit tests for _is_bot_mentioned() with mention_user_ids
  • 2 new integration tests through _on_room_message() verifying the full flow
  • All 43 matrix mention tests pass

Test plan

python3 -m pytest tests/gateway/test_matrix_mention.py -o 'addopts=' -q

Port from openclaw/openclaw#64796: Per MSC3952 / Matrix v1.7, the
m.mentions.user_ids field is the authoritative mention signal.  Non-
OpenClaw Matrix clients (Element, matrix-bot-sdk bots, etc.) commonly
send messages with proper m.mentions.user_ids metadata but without
duplicating the @bot text in the message body.

Before this change, _is_bot_mentioned() relied entirely on text-based
detection (body string matching and HTML pill detection), causing
messages from these clients to be silently dropped when
MATRIX_REQUIRE_MENTION=true.

Now, if the bot's user_id appears in m.mentions.user_ids, that alone
is sufficient to register a mention — matching the Matrix spec.
Text-based fallback remains for backwards compatibility with older
clients that don't populate m.mentions.
teknium1 added a commit that referenced this pull request Apr 13, 2026
Port from openclaw/openclaw#64796: Per MSC3952 / Matrix v1.7, the
m.mentions.user_ids field is the authoritative mention signal. Clients
that populate m.mentions but don't duplicate @bot in the body text
were being silently dropped when MATRIX_REQUIRE_MENTION=true.

Cherry-picked from PR #8673.
teknium1 added a commit that referenced this pull request Apr 13, 2026
Port from openclaw/openclaw#64796: Per MSC3952 / Matrix v1.7, the
m.mentions.user_ids field is the authoritative mention signal. Clients
that populate m.mentions but don't duplicate @bot in the body text
were being silently dropped when MATRIX_REQUIRE_MENTION=true.

Cherry-picked from PR #8673.
ulasbilgen pushed a commit to ulasbilgen/hermes-adhd-agent that referenced this pull request May 1, 2026
Port from openclaw/openclaw#64796: Per MSC3952 / Matrix v1.7, the
m.mentions.user_ids field is the authoritative mention signal. Clients
that populate m.mentions but don't duplicate @bot in the body text
were being silently dropped when MATRIX_REQUIRE_MENTION=true.

Cherry-picked from PR NousResearch#8673.
aj-nt pushed a commit to aj-nt/hermes-agent that referenced this pull request May 1, 2026
Port from openclaw/openclaw#64796: Per MSC3952 / Matrix v1.7, the
m.mentions.user_ids field is the authoritative mention signal. Clients
that populate m.mentions but don't duplicate @bot in the body text
were being silently dropped when MATRIX_REQUIRE_MENTION=true.

Cherry-picked from PR NousResearch#8673.
02356abc pushed a commit to 02356abc/hermes-agent that referenced this pull request May 14, 2026
Port from openclaw/openclaw#64796: Per MSC3952 / Matrix v1.7, the
m.mentions.user_ids field is the authoritative mention signal. Clients
that populate m.mentions but don't duplicate @bot in the body text
were being silently dropped when MATRIX_REQUIRE_MENTION=true.

Cherry-picked from PR NousResearch#8673.
olympus-terminal pushed a commit to olympus-terminal/hermes-agent that referenced this pull request May 16, 2026
Port from openclaw/openclaw#64796: Per MSC3952 / Matrix v1.7, the
m.mentions.user_ids field is the authoritative mention signal. Clients
that populate m.mentions but don't duplicate @bot in the body text
were being silently dropped when MATRIX_REQUIRE_MENTION=true.

Cherry-picked from PR NousResearch#8673.
Egavasyug pushed a commit to Egavasyug/hermes-agent that referenced this pull request Jun 10, 2026
Port from openclaw/openclaw#64796: Per MSC3952 / Matrix v1.7, the
m.mentions.user_ids field is the authoritative mention signal. Clients
that populate m.mentions but don't duplicate @bot in the body text
were being silently dropped when MATRIX_REQUIRE_MENTION=true.

Cherry-picked from PR NousResearch#8673.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant