From b24c915168397e526fab2e810fe303e4bbfb05ed Mon Sep 17 00:00:00 2001 From: KCAYAAI Date: Thu, 23 Jul 2026 18:28:53 +0000 Subject: [PATCH] fix(slack): trust adapter routing after stripping self mention --- plugins/platforms/slack/adapter.py | 15 +++++++++----- tests/gateway/test_slack.py | 32 ++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/plugins/platforms/slack/adapter.py b/plugins/platforms/slack/adapter.py index a34c995cc81..62a5fdcd5f2 100644 --- a/plugins/platforms/slack/adapter.py +++ b/plugins/platforms/slack/adapter.py @@ -3936,11 +3936,16 @@ class SlackAdapter(BasePlatformAdapter): return "" return ( f"You are connected to this Slack workspace as the bot " - f'"@{name}". In messages, each line is prefixed with the sender\'s ' - f"name, and mentions are shown as @DisplayName. Only treat a " - f'message as directed at you when it mentions "@{name}" ' - f"specifically; a mention of any other participant is not a " - f"mention of you, even if their name is similar." + f'"@{name}". The Slack adapter already applied authorization, mention, ' + f"and channel-routing rules before delivering this message. Treat every " + f"delivered turn as intentionally routed to you, including a message " + f"accepted from a free-response channel or active thread. Your own routing " + f'mention "@{name}" may have been removed from the model-visible text. ' + f"Do not ask for another mention, reject the message, or stay silent solely " + f'because "@{name}" is absent. In messages, each line is prefixed with the ' + f"sender's name, and visible mentions are shown as @DisplayName; a mention " + f"of any other participant is not a mention of you, even if their name is " + f"similar." ) async def _resolve_user_is_bot( diff --git a/tests/gateway/test_slack.py b/tests/gateway/test_slack.py index fca22ee1c5c..15a0faf5eb4 100644 --- a/tests/gateway/test_slack.py +++ b/tests/gateway/test_slack.py @@ -1864,6 +1864,38 @@ class TestMessageRouting: assert msg_event.text == "what's the weather?" assert "<@U_BOT>" not in msg_event.text + @pytest.mark.asyncio + async def test_accepted_mention_prompt_trusts_adapter_routing(self, adapter): + """Cleaned text must not make the model revalidate an accepted mention.""" + adapter.config.extra.update({"require_mention": True, "strict_mention": True}) + adapter._bot_display_name = "TestBot" + adapter._team_bot_names = {"T123": "WorkspaceBot"} + event = { + "text": "<@U_BOT> Hi", + "user": "U_USER", + "channel": "C123", + "channel_type": "channel", + "team": "T123", + "ts": "1234567890.000001", + } + + await adapter._handle_slack_message(event) + + adapter.handle_message.assert_awaited_once() + msg_event = adapter.handle_message.await_args.args[0] + prompt = msg_event.channel_prompt + assert msg_event.text == "Hi" + assert "@WorkspaceBot" in prompt + assert "already applied" in prompt + assert "may have been removed" in prompt + assert "Do not ask for another mention" in prompt + assert "free-response channel or active thread" in prompt + assert "not a mention of you" in prompt + assert "Only treat a message as directed" not in prompt + + @pytest.mark.asyncio + + @pytest.mark.asyncio async def test_allow_bots_mentions_ignores_bot_user_without_current_mention(