Skip to content

fix(slack): re-apply bang→slash rewrite after @mention strip - #47115

Closed
zenplace-system wants to merge 1 commit into
NousResearch:mainfrom
zenplace-system:fix/slack-mention-bang-command-rewrite
Closed

fix(slack): re-apply bang→slash rewrite after @mention strip#47115
zenplace-system wants to merge 1 commit into
NousResearch:mainfrom
zenplace-system:fix/slack-mention-bang-command-rewrite

Conversation

@zenplace-system

Copy link
Copy Markdown

Problem

When a user types @bot !model ... (or any !cmd prefixed with an @mention) in a Slack channel, the !/ rewrite that normally fires for bare !cmd messages 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 plain TEXT instead of COMMAND.

Reproducer

Send @bot !model jp.anthropic.claude-opus-4 --provider bedrock in 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, if is_gateway_known_command resolves it, rewrite it to /cmd ... and sync original_text so the downstream MessageType.COMMAND detection fires correctly.

The added code reuses the exact same logic that already exists for the bare-! path, keeping behaviour identical.

Testing

  • Existing Slack test suite passes (failures in test_slack_channel_session_scope and test_help_returns_command_list are pre-existing and unrelated to this change — confirmed by running baseline on main before the patch).
  • Manually verified the rewrite logic with a Python reproducer:
text = '<@UBOT123> !model jp.anthropic.claude-opus-4-8 --provider bedrock'
# After mention strip:
# → '!model jp.anthropic.claude-opus-4-8 --provider bedrock'
# After bang rewrite (new code):
# → '/model jp.anthropic.claude-opus-4-8 --provider bedrock'  ✅

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`.
@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery platform/slack Slack app adapter P2 Medium — degraded but workaround exists duplicate This issue or pull request already exists labels Jun 16, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

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

Thanks for isolating a real Slack command-routing gap.

Problems

  • Current main moved the runtime adapter from gateway/platforms/slack.py to plugins/platforms/slack/adapter.py in 5600105478ffde29d7566b45421b100eaa29c4ef; 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("!"):

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.

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.

@teknium1 teknium1 added sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 14, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Closing as superseded by #69479 (merged): duplicate of #30592's re-normalization approach and targeted the pre-plugin-migration file.

Thanks for the work — it's credited in #69479's summary.

@teknium1 teknium1 closed this Jul 23, 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 duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists 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 type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants