Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(slack_app): post project command replies at channel root for top-level mentions (#73097)

Vojta Bartošf6e703914598
diff --git a/posthog/temporal/ai/slack_app/activities/rules.py b/posthog/temporal/ai/slack_app/activities/rules.py
index e3d9dc315396..1c6e096a7a71 100644
--- a/posthog/temporal/ai/slack_app/activities/rules.py
+++ b/posthog/temporal/ai/slack_app/activities/rules.py
@@ -124,8 +124,11 @@ def handle_posthog_code_slack_mention_command_activity(
event = inputs.event
channel = event.get("channel")
- # Empty anchor posts at the channel root — correct for a slash command invoked outside a thread.
- thread_ts = event.get("thread_ts") or event.get("ts") or ""
+ # Anchor the reply to the thread only when the command was posted in one. For a top-level
+ # mention (or a slash command outside a thread) the empty anchor posts at the channel root,
+ # where the user actually sees it — a thread-anchored ephemeral is only rendered to someone
+ # already viewing that thread, so it reads as no response.
+ thread_ts = event.get("thread_ts") or ""
slack_user_id = event.get("user")
if not channel or not slack_user_id:
return PostHogCodeSlackMentionCommandResult(status="done")
diff --git a/products/slack_app/backend/tests/test_mention_command_activity.py b/products/slack_app/backend/tests/test_mention_command_activity.py
index 7f5302768f98..a49144c88eff 100644
--- a/products/slack_app/backend/tests/test_mention_command_activity.py
+++ b/products/slack_app/backend/tests/test_mention_command_activity.py
@@ -24,10 +24,10 @@ class TestMentionCommandActivity:
)
self.user = User.objects.create_and_join(self.organization, "[email protected]", "pw")
- def _inputs(self, *, command_prefix: str, with_thread: bool) -> PostHogCodeSlackMentionCommandWorkflowInputs:
- event = {"channel": "C1", "user": "U1", "text": "help"}
- if with_thread:
- event["ts"] = "111.1"
+ def _inputs(
+ self, *, command_prefix: str, event_extra: dict[str, str]
+ ) -> PostHogCodeSlackMentionCommandWorkflowInputs:
+ event = {"channel": "C1", "user": "U1", "text": "help", **event_extra}
return PostHogCodeSlackMentionCommandWorkflowInputs(
event=event,
integration_ids=[self.integration.id],
@@ -38,12 +38,15 @@ class TestMentionCommandActivity:
@parameterized.expand(
[
- # A slash command outside a thread carries no ``ts``; the reply must
- # still go out (channel-root anchor) rather than silently no-op on the
- # guard, and it must speak the ``/posthog`` surface.
- ("slash_outside_thread", "/posthog", False, ""),
- # The mention surface always carries a ``ts`` and keeps its copy.
- ("mention_in_thread", "@PostHog", True, "111.1"),
+ # A slash command outside a thread carries neither ts nor thread_ts; the
+ # reply anchors to the channel root and speaks the ``/posthog`` surface.
+ ("slash_outside_thread", "/posthog", {}, ""),
+ # A top-level mention carries only its own ts (no thread_ts). The reply
+ # must anchor to the channel root, not that ts — a thread-anchored reply
+ # is invisible to a user who isn't already viewing the thread.
+ ("mention_top_level", "@PostHog", {"ts": "111.1"}, ""),
+ # A mention inside a real thread carries thread_ts; the reply threads there.
+ ("mention_in_thread", "@PostHog", {"ts": "222.2", "thread_ts": "111.1"}, "111.1"),
]
)
@patch("products.slack_app.backend.services.slack_user_info.get_slack_user_info")
@@ -52,7 +55,7 @@ class TestMentionCommandActivity:
self,
_name: str,
command_prefix: str,
- with_thread: bool,
+ event_extra: dict[str, str],
expected_thread_ts: str,
mock_slack_cls,
mock_info,
@@ -61,7 +64,7 @@ class TestMentionCommandActivity:
client = mock_slack_cls.return_value.client
result = handle_posthog_code_slack_mention_command_activity(
- self._inputs(command_prefix=command_prefix, with_thread=with_thread), self.user.id
+ self._inputs(command_prefix=command_prefix, event_extra=event_extra), self.user.id
)
assert result.status == "done"