Skip to content

The agent that grows with you

fix(slack): a follow-up in a flat reply_in_thread: false channel keeps the silence fallback

kshitijk4poorb17e037e3565
diff --git a/plugins/platforms/slack/adapter.py b/plugins/platforms/slack/adapter.py
index a19741e2a03..d78300d4da5 100644
--- a/plugins/platforms/slack/adapter.py
+++ b/plugins/platforms/slack/adapter.py
@@ -4663,9 +4663,8 @@ class SlackAdapter(BasePlatformAdapter):
user_id=user_id, thread_ts=thread_ts, is_dm=is_dm, media_urls=media_urls,
media_types=media_types, media_text_inlined=media_text_inlined, channel_context=channel_context,
reply_expected=self._slack_reply_expected(
- routing_text, {u for u in (bot_uid, self._bot_user_id) if u}, channel_id=channel_id,
- addressed=is_one_to_one_dm or is_mentioned or is_command_text or force_process,
- is_thread_reply=is_thread_reply))
+ routing_text, bot_uid, channel_id=channel_id, opens_own_session=thread_ts == ts,
+ addressed=is_one_to_one_dm or is_mentioned or is_command_text or force_process))
# React only when directly addressed; MPIMs are shared, so they need a
# mention like any channel.
if (is_one_to_one_dm or is_mentioned) and self._reactions_enabled():
@@ -6359,17 +6358,20 @@ class SlackAdapter(BasePlatformAdapter):
channel_id in self._slack_free_response_channels() or not self._slack_require_mention())
def _slack_reply_expected(
- self, routing_text: str, self_uids: set, *, channel_id: str, addressed: bool,
- is_thread_reply: bool) -> Optional[bool]:
+ self, routing_text: str, bot_uid: Optional[str], *, channel_id: str, addressed: bool,
+ opens_own_session: bool) -> Optional[bool]:
"""``MessageEvent.reply_expected`` for an admitted message. False (a bare silence marker may
- stand) only when it opens by @mentioning someone else, or is a top-level message a
- free-response channel admitted unaddressed. A plain reply in a thread the bot is part of is
- None: it is usually meant for the bot, so the gateway keeps its visible fallback (#110952)."""
+ stand) only when it opens by @mentioning someone else, or is an unaddressed message that a
+ free-response channel admitted as the start of its own session (a new top-level thread).
+ A plain follow-up in a conversation the bot is part of (a thread, or a flat
+ ``reply_in_thread: false`` channel) is None: it is usually meant for the bot, so the
+ gateway keeps its visible fallback (#110952)."""
+ self_uids = {u for u in (bot_uid, self._bot_user_id) if u}
if addressed or self._slack_message_mentions_self(routing_text, self_uids):
return True
if self._slack_message_addressed_to_other_user(routing_text, self_uids):
return False
- return False if not is_thread_reply and self._slack_is_free_channel(channel_id) else None
+ return False if opens_own_session and self._slack_is_free_channel(channel_id) else None
def _slack_message_mentions_self(self, text: str, self_uids: set) -> bool:
"""True when ``text`` @-mentions this bot anywhere, in either ``<@U123>`` or
diff --git a/tests/gateway/test_slack_reply_expected.py b/tests/gateway/test_slack_reply_expected.py
index 8c202610216..dff70ea2bd0 100644
--- a/tests/gateway/test_slack_reply_expected.py
+++ b/tests/gateway/test_slack_reply_expected.py
@@ -29,7 +29,10 @@ def _message(text, ts, **extra):
({}, _message("done?", "1.4", thread_ts=THREAD), None),
({}, _message(f"<@{OTHER_USER_ID}> can you check?", "1.5", thread_ts=THREAD), False),
({"free_response_channels": CHANNEL_ID}, _message("side chatter", "1.6"), False),
-], ids=["dm", "mention", "reaction", "thread-followup", "peer-addressed", "free-channel-top-level"])
+ ({"free_response_channels": CHANNEL_ID, "reply_in_thread": False}, _message("any update?", "1.7"), None),
+ ({}, _message(f"<@{OTHER_USER_ID}> and <@{BOT_USER_ID}|hermes> both look", "1.8", thread_ts=THREAD), True),
+], ids=["dm", "mention", "reaction", "thread-followup", "peer-addressed", "free-channel-top-level",
+ "flat-channel-followup", "peer-led-but-mentions-bot"])
async def test_admitted_message_carries_whether_it_was_addressed(adapter, extra, event, expected):
adapter.config.extra.update(extra)
adapter._mentioned_threads.add(THREAD)
diff --git a/website/docs/user-guide/messaging/index.md b/website/docs/user-guide/messaging/index.md
index 493e5858505..b343b584e17 100644
--- a/website/docs/user-guide/messaging/index.md
+++ b/website/docs/user-guide/messaging/index.md
@@ -154,7 +154,7 @@ user: next message
Failed turns still surface as errors; Hermes does not hide failures just because the text resembles a silence token.
-On a message from a person, a bare silence token is replaced by a short notice, because a message that needed a reply must not vanish. Internal wakes such as background-process notifications may stay silent, and so may a message the platform adapter reports as not addressed to the bot. Slack reports this for messages that open by @mentioning someone else and for unmentioned top-level messages in free-response channels; other platforms always get the notice.
+On a message from a person, a bare silence token is replaced by a short notice, because a message that needed a reply must not vanish. Internal wakes such as background-process notifications may stay silent, and so may a message the platform adapter reports as not addressed to the bot. Slack reports this for messages that open by @mentioning someone else and for unmentioned top-level messages that start a new thread in a free-response channel; other platforms always get the notice.
## Quick Setup
diff --git a/website/docs/user-guide/messaging/slack.md b/website/docs/user-guide/messaging/slack.md
index 818a708b3ce..d70a3e4ead2 100644
--- a/website/docs/user-guide/messaging/slack.md
+++ b/website/docs/user-guide/messaging/slack.md
@@ -676,7 +676,7 @@ Set this to `true` when the bot follows busy threads (via thread auto-engagement
:::
:::note Silence markers on messages not addressed to the bot
-When the bot answers a human message with only a [silence token](index.md#intentional-silence-tokens), Hermes normally posts a short notice instead so a question never goes unanswered. On Slack the token is allowed to stand when the message opened by @mentioning someone else, or was a top-level message in a `free_response_channels` channel without a mention. A 1:1 DM, a mention of the bot, a command, a reaction trigger, or a plain reply in a thread the bot is part of still gets the notice.
+When the bot answers a human message with only a [silence token](index.md#intentional-silence-tokens), Hermes normally posts a short notice instead so a question never goes unanswered. On Slack the token is allowed to stand when the message opened by @mentioning someone else, or was an unmentioned top-level message in a `free_response_channels` channel that starts its own thread (the default `reply_in_thread: true`). A 1:1 DM, a mention of the bot, a command, a reaction trigger, or a plain follow-up in a conversation the bot is part of (a thread, or a `reply_in_thread: false` channel) still gets the notice.
:::
:::info