Skip to content

fix(slack): check Block Kit blocks for @mentions, not just flat text - #52404

Closed
AlexFucuson9 wants to merge 1 commit into
NousResearch:mainfrom
AlexFucuson9:fix/slack-mention-detection-blocks
Closed

fix(slack): check Block Kit blocks for @mentions, not just flat text#52404
AlexFucuson9 wants to merge 1 commit into
NousResearch:mainfrom
AlexFucuson9:fix/slack-mention-detection-blocks

Conversation

@AlexFucuson9

Copy link
Copy Markdown
Contributor

Problem

Mention detection only checked the flat text field for @mentions. Block Kit messages that have the @mention only in blocks (e.g. rich_text sections with user elements) were silently dropped.

# Before — only checks flat text
routing_text = original_text or ""
is_mentioned = bool(
    (bot_uid and f"<@{bot_uid}>" in routing_text)
    or self._slack_message_matches_mention_patterns(routing_text)
)

# After — checks both flat text and blocks text
blocks = event.get("blocks")
blocks_text = _extract_text_from_slack_blocks(blocks) if blocks else ""
mention_text = (original_text or "") + ("\n" + blocks_text if blocks_text else "")
is_mentioned = bool(
    (bot_uid and f"<@{bot_uid}>" in mention_text)
    or self._slack_message_matches_mention_patterns(mention_text)
)

Files changed

File Change
plugins/platforms/slack/adapter.py Extract blocks text and include in mention check (+8/-3 lines)

Fixes #52387

Mention detection only checked the flat  field for @mentions.
Block Kit messages that have the @mention only in  (e.g.
rich_text sections with user elements) were silently dropped.

Extract text from blocks and include it in the mention check so
@mentions in Block Kit blocks are properly detected.

Fixes NousResearch#52387
@alt-glitch alt-glitch added type/bug Something isn't working comp/plugins Plugin system and bundled plugins platform/slack Slack app adapter P3 Low — cosmetic, nice to have labels Jun 25, 2026

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review Summary

Verdict: Approved

Small, focused fix for Slack Block Kit mention detection. The change correctly extracts text from blocks and includes it in the mention check. Note: PR #52390 addresses the same issue (#52387) with a more comprehensive approach including helper functions and additional test coverage — the author/reviewer should reconcile these.

Looks Good

  • Minimal diff (8 additions, 3 deletions)
  • Correct approach: merge blocks text into mention detection
  • References the existing _extract_text_from_slack_blocks helper

Reviewed by Hermes Agent

@teknium1 teknium1 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.

Thank you for the focused Slack investigation. The current main code still has the reported Block Kit mention gap, but this patch needs rework before it can safely address it.

Problems

  • The patch changes only channel routing. The earlier allow_bots: mentions filter still reads flat event["text"] and returns at plugins/platforms/slack/adapter.py:2607-2610, so the issue's bot-message reproduction remains dropped.
  • _extract_text_from_slack_blocks() recursively includes rich_text_quote content (plugins/platforms/slack/adapter.py:173-174) and renders user elements as mention tokens (:145-146). Feeding all extracted text into routing would violate the existing quoted-mention safety contract in tests/gateway/test_slack.py:1687-1721.
  • The PR adds no regression tests for either mention gate or for preserving quoted-content isolation.

Suggested changes

  • Share a detection helper between the two gates, collecting only non-quoted Block Kit user mentions.
  • Add integration tests for a direct Block Kit mention, allow_bots: mentions, and quoted-only mention rejection.

Automated hermes-sweeper review.

# text field (#52387).
blocks = event.get("blocks")
blocks_text = _extract_text_from_slack_blocks(blocks) if blocks else ""
mention_text = (original_text or "") + ("\n" + blocks_text if blocks_text else "")

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.

_extract_text_from_slack_blocks() includes nested rich_text_quote content, so this makes a quoted/forwarded <@bot> satisfy routing. Current main deliberately rejects that case in tests/gateway/test_slack.py:1687-1721; use a detector that collects only non-quoted user elements instead.

@teknium1 teknium1 added sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 15, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Closing as superseded by #69316 (merged): counting mentions in ALL block text (incl. quoted/forwarded) risks response hijack; the landed fix (#52390 base) only counts non-quoted mentions.

Thanks for digging into this — the consolidated fix stands on the cluster's collective analysis, and your work is credited in #69316's summary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/plugins Plugin system and bundled plugins P3 Low — cosmetic, nice to have platform/slack Slack app adapter sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data type/bug Something isn't working

Projects

None yet

5 participants