hermes - ✅(Solved) Fix Mattermost mention gating falsely matches @bot prefix collisions in channel messages [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
NousResearch/hermes-agent#11901Fetched 2026-04-18 05:58:26
View on GitHub
Comments
0
Participants
1
Timeline
1
Reactions
0
Participants
Timeline (top)
cross-referenced ×1

PR fix notes

PR #11964: fix(mattermost): avoid mention prefix collisions

Description (problem / solution / changelog)

Summary

  • fix Mattermost mention gating so @hermes-bot2 does not match @hermes-bot
  • strip only whole mention tokens instead of raw substrings
  • add a regression test covering prefix-collision channel messages

Problem

Fixes #11901.

Mattermost channel mention gating previously used case-insensitive substring matching. That caused prefix collisions like @hermes-bot2 hello to be treated as a real mention of @hermes-bot, and the forwarded text was corrupted to 2 hello.

Solution

Use token-boundary-aware regex matching for mention detection and stripping. This keeps normal @hermes-bot mentions working while rejecting longer usernames that merely share the same prefix.

Verification

  • python3 -m pytest -o addopts= tests/gateway/test_mattermost.py
  • repo-local repro for @hermes-bot2 hello now leaves handle_message uncalled

Changed files

  • gateway/platforms/mattermost.py (modified, +10/-9)
  • tests/gateway/test_mattermost.py (modified, +10/-0)
RAW_BUFFERClick to expand / collapse

Bug Description

Mattermost mention gating treats substring matches as valid mentions. In channel messages, _handle_ws_event() checks pattern.lower() in message_text.lower() and then strips the matched substring with re.sub(...). That means @hermes-bot2 hello is treated as a mention of @hermes-bot, and the forwarded message text becomes 2 hello.

Affected Files / Lines

  • gateway/platforms/mattermost.py:629-650

Why this is a bug

Mention matching should only trigger on the exact bot mention token (or a safe mention syntax), not arbitrary substrings. The current logic causes false-positive bot replies in channels and corrupts the message text that is sent downstream.

Minimal Reproduction

Using the current tests/gateway/test_mattermost.py helper setup:

  1. Create a MattermostAdapter with _bot_username = "hermes-bot".
  2. Send a channel posted event whose message is @hermes-bot2 hello.
  3. Observe that handle_message(...) is called and the forwarded text is 2 hello.

Observed in repo-local repro:

  • MATTERMOST_CALLED True
  • MATTERMOST_TEXT 2 hello

Expected Behavior

A channel message like @hermes-bot2 hello should not count as a mention of @hermes-bot, so the adapter should skip it when mention-gating is enabled.

Actual Behavior

The adapter responds as if the bot was mentioned and strips the substring @hermes-bot out of the message, leaving 2 hello.

Suggested Investigation Direction

Use token-boundary-aware mention matching (or Mattermost-specific mention syntax) before stripping. A narrow regression test around @hermes-bot2 / prefix collisions would lock this down.

extent analysis

TL;DR

Implement token-boundary-aware mention matching to prevent substring matches from being treated as valid mentions.

Guidance

  • Modify the pattern.lower() in message_text.lower() check in gateway/platforms/mattermost.py to use a more precise matching approach, such as using word boundaries or Mattermost-specific mention syntax.
  • Update the re.sub(...) call to only strip the exact matched mention token, rather than a substring.
  • Create a regression test to verify the fix, focusing on prefix collisions like @hermes-bot2.
  • Review the tests/gateway/test_mattermost.py helper setup to ensure it covers the updated mention matching logic.

Example

import re

# Example of using word boundaries for mention matching
pattern = r'\B@hermes-bot\b'
if re.search(pattern, message_text):
    # Handle mention
    pass

Notes

The current implementation may have unintended consequences, such as false-positive bot replies and corrupted message text. The suggested fix should prevent these issues, but thorough testing is necessary to ensure the updated logic works as expected.

Recommendation

Apply a workaround by implementing token-boundary-aware mention matching, as this will prevent substring matches from being treated as valid mentions and ensure the adapter only responds to exact bot mentions.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

hermes - ✅(Solved) Fix Mattermost mention gating falsely matches @bot prefix collisions in channel messages [1 pull requests, 1 participants]