fix(slack): normalize bang commands before parsing - #60907
Conversation
Duplicate of #59903 — same fix (skip appending the Slack rich_text block when it mirrors the pre-rewrite |
d8a581a to
6a2fb08
Compare
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Comment (token read-only)
PR 60907 normalizes bang commands (!) before parsing in the Slack integration. Fixes a potential command parsing edge case. Well-scoped (2 files, 74 additions, 3 deletions). No security issues or debug artifacts detected.
LGTM - awaiting maintainer approval.
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Comment (74 additions — normalize bang commands before parsing in Slack)
Scope
Normalizes bang commands before parsing in Slack to handle edge cases.
Observations
- Good robustness fix for Slack command parsing.
- The existing 1 review is a COMMENT-only — this is a fresh formal review.
Recommendation
Human reviewer familiar with Slack parsing should confirm the normalization handles all expected bang command formats.
Reviewed by Hermes Agent
teknium1
left a comment
There was a problem hiding this comment.
Thanks for the focused Slack regression coverage. The current main implementation still has the reported behavior: normalization is gated by original_text.startswith("!") at plugins/platforms/slack/adapter.py:2631, and block deduplication compares only against the rewritten text at plugins/platforms/slack/adapter.py:2662.
Problems
- The new mention test invokes
_make_event()with its DM defaults. That bypasses the channel mention-routing branch atplugins/platforms/slack/adapter.py:2835, so it does not cover the proposedraw_original_textrouting preservation.
Suggested changes
- Make that regression a channel event and assert it reaches
handle_message; this covers both command normalization and preservation of the raw mention for routing.
Automated hermes-sweeper review.
| # same thread. | ||
| assert msg_event.source.thread_id == "1111111111.000001" | ||
|
|
||
| @pytest.mark.asyncio |
There was a problem hiding this comment.
This uses the helper's default DM event, which bypasses channel mention gating. Please make it a channel event (channel_type="channel", channel="C123") so the regression also proves raw_original_text preserves the mention for routing after early stripping.
What does this PR do?
Fixes two Slack alternate command-prefix edge cases for messages like
!commandsand<@bot> !status.Hermes rewrites known
!cmdmessages to/cmdbecause Slack native slash commands do not work in threads. In practice, Slack can decorate those messages before they reach the adapter:textand mirroredrich_textblocks;text, for example<@U_BOT> !status.Before this change, those shapes either duplicated the original bang command or prevented command parsing from seeing the command at the start of the message.
Root cause
The command normalization path only handled text that already started with
!.For
!commandswith matching rich text blocks, the adapter rewrote the plain text to/commands, then compared extracted block text against the rewritten text only. Because the block still contained!commands, it was appended as extra content and downstream handlers saw:For
<@bot> !status, routing correctly detected that the bot was mentioned, but the command parser still received the leading mention text. That made the message an addressed prompt rather than a gateway command.Changes Made
!commandsrich-text duplication and<@U_BOT> !statuscommand parsing.Reproduction
Rich text duplication before this change:
text: "!commands".rich_textblock containing!commands./commands.!commands, so the command parser receives duplicate content.Leading mention before this change:
text: "<@U_BOT> !status".!statusat the start, so it is handled as normal message text instead of/status.After this change, the downstream command text is exactly
/commandsor/statusrespectively.How to Test
python -m pytest tests/gateway/test_slack.py::TestBangPrefixCommands -qscripts/run_tests.sh tests/gateway/test_slack.py -qpython -m ruff check plugins/platforms/slack/adapter.py tests/gateway/test_slack.pyIssue / PR search
I searched for existing issues and PRs around Slack
!commands, rich text blocks, alternate command prefixes, duplicate command content, and mention-prefixed bang commands, and did not find an existing match.Checklist