Repository navigation
fix: reply once to a thread reply that mentions the agent - #318
Conversation
A thread reply that @-mentions the agent fires both app_mention and message, so the agent ran twice and posted two replies. The message listener now leaves those replies to app_mention.
WilliamBergamin
left a comment
There was a problem hiding this comment.
💯 Thanks @mwbrooks! Checking for Casey's own mention keeps the fix to two lines, and it lines up with the JS port in slack-samples/bolt-js-support-agent#166.
Left one small test suggestion, nothing blocking 🚀
| if is_dm: | ||
| pass | ||
| elif is_thread_reply: | ||
| if f"<@{context.bot_user_id}>" in event.get("text", ""): |
There was a problem hiding this comment.
💯 praise: Matching Casey's own ID instead of any mention is the right call, so a thread reply that tags a teammate still gets answered here.
| fake_run_agent.assert_called_once() | ||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_skips_thread_reply_that_mentions_the_agent(self): |
There was a problem hiding this comment.
💯 praise: This test fails against main's handler and passes here, so it pins exactly the double reply folks hit.
| async def test_skips_thread_reply_that_mentions_the_agent(self): | ||
| fake_run_agent = await self.handle("<@UBOT> and then?") | ||
|
|
||
| fake_run_agent.assert_not_called() |
There was a problem hiding this comment.
🧪 suggestion (non-blocking): Could we add a test that a DM mentioning Casey still runs the agent, in all three projects? app_mention never fires in DMs, so moving this guard above the is_dm branch would silence Casey there with no test failing.
There was a problem hiding this comment.
Added in commit 6dd6ea7, great catch! It's in all three projects.
|
Thanks @WilliamBergamin for the review! 🙇 The DM test is a great catch, it guards against the skip silencing Casey in DMs. |
Summary
This pull request makes Casey reply once, not twice, when someone @-mentions it in a channel thread Casey is already part of. Slack sends both an
app_mentionand amessageevent for that reply, and both listeners ran the agent. Themessagelistener now skips thread replies that mention the agent and leaves them toapp_mention.The fix is in
claude-agent-sdk/,openai-agents-sdk/, andpydantic-ai/. The same fix for the starter agent is slack-samples/bolt-python-starter-agent#284.Testing
app_mentionnever fires in DMs.tests/test_message.pyin all three projects: a thread reply in a thread Casey is part of runs the agent, and a thread reply that mentions Casey is skipped.mainand passes with this change, in all three projects.ruff check .,ruff format --check ., andpytestpass in all three projects.Notes