Skip to content

fix(slack): dispatch @bot !cmd as command in threads - #30592

Closed
cypres0099 wants to merge 1 commit into
NousResearch:mainfrom
cypres0099:fix/slack-thread-bang-command-dispatch
Closed

fix(slack): dispatch @bot !cmd as command in threads#30592
cypres0099 wants to merge 1 commit into
NousResearch:mainfrom
cypres0099:fix/slack-thread-bang-command-dispatch

Conversation

@cypres0099

@cypres0099 cypres0099 commented May 22, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes mention-prefixed gateway commands in Slack threads. Inputs such as @bot !new are now normalized after the bot mention is removed and before Slack rich-content augmentation, so they dispatch as commands instead of becoming conversational text or acquiring serialized block content as arguments.

The command path also skips first-thread conversational-context backfill, which would otherwise prepend text before the slash and make command detection fail.

This is the targeted current-architecture port requested by the automated maintainer sweep; Slack now lives in plugins/platforms/slack/adapter.py.

Related Issue

N/A — this was reproduced in a live Slack thread; no separate upstream issue is open.

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • plugins/platforms/slack/adapter.py
    • Re-normalizes recognized !command input after mention stripping.
    • Performs command recognition before rich Slack block augmentation and skips augmentation for recognized commands.
    • Skips first-thread context backfill for commands so command text remains slash-prefixed.
  • tests/gateway/test_slack.py
    • Covers mention-prefixed bang commands, including no-space and unknown-token cases.
    • Covers thread-context bypass for commands.
    • Adds the requested combined mention + bang command + rich-text-block regression.

How to Test

  1. Run HOME=/tmp/hermes-ci-home scripts/run_tests.sh -j 1 tests/gateway/test_slack.py.
  2. Confirm all 221 tests pass.
  3. In a mention-required Slack thread, send @bot !new with rich block content and confirm it dispatches /new without block serialization being appended as arguments.

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: macOS, Python 3.11

The canonical full suite was run on the current-main rebase. It reported 27 failures and 8 timeout/collection files outside this two-file diff, in the macOS/environment-sensitive areas reproduced on clean current main. The complete Slack test file passes 221/221.

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Screenshots / Logs

tests/gateway/test_slack.py: 221 passed, 0 failed
ruff check .: passed
git diff --check upstream/main...HEAD: passed
check-windows-footguns.py --diff upstream/main: passed (2 files scanned)

@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 May 22, 2026
@cypres0099

Copy link
Copy Markdown
Contributor Author

Fresh status check: all checks are green and the PR remains a focused Slack gateway bug fix (2 files, regression tests included). GitHub shows it as blocked only by the normal review/merge gate, not by CI. I believe this is ready for maintainer review when someone has bandwidth.

@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 the mention-prefixed thread-command path. The underlying issue is still present on current main: plugins/platforms/slack/adapter.py:2631 only rewrites a raw leading !, while mention stripping at :2870-2872 does not re-normalize it; first-thread context is then prepended at :2888-2900 before command tagging at :2902-2905.

Problems

  • The branch changes gateway/platforms/slack.py, but Slack moved to plugins/platforms/slack/adapter.py in 5600105478ffde29d7566b45421b100eaa29c4ef; this needs a targeted port rather than a direct cherry-pick.
  • The proposed original_text = text is after Slack block augmentation. Current main appends extracted/serialized blocks at plugins/platforms/slack/adapter.py:2655-2672; this can make a mention-prefixed command carry rich-text payload as command arguments. The related open #43533 covers that distinct command-content issue.

Suggested changes

  • Port the normalization/context guard to the plugin adapter, and normalize commands before augmentation or skip augmentation for recognized commands.
  • Add a combined mention-prefixed bang command with rich-text-block regression case.

Automated hermes-sweeper review.

Comment thread gateway/platforms/slack.py Outdated
@teknium1 teknium1 added sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state 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 13, 2026
@cypres0099

Copy link
Copy Markdown
Contributor Author

Final refresh complete at e9f9a0c71: the sweeper-requested plugin-adapter port and rich-content regression are included, the review thread is resolved, all required CI checks pass, and GitHub reports the PR CLEAN/MERGEABLE.

Copy link
Copy Markdown
Contributor

Thanks for the focused current-adapter port and regression coverage. I reproduced the same @bot !cmd / first-entry thread behavior and opened #66069 as a deliberately narrow, complementary follow-up.

The distinction is:

  • fix(slack): dispatch @bot !cmd as command in threads #30592 fixes recognition and text integrity for mention-prefixed commands: it re-runs bang-command normalization after stripping @bot, avoids rich-block enrichment changing the arguments, and skips _fetch_thread_context() for commands.
  • fix(slack): preserve thread context for commands #66069 fixes history preservation for commands that are already recognized (for example plain !queue in an existing thread after a gateway restart): it leaves exact normalized command text in MessageEvent.text and puts recovered thread history in the existing MessageEvent.channel_context field.

That keeps text == "/queue follow up" and exact command arguments while avoiding loss of the recovered thread history. It also preserves the normal-message backfill path. The full tests/gateway/test_slack.py suite passes 245/245, along with Ruff, git diff --check, and the Windows-footgun scan.

The patches touch the same nearby adapter block, so I’m happy to rebase or fold #66069 into this PR if maintainers prefer one combined change.

@teknium1

Copy link
Copy Markdown
Contributor

Merged via #69479 — your commit was cherry-picked/reapplied onto current main with your authorship preserved in git history: your mention-then-bang rewrite (earliest fix for this ordering class) was cherry-picked directly.

Thanks for the contribution!

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 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-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants