fix(slack): trust adapter routing after stripping self mention

This commit is contained in:
KCAYAAI 2026-07-23 18:28:53 +00:00 committed by kshitij
parent 53559aaf86
commit b24c915168
2 changed files with 42 additions and 5 deletions

View file

@ -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(

View file

@ -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(