From 0b597cdb6b7fd05f4fb00a5a518a35fce366d050 Mon Sep 17 00:00:00 2001 From: KCAYAAI Date: Thu, 23 Jul 2026 18:28:53 +0000 Subject: [PATCH 1/2] 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 a34c995cc81f..62a5fdcd5f27 100644 --- a/plugins/platforms/slack/adapter.py +++ b/plugins/platforms/slack/adapter.py @@ -3936,11 +3936,16 @@ def _build_identity_prompt(self, team_id: str = "") -> str: 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 fca22ee1c5cb..15a0faf5eb46 100644 --- a/tests/gateway/test_slack.py +++ b/tests/gateway/test_slack.py @@ -1864,6 +1864,38 @@ async def test_channel_mention_strips_bot_id(self, adapter): 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( From 505c1e924ce9992f75647ee02f65e11405260dae Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Fri, 31 Jul 2026 17:45:40 +0530 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20trim=20identity=20prompt=20=E2=80=94?= =?UTF-8?q?=20remove=20jargon,=20tighten=20directive?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow-up to PR #70238. Remove 'free-response channel' and 'authorization' jargon from the model-facing prompt. Collapse the triple-negative 'do not ask / do not reject / do not stay silent' into a single directive. ~70 tokens vs ~175 in the contributor's version, same semantics. --- plugins/platforms/slack/adapter.py | 18 ++++++++---------- tests/gateway/test_slack.py | 6 +++--- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/plugins/platforms/slack/adapter.py b/plugins/platforms/slack/adapter.py index 62a5fdcd5f27..736598dba88f 100644 --- a/plugins/platforms/slack/adapter.py +++ b/plugins/platforms/slack/adapter.py @@ -3936,16 +3936,14 @@ def _build_identity_prompt(self, team_id: str = "") -> str: return "" return ( f"You are connected to this Slack workspace as the bot " - 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." + f'"@{name}". The adapter already applied mention and channel ' + f"routing; treat every delivered turn as intentionally routed to " + f'you. Your routing mention "@{name}" may have been stripped from ' + f'the visible text — do not reject or ignore a message solely ' + f'because "@{name}" is absent. In messages, each line is prefixed ' + f"with the sender's name, and visible mentions are shown as " + f"@DisplayName; a mention of any other participant is not a " + f"mention of you, even if their name is similar." ) async def _resolve_user_is_bot( diff --git a/tests/gateway/test_slack.py b/tests/gateway/test_slack.py index 15a0faf5eb46..d9acaefaf6b0 100644 --- a/tests/gateway/test_slack.py +++ b/tests/gateway/test_slack.py @@ -1887,9 +1887,9 @@ async def test_accepted_mention_prompt_trusts_adapter_routing(self, adapter): 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 "may have been stripped" in prompt + assert "do not reject or ignore" in prompt + assert "intentionally routed" in prompt assert "not a mention of you" in prompt assert "Only treat a message as directed" not in prompt