fix: handle Slack workflow/bot messages in app_mention events#2844
Conversation
Workflow-triggered app_mention events lack a "user" field (they have "bot_id" instead), causing a KeyError that silently killed message processing after the 👀 reaction was added. Branch on the event payload to determine human vs bot, then call the appropriate Slack API (users_info vs bots_info) upfront instead of relying on exception-driven control flow. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
There was a problem hiding this comment.
1 issue found across 1 file
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="backend/chainlit/slack/app.py">
<violation number="1" location="backend/chainlit/slack/app.py:324">
P2: `bot_id` fallback was added in a shared path, so generic `message` events from bots/workflows are now processed as user messages without sender/subtype filtering.</violation>
</file>
Since this is your first cubic review, here's how it works:
- cubic automatically reviews your code and comments on bugs and improvements
- Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
- Add one-off context when rerunning by tagging
@cubic-dev-aiwith guidance or docs links (includingllms.txt) - Ask questions if you need clarification on any suggestion
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
The bot_id fallback in process_slack_message was also reachable from handle_message, which handles all DM-channel messages. This caused bot/workflow messages in DMs to be processed as user messages instead of being dropped. Guard handle_message to only process human messages; workflow mentions are already handled via the app_mention event. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Split the chained .get() call to avoid a mypy type inference issue with SlackResponse's overloaded get method. Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
@hayescode @asvishnyakov This fixes the problem of accepting mentions from bots on slack. Let's say the bot is named chainlit, another bot can mention chainlit to delagate issues. Review & approve pls when you are available |
|
This fixes a real silent failure, the 👀 reaction would fire and then nothing. Branching on bot_id vs user upfront and calling the right Slack API accordingly is the correct approach. The DM handler guard is a nice defensive touch too. LGTM, approving! |
|
@willydouhard Could you take a look at this pr? It fixes an important problem we encounter within slack |
hayescode
left a comment
There was a problem hiding this comment.
Reviewed via Codex
LGTM.
Thx @hayescode for the review. i don't think i have the merge permission |
Workflow-triggered app_mention events lack a "user" field (they have "bot_id" instead), causing a KeyError that silently killed message processing after the 👀 reaction was added.
Branch on the event payload to determine human vs bot, then call the appropriate Slack API (users_info vs bots_info) upfront instead of relying on exception-driven control flow.
Summary by cubic
Handle Slack app_mention events from workflows and bots by using bot_id to fetch the right profile. Ignore bot/workflow messages in DMs and fix a
mypyerror in bot profile lookup to prevent crashes and misclassifying bots.Bug Fixes
user: branch tousers_infoorbots_info; fallback to_get_bot_profileonSlackApiError.mypycall-overload in_get_bot_profileby splitting chainedgetcalls.Refactors
backend/chainlit/slack/app.pywithruff.Written for commit a5db861. Summary will update on new commits.