Skip to content

fix(slack): preserve third-party bot parents in thread context#12527

Closed
ching-kaching wants to merge 1 commit into
NousResearch:mainfrom
ching-kaching:slack-include-thirdparty-bot-parents
Closed

fix(slack): preserve third-party bot parents in thread context#12527
ching-kaching wants to merge 1 commit into
NousResearch:mainfrom
ching-kaching:slack-include-thirdparty-bot-parents

Conversation

@ching-kaching

@ching-kaching ching-kaching commented Apr 19, 2026

Copy link
Copy Markdown
Contributor

Problem

When an agent is @-mentioned in a Slack thread whose parent is a third-party bot (Intercom escalations, GitHub/Sentry alerts, webhook posts), the parent message — often the entire reason for the ping — never reaches the model. The agent then has to ask the user for clarification or manually fetch the thread via the Slack API.

Root cause

_fetch_thread_context() in gateway/platforms/slack.py filtered every message carrying a bot_id or subtype: bot_message:

# Exclude our own bot messages to avoid circular context.
if msg.get("bot_id") or msg.get("subtype") == "bot_message":
    continue

The comment says "our own bot messages" but the predicate matches all bots.

Fix

Match the filter against the resolved bot_uid (already computed a few lines above). Our own replies stay excluded (no circular context); every other bot's messages flow through as normal thread context.

If bot_uid is unresolved, fall back to the old behavior (drop all bot messages) so we can't accidentally feed our own output back in.

is_bot_msg = bool(msg.get("bot_id")) or msg.get("subtype") == "bot_message"
if is_bot_msg and (not bot_uid or msg.get("user") == bot_uid):
    continue

Testing

Locally reproduced with an Intercom-style bot-authored thread parent:

  • Before: agent saw only the user's [investigate] ping, no parent.
  • After: [Thread context —] block includes the bot parent verbatim.

@ching-kaching ching-kaching force-pushed the slack-include-thirdparty-bot-parents branch 2 times, most recently from a94f2cf to 94ac524 Compare April 19, 2026 11:39
The thread context fetcher filtered every message with a bot_id or
bot_message subtype, which also dropped third-party bot parents
(Intercom escalations, GitHub/Sentry alerts, webhook posts). When a
user @-mentions the agent in such a thread, the parent message — the
actual reason for the ping — never reached the model, leaving the
agent to ask for clarification.

Now we only skip our own bot's messages (matched against the resolved
bot_uid). Other bots' messages flow through as normal context.
@ching-kaching ching-kaching force-pushed the slack-include-thirdparty-bot-parents branch from 94ac524 to f8811e8 Compare April 19, 2026 11:40
@hhhonzik

Copy link
Copy Markdown
Contributor

have the same problems, very annoying.

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery platform/slack Slack app adapter labels Apr 22, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Closing as superseded by #16200 (via @Satoshi-agi's #12561, which included the same "keep third-party bot parents in context" fix you proposed here plus additional layers — reply_to_text parity, per-workspace self-bot identification, new tests). Your diagnosis was the correct root cause; #12561 happened to land on the same file with a larger fix. Thanks for the contribution!

@teknium1 teknium1 closed this Apr 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists platform/slack Slack app adapter type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants