Skip to content

The agent that grows with you

fix(slack): a slash command that stops or unblocks the running turn waits for no Slack lookup

John Paul Solivad2ac28c77d25
diff --git a/plugins/platforms/slack/adapter.py b/plugins/platforms/slack/adapter.py
index f65ff3aae1a..727e9af4271 100644
--- a/plugins/platforms/slack/adapter.py
+++ b/plugins/platforms/slack/adapter.py
@@ -6079,15 +6079,8 @@ class SlackAdapter(BasePlatformAdapter):
rejected = self._early_reject_unauthorized(user_id, channel_id, is_dm)
if rejected and not is_dm:
return
- # A slash turn is a human turn: it re-pins the channel prompt and session context, so it
- # must carry the same names and prompt as a message here or the next message flips them.
source = self.build_source(
- chat_id=channel_id,
- chat_name=None if rejected else await self._resolve_channel_name(channel_id, team_id=team_id),
- chat_type="dm" if is_dm else "group",
- user_id=user_id,
- user_name=None if rejected else await self._resolve_user_name(
- user_id, chat_id=channel_id, team_id=team_id),
+ chat_id=channel_id, chat_type="dm" if is_dm else "group", user_id=user_id,
thread_id=thread_id, scope_id=team_id or None)
from gateway.platforms.base import resolve_channel_skills
event = MessageEvent(
@@ -6097,6 +6090,17 @@ class SlackAdapter(BasePlatformAdapter):
channel_prompt=self._channel_prompt_with_identity(channel_id, team_id),
# Bound skills load only when a session starts; "/hermes <question>" can start one.
auto_skill=resolve_channel_skills(self.config.extra, channel_id, None))
+ # A slash turn is a human turn: it re-pins the channel prompt and session context, so it
+ # must carry the same names as a message here or the next message flips them. A command
+ # that interrupts or unblocks the running turn starts none of its own, and a slow
+ # users.info must not hold /stop back while the worker keeps running.
+ from hermes_cli.commands import resolve_command
+ cmd = resolve_command(event.get_command() or "")
+ controls_running_turn = cmd is not None and (
+ cmd.busy_policy == "interrupt_then_dispatch" or cmd.name in ("approve", "deny"))
+ if not rejected and not controls_running_turn:
+ source.chat_name = await self._resolve_channel_name(channel_id, team_id=team_id)
+ source.user_name = await self._resolve_user_name(user_id, chat_id=channel_id, team_id=team_id)
# Stash response_url so the first reply for this channel+user goes ephemeral. COMMAND
# events only: free-form "/hermes <question>" replies must stay public.
response_url = command.get("response_url", "")
diff --git a/tests/plugins/platforms/slack/test_slash_command_channel_prompt.py b/tests/plugins/platforms/slack/test_slash_command_channel_prompt.py
index 9fe9f3765ce..cc909eaff7d 100644
--- a/tests/plugins/platforms/slack/test_slash_command_channel_prompt.py
+++ b/tests/plugins/platforms/slack/test_slash_command_channel_prompt.py
@@ -36,12 +36,15 @@ def _adapter(channel_id: str) -> SlackAdapter:
@pytest.mark.asyncio
[email protected]("channel_id, channel_type, chat_name", [
- ("C_OPS", "channel", "ops"), ("D_ALICE", "im", "Alice")])
-async def test_slash_turn_matches_message_turn_prompt_and_names(channel_id, channel_type, chat_name):
[email protected]("channel_id, channel_type, chat_name, text", [
+ ("C_OPS", "channel", "ops", "what broke?"), ("D_ALICE", "im", "Alice", "what broke?"),
+ ("C_OPS", "channel", "ops", "queue what broke?")], ids=["channel", "dm", "queue-command"])
+async def test_slash_turn_matches_message_turn_prompt_and_names(channel_id, channel_type, chat_name, text):
+ """``queue-command``: a registered command that starts a turn (``/queue <prompt>``) is a human
+ turn like the free-form question, so it carries the same inputs."""
adapter = _adapter(channel_id)
await adapter._handle_slash_command(
- {"command": "/hermes", "text": "what broke?", "user_id": "U_ALICE",
+ {"command": "/hermes", "text": text, "user_id": "U_ALICE",
"channel_id": channel_id, "team_id": "T1"})
await adapter._handle_slack_message(
{"text": "<@U_BOT> what broke?", "user": "U_ALICE", "channel": channel_id,
@@ -58,17 +61,23 @@ async def test_slash_turn_matches_message_turn_prompt_and_names(channel_id, chan
@pytest.mark.asyncio
[email protected]("channel_id, reaches_runner", [("C_OPS", 0), ("D_ALICE", 1)], ids=["channel", "dm"])
-async def test_rejected_slash_sender_costs_no_slack_lookup(channel_id, reaches_runner):
[email protected]("channel_id, authorized, command, reaches_runner", [
+ ("C_OPS", False, "/hermes", 0), ("D_ALICE", False, "/hermes", 1),
+ ("C_OPS", True, "/stop", 1), ("C_OPS", True, "/approve", 1),
+], ids=["rejected-channel", "rejected-dm", "stop", "approve"])
+async def test_slash_that_starts_no_turn_costs_no_slack_lookup(channel_id, authorized, command, reaches_runner):
"""The message path rejects an unauthorized sender before any Slack lookup, and the names the
slash path now resolves must not cost one either. In a DM the runner still gets the event,
without names: it answers an unauthorized DM per ``unauthorized_dm_behavior`` (pairing code
- or decline), and a slash command there is how an unpaired user gets that answer."""
+ or decline), and a slash command there is how an unpaired user gets that answer.
+ ``stop`` / ``approve``: a command that interrupts or unblocks the running turn is handed over
+ before any lookup. A cold ``users.info`` for a second operator must not hold ``/stop`` back
+ while the worker keeps running."""
adapter = _adapter(channel_id)
- adapter.set_authorization_check(lambda *_args, **_kwargs: False)
+ adapter.set_authorization_check(lambda *_args, **_kwargs: authorized)
await adapter._handle_slash_command(
- {"command": "/hermes", "text": "what broke?", "user_id": "U_MALLORY",
- "channel_id": channel_id, "team_id": "T1"})
+ {"command": command, "text": "what broke?" if command == "/hermes" else "",
+ "user_id": "U_MALLORY", "channel_id": channel_id, "team_id": "T1"})
adapter._app.client.users_info.assert_not_awaited()
adapter._app.client.conversations_info.assert_not_awaited()
assert adapter.handle_message.await_count == reaches_runner