Skip to content

The agent that grows with you

fix(slack): gated slash commands get a bare ack, not "Running /x"

kshitijk4poor0089fca37d1d
diff --git a/plugins/platforms/slack/adapter.py b/plugins/platforms/slack/adapter.py
index 74f37031021..28a152fe304 100644
--- a/plugins/platforms/slack/adapter.py
+++ b/plugins/platforms/slack/adapter.py
@@ -1673,11 +1673,7 @@ class SlackAdapter(BasePlatformAdapter):
else: # pragma: no cover - registry always non-empty
_slash_pattern = re.compile(r"^/hermes$")
- @self._app.command(_slash_pattern)
- async def handle_hermes_command(ack, command):
- slash = (command.get("command") or "").lstrip("/")
- await ack(response_type="ephemeral", text=t("platform.slack.slash.running", command=slash))
- await self._handle_slash_command(command)
+ self._app.command(_slash_pattern)(self._handle_hermes_command)
# Approval buttons, slash-confirm buttons (tools/slash_confirm.py), feedback.
for _action_id in self._APPROVAL_CHOICES:
@@ -6042,6 +6038,25 @@ class SlackAdapter(BasePlatformAdapter):
logger.debug("[Slack] Thread-root image recovery failed: %s", exc)
return media_urls, media_types
+ def _slash_channel_gated(self, channel_id: str) -> bool:
+ """The message path's channel gates (_prefilter_inbound, _channel_gate_allows) for a slash
+ command: ignored channels are never touched, and outside allowed_channels only a 1:1 DM is
+ answered. By id alone, so no lookup can drop a control command."""
+ if self._is_ignored_channel(channel_id):
+ return True
+ allowed_channels = self._slack_allowed_channels()
+ return bool(allowed_channels) and not str(channel_id).startswith("D") and channel_id not in allowed_channels
+
+ async def _handle_hermes_command(self, ack, command: dict) -> None:
+ """Bolt listener for every native slash: ack within 3s, then run. A gated channel gets a
+ bare ack, never a "Running /x" promise the gate in _handle_slash_command will break."""
+ if self._slash_channel_gated(command.get("channel_id", "")):
+ await ack()
+ else:
+ slash = (command.get("command") or "").lstrip("/")
+ await ack(response_type="ephemeral", text=t("platform.slack.slash.running", command=slash))
+ await self._handle_slash_command(command)
+
async def _handle_slash_command(self, command: dict) -> None:
"""Slash commands: native ``/<command> [args]`` for every COMMAND_REGISTRY entry, or
``/hermes <subcommand> [args]``; other text after ``/hermes`` is a regular message."""
@@ -6052,17 +6067,10 @@ class SlackAdapter(BasePlatformAdapter):
self._remember_channel_team(channel_id, team_id)
text = self._slash_command_text(command)
thread_id = self._slash_thread_id(command)
- # The message path's channel gates (_prefilter_inbound, _channel_gate_allows): ignored
- # channels are never touched, and outside allowed_channels only a 1:1 DM is answered. By id
- # alone, so no lookup can drop a control command.
- is_dm = str(channel_id).startswith("D")
- if self._is_ignored_channel(channel_id):
- logger.debug("[Slack] Ignoring slash command in ignored channel: %s", channel_id)
- return
- allowed_channels = self._slack_allowed_channels()
- if allowed_channels and not is_dm and channel_id not in allowed_channels:
- logger.debug("[Slack] Ignoring slash command in non-allowed channel: %s", channel_id)
+ if self._slash_channel_gated(channel_id):
+ logger.debug("[Slack] Ignoring slash command in ignored/non-allowed channel: %s", channel_id)
return
+ is_dm = str(channel_id).startswith("D")
if is_dm and self._slack_disable_dms():
logger.info(
"[Slack] Ignoring slash command from DM because Slack DMs are disabled: channel=%s user=%s",
diff --git a/tests/gateway/test_slack.py b/tests/gateway/test_slack.py
index ab696cbbbd1..3afd6f88712 100644
--- a/tests/gateway/test_slack.py
+++ b/tests/gateway/test_slack.py
@@ -260,12 +260,16 @@ class TestSlashCommandSessionIsolation:
async def test_slash_command_obeys_message_channel_gates(
self, adapter, channel_id, extra, dispatched):
"""allowed_channels / ignored_channels gate a slash command like a message in the same
- conversation: every conversation but a 1:1 DM."""
+ conversation: every conversation but a 1:1 DM. A gated command gets a bare ack, never a
+ "Running /x" promise."""
adapter.config.extra.update(extra)
- await adapter._handle_slash_command(
- {"text": "hello", "user_id": "U123", "channel_id": channel_id, "team_id": "T123"})
+ ack = AsyncMock()
+ await adapter._handle_hermes_command(ack, {
+ "command": "/status", "text": "hello", "user_id": "U123", "channel_id": channel_id,
+ "team_id": "T123"})
assert adapter.handle_message.await_count == (1 if dispatched else 0)
+ assert ("text" in ack.await_args.kwargs) == dispatched
class TestSlackWorkspaceCollisionIsolation: