fix(slack): re-apply bang→slash rewrite after @mention strip - #47115
fix(slack): re-apply bang→slash rewrite after @mention strip#47115zenplace-system wants to merge 1 commit into
Conversation
When a user types `@bot !model ...` the message text starts with `<@BOT_UID>`, so the early bang-rewrite pass (which only fires when text starts with `!`) is skipped entirely. After the bot mention is stripped the leading `!` becomes visible, but no second rewrite pass was run, leaving the command as a plain text message instead of a COMMAND-typed dispatch. Fix: after stripping the bot mention, check whether the resulting text starts with `!` and, if it resolves to a known gateway command via `is_gateway_known_command`, rewrite it to `/cmd ...` and sync `original_text` so the downstream `MessageType.COMMAND` detection fires correctly. Reproducer: send `@bot !model jp.anthropic.claude-opus-4 --provider bedrock` in a Slack channel — previously silently ignored, now dispatched as `/model jp.anthropic.claude-opus-4 --provider bedrock`.
|
Duplicate of #30592 — that PR (open, filed earlier) adds the identical bang->slash re-rewrite block after mention-stripping in slack.py, with byte-equivalent logic (same is_gateway_known_command guard and original_text sync). #30592 also fixes a second bug (thread-context prepend breaking the is_command() slash check), so it is the broader, canonical fix. |
teknium1
left a comment
There was a problem hiding this comment.
Thanks for isolating a real Slack command-routing gap.
Problems
- Current main moved the runtime adapter from
gateway/platforms/slack.pytoplugins/platforms/slack/adapter.pyin5600105478ffde29d7566b45421b100eaa29c4ef; this hunk therefore cannot reach the active adapter. - The re-rewrite uses post-augmentation
text. Current Slack processing appends rich-block content before mention stripping (plugins/platforms/slack/adapter.py:2655-2672), so quoted content can become command arguments. - First-thread context is still prepended at
plugins/platforms/slack/adapter.py:2886-2900.MessageEvent.is_command()requires the final text to start with/(gateway/platforms/base.py:1805-1807), so this can still prevent dispatch. - No regression test covers
@bot !cmd; existing coverage is bare-bang only (tests/gateway/test_slack.py:1145-1201).
Suggested changes
- Port the logic to the plugin adapter, normalize mention-stripped raw text, bypass context prepend for commands, and add the focused regressions. The member-linked #30592 already targets this architecture and covers these cases.
Automated hermes-sweeper review.
| # only fires when the text starts with ``!``) is skipped. After | ||
| # mention-stripping the leading ``!`` is visible, so we run the | ||
| # same logic again here to normalise it to a slash command. | ||
| if text.startswith("!"): |
There was a problem hiding this comment.
Current main migrated this adapter to plugins/platforms/slack/adapter.py in 5600105478ffde29d7566b45421b100eaa29c4ef, so this hunk will not reach the active Slack runtime. Port the normalization there and apply it to the mention-stripped raw text rather than post-block-augmentation text.
Problem
When a user types
@bot !model ...(or any!cmdprefixed with an@mention) in a Slack channel, the!→/rewrite that normally fires for bare!cmdmessages is silently skipped.Root cause
The bang-rewrite pass (around line 2298) guards on
original_text.startswith("!").When the message starts with
<@BOT_UID>, that condition is false and the rewrite never runs.After mention-stripping (line 2527) the text becomes
!model ..., but there is no second rewrite pass — so the message arrives at the dispatcher as plainTEXTinstead ofCOMMAND.Reproducer
Send
@bot !model jp.anthropic.claude-opus-4 --provider bedrockin a Slack channel.Expected: model switches (or asks for confirmation).
Actual: silently ignored / treated as free text.
Fix
After stripping the bot mention, check whether the resulting text starts with
!and, ifis_gateway_known_commandresolves it, rewrite it to/cmd ...and syncoriginal_textso the downstreamMessageType.COMMANDdetection fires correctly.The added code reuses the exact same logic that already exists for the bare-
!path, keeping behaviour identical.Testing
test_slack_channel_session_scopeandtest_help_returns_command_listare pre-existing and unrelated to this change — confirmed by running baseline onmainbefore the patch).