Skip to content

fix: reply once to a thread reply that mentions the agent - #318

Merged
mwbrooks merged 2 commits into
mainfrom
mwbrooks-fix-thread-mention-double-reply
Nov 17, 2026
Merged

mwbrooks merged 2 commits into
mainfrom
mwbrooks-fix-thread-mention-double-reply

Conversation

@mwbrooks

@mwbrooks mwbrooks commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

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_mention and a message event for that reply, and both listeners ran the agent. The message listener now skips thread replies that mention the agent and leaves them to app_mention.

The fix is in claude-agent-sdk/, openai-agents-sdk/, and pydantic-ai/. The same fix for the starter agent is slack-samples/bolt-python-starter-agent#284.

Testing

  • Added a test that a DM mentioning the agent is still handled, since app_mention never fires in DMs.
  • Added tests/test_message.py in 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.
  • The mention test fails on main and passes with this change, in all three projects.
  • ruff check ., ruff format --check ., and pytest pass in all three projects.

Notes

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.
@mwbrooks mwbrooks added the bug Something isn't working label Nov 16, 2026
@mwbrooks mwbrooks self-assigned this Nov 16, 2026
@mwbrooks
mwbrooks marked this pull request as ready for review November 16, 2026 15:29
@mwbrooks
mwbrooks requested a review from a team as a code owner November 16, 2026 15:29
@mwbrooks
mwbrooks requested review from WilliamBergamin, srtaalej and zimeg and removed request for a team November 16, 2026 15:29

@WilliamBergamin WilliamBergamin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 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", ""):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 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):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 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()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧪 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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in commit 6dd6ea7, great catch! It's in all three projects.

@mwbrooks

Copy link
Copy Markdown
Member Author

Thanks @WilliamBergamin for the review! 🙇 The DM test is a great catch, it guards against the skip silencing Casey in DMs.

@mwbrooks
mwbrooks merged commit 1a5d7ad into main Nov 17, 2026
8 checks passed
@mwbrooks
mwbrooks deleted the mwbrooks-fix-thread-mention-double-reply branch November 17, 2026 00:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants