Skip to content

fix(gateway/telegram): skip messages that explicitly @mention another agent - #20464

Closed
Cullusion wants to merge 2 commits into
NousResearch:mainfrom
Cullusion:fix/telegram-skip-other-bot-mentions
Closed

fix(gateway/telegram): skip messages that explicitly @mention another agent#20464
Cullusion wants to merge 2 commits into
NousResearch:mainfrom
Cullusion:fix/telegram-skip-other-bot-mentions

Conversation

@Cullusion

Copy link
Copy Markdown

Summary

  • Adds _message_targets_other_bot() to the Telegram adapter, which scans MessageEntity objects for @mention and text_mention entities directed at a different account
  • Wires it into _should_process_message() so that if another agent is explicitly @mentioned but this bot is not, the message is skipped early — regardless of the require_mention setting
  • Updates the _should_process_message docstring to document the new cross-talk guard
  • Mirrors the equivalent guard already present in the Discord adapter

Root cause

_should_process_message() hit return True immediately when require_mention: false, before any check for whether the message was addressed to a different bot. In a multi-agent group this caused every bot to respond whenever any one of them was @mentioned.

Test plan

  • Single-bot group with require_mention: false — bot still responds to all messages with no @mention
  • Multi-bot group: @other_bot do this — only other_bot responds, not this bot
  • Multi-bot group: @this_bot do this — this bot responds normally
  • Multi-bot group: @this_bot @other_bot help — both bots respond (both mentioned)
  • DM to bot — unaffected, always responds

Fixes #20373

🤖 Generated with Claude Code

Cullusion and others added 2 commits May 5, 2026 18:12
… agent

In multi-agent group chats with require_mention disabled, all bots were
responding to messages that @mentioned a different bot because
_should_process_message() returned True immediately without checking
whether an explicit mention was directed elsewhere.

Adds _message_targets_other_bot() which scans Telegram MessageEntity
objects for @mention and text_mention entities. If another account is
explicitly mentioned but this bot is not, the method returns True and
_should_process_message() returns False early — skipping the message
regardless of the require_mention setting.

Mirrors the cross-talk guard already present in the Discord adapter.

Fixes NousResearch#20373

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…resolve_mention_targets

_message_mentions_bot() and _message_targets_other_bot() previously each
iterated over MessageEntity objects independently. Extract a shared
_resolve_mention_targets() that performs a single pass and returns
(self_mentioned, other_mentioned), then reduce both methods to thin
wrappers around it.

Also extends bot_command handling to set other_mentioned when a
/cmd@other_bot disambiguation suffix does not match this bot, covering
a case the previous implementation missed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #20361 — both PRs add _message_targets_other_bot() to _should_process_message() in the Telegram adapter to fix #20373. Same approach, same fix.

@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery platform/telegram Telegram bot adapter P2 Medium — degraded but workaround exists duplicate This issue or pull request already exists labels May 5, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Automated hermes-sweeper review: this Telegram multi-bot mention routing fix is already implemented on current main.

Evidence:

  • A maintainer already noted this PR is a duplicate of fix(telegram): reject messages that @mention a different bot in group chats #20361, both targeting Telegram: bots respond to messages @mentioning a different bot when require_mention is false #20373 with the same Telegram other-bot mention guard.
  • gateway/platforms/telegram.py:5251 now rejects messages whose explicit bot mentions exclude this adapter before the free-response and require_mention gates run.
  • gateway/platforms/telegram.py:4820 extracts explicit Telegram bot usernames from text/caption entities and /command@botname bot_command entities.
  • tests/gateway/test_telegram_group_gating.py:498 covers the reported require_mention: false case: a message addressed to @Interntestnumber1bot is ignored by Interntestnumber2bot and accepted by the mentioned bot.
  • tests/gateway/test_telegram_group_gating.py:508 covers /stop@Interntestnumber1bot exclusivity when mentions are not required.
  • The implementation landed in ce4d8570215a7e601e13de5936853b64c355ef5d, with follow-up hardening in fbfe2948827b8bdd6e0c0f1aa71eb897938f9635; the earliest containing release tag I found is v2026.5.28.

Thanks for the PR and for matching the Discord cross-talk guard direction; the same bug class is now handled on main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists platform/telegram Telegram bot adapter sweeper:implemented-on-main Sweeper: behavior already present on current main type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Telegram: bots respond to messages @mentioning a different bot when require_mention is false

3 participants