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): stop treating DMs as Slack Connect channels (#130876)

Vojta Bartoš9475677e3698
diff --git a/products/slack_app/backend/services/slack_conversations.py b/products/slack_app/backend/services/slack_conversations.py
index fd5bc4cad16d..428d8cddf347 100644
--- a/products/slack_app/backend/services/slack_conversations.py
+++ b/products/slack_app/backend/services/slack_conversations.py
@@ -109,6 +109,11 @@ def channel_ext_shared_state(slack: SlackIntegration, channel: str) -> bool | No
For a caller that can wait and ask again, a failed lookup is not the same as a shared
channel.
"""
+ # A DM with the app is never a Slack Connect channel. The lookup below also cannot answer
+ # for a `D…` id because the app does not request `im:read`, so without this check every DM
+ # reads as shared and is sent to an approval it can never get.
+ if channel.startswith("D"):
+ return False
try:
info = slack.client.conversations_info(channel=channel)
conversation: dict[str, Any] = info.get("channel") or {}
diff --git a/products/slack_app/backend/tests/services/test_slack_conversations.py b/products/slack_app/backend/tests/services/test_slack_conversations.py
index fd58812d24ca..2819e1603e2a 100644
--- a/products/slack_app/backend/tests/services/test_slack_conversations.py
+++ b/products/slack_app/backend/tests/services/test_slack_conversations.py
@@ -4,7 +4,7 @@ from unittest.mock import MagicMock
from slack_sdk.errors import SlackApiError
from products.slack_app.backend.models import SlackThreadTaskMapping
-from products.slack_app.backend.services.slack_conversations import resolve_conversation_type
+from products.slack_app.backend.services.slack_conversations import channel_is_ext_shared, resolve_conversation_type
ConversationType = SlackThreadTaskMapping.ConversationType
@@ -78,3 +78,20 @@ class TestResolveConversationType:
result = resolve_conversation_type(_slack(error=error), {"type": "app_mention"}, "C123")
assert result == ConversationType.UNKNOWN
+
+
+class TestChannelIsExtShared:
+ @pytest.mark.parametrize(
+ "channel_id,expected",
+ [
+ ("D123", False),
+ ("C123", True),
+ ],
+ )
+ def test_failed_lookup_fails_closed_except_for_a_dm(self, channel_id: str, expected: bool) -> None:
+ # `conversations.info` fails on every `D…` id in production because the app lacks
+ # `im:read`. A DM must not fall into the fail-closed path, or every DM click is sent to
+ # a channel approval it can never get. A channel still fails closed.
+ slack = _slack(error=SlackApiError("missing_scope", {"error": "missing_scope"}))
+
+ assert channel_is_ext_shared(slack, channel_id) is expected