Skip to content

fix: handle Slack workflow/bot messages in app_mention events#2844

Merged
hayescode merged 6 commits into
Chainlit:mainfrom
sefadegirmenci:main
Apr 1, 2026
Merged

fix: handle Slack workflow/bot messages in app_mention events#2844
hayescode merged 6 commits into
Chainlit:mainfrom
sefadegirmenci:main

Conversation

@sefadegirmenci
Copy link
Copy Markdown
Contributor

@sefadegirmenci sefadegirmenci commented Mar 14, 2026

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 mypy error in bot profile lookup to prevent crashes and misclassifying bots.

  • Bug Fixes

    • Handle events without user: branch to users_info or bots_info; fallback to _get_bot_profile on SlackApiError.
    • Drop bot/workflow messages in the DM handler; only human DMs are processed.
    • Fix mypy call-overload in _get_bot_profile by splitting chained get calls.
  • Refactors

    • Formatted backend/chainlit/slack/app.py with ruff.

Written for commit a5db861. Summary will update on new commits.

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]>
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. backend Pertains to the Python backend. bug Something isn't working labels Mar 14, 2026
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

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-ai with guidance or docs links (including llms.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.

Comment thread backend/chainlit/slack/app.py
sefadegirmenci and others added 2 commits March 14, 2026 14:16
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]>
@sefadegirmenci
Copy link
Copy Markdown
Contributor Author

@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

@efealioksuz
Copy link
Copy Markdown
Contributor

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!

@sefadegirmenci
Copy link
Copy Markdown
Contributor Author

@willydouhard Could you take a look at this pr? It fixes an important problem we encounter within slack

Copy link
Copy Markdown
Contributor

@hayescode hayescode left a comment

Choose a reason for hiding this comment

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

Reviewed via Codex

LGTM.

@hayescode hayescode added this pull request to the merge queue Apr 1, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 1, 2026
@dokterbob dokterbob added this pull request to the merge queue Apr 1, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 1, 2026
@sefadegirmenci
Copy link
Copy Markdown
Contributor Author

Reviewed via Codex

LGTM.

Thx @hayescode for the review. i don't think i have the merge permission

@hayescode hayescode added this pull request to the merge queue Apr 1, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 1, 2026
@hayescode hayescode added this pull request to the merge queue Apr 1, 2026
Merged via the queue into Chainlit:main with commit ee9fd47 Apr 1, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Pertains to the Python backend. bug Something isn't working size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants