: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(slack-app): always proxy app_mention from primary to secondary region (#59601)
Vojta Bartoša28c252d5d26
diff --git a/products/slack_app/backend/api.py b/products/slack_app/backend/api.pyindex 26fb6b381280..572744b8ba6b 100644--- a/products/slack_app/backend/api.py+++ b/products/slack_app/backend/api.py@@ -1236,6 +1236,12 @@ def route_posthog_code_event_to_relevant_region(event_type = event.get("type")+ # Coding-agent workflows only run in the secondary region (US). Force-reset local_match in+ # the primary region for app_mention so it always proxies to the secondary, regardless of+ # whether a slack integration row exists in the primary.+ if event_type == "app_mention" and request.get_host() == SLACK_PRIMARY_REGION_DOMAIN:+ local_match = None+if local_match and not (settings.DEBUG and request.get_host() == SLACK_PRIMARY_REGION_DOMAIN):if event_type == "app_mention":if not _posthog_code_enabled_for_integration(local_match):diff --git a/products/slack_app/backend/tests/test_posthog_code_event_handler.py b/products/slack_app/backend/tests/test_posthog_code_event_handler.pyindex e3e1250c2c32..8c83cb38f966 100644--- a/products/slack_app/backend/tests/test_posthog_code_event_handler.py+++ b/products/slack_app/backend/tests/test_posthog_code_event_handler.py@@ -118,7 +118,7 @@ class TestRoutePostHogCodeEventToRelevantRegion(TestCase):@patch("products.slack_app.backend.api.sync_connect")@override_settings(DEBUG=False)def test_local_match_starts_temporal_workflow(self, mock_sync_connect, mock_asyncio_run, _mock_flag):- request = self.factory.post("/slack/event-callback/", HTTP_HOST="eu.posthog.com")+ request = self.factory.post("/slack/event-callback/", HTTP_HOST="us.posthog.com")from products.slack_app.backend.api import ROUTE_HANDLED_LOCALLY, route_posthog_code_event_to_relevant_region@@ -177,7 +177,7 @@ class TestRoutePostHogCodeEventToRelevantRegion(TestCase):_mock_flag,mock_get_repos,):- request = self.factory.post("/slack/event-callback/", HTTP_HOST="eu.posthog.com")+ request = self.factory.post("/slack/event-callback/", HTTP_HOST="us.posthog.com")mock_get_repos.return_value = repo_listfrom products.slack_app.backend.api import (@@ -253,6 +253,46 @@ class TestRoutePostHogCodeEventToRelevantRegion(TestCase):passed_integration = mock_unfurl.call_args[0][1]assert passed_integration.id == self.posthog_code_integration.id+ @patch("products.slack_app.backend.api._posthog_code_enabled_for_integration", return_value=True)+ @patch("products.slack_app.backend.api.asyncio.run")+ @patch("products.slack_app.backend.api.sync_connect")+ @patch("products.slack_app.backend.api.proxy_slack_event_to_secondary_region")+ @patch("products.slack_app.backend.api.SLACK_PRIMARY_REGION_DOMAIN", "eu.posthog.com")+ @override_settings(DEBUG=False)+ def test_app_mention_in_primary_always_proxies_even_with_local_integration(+ self, mock_proxy, mock_sync_connect, mock_asyncio_run, _mock_flag+ ):+ # Coding-agent workflows only run in the secondary region (US). Even when a slack+ # integration exists in the primary region (EU), app_mention must proxy rather than+ # handle locally.+ mock_proxy.return_value = True+ request = self.factory.post("/slack/event-callback/", HTTP_HOST="eu.posthog.com")++ from products.slack_app.backend.api import ROUTE_PROXIED, route_posthog_code_event_to_relevant_region++ result = route_posthog_code_event_to_relevant_region(request, self.event, "T12345")++ assert result == ROUTE_PROXIED+ mock_proxy.assert_called_once_with(request)+ mock_sync_connect.assert_not_called()+ mock_asyncio_run.assert_not_called()++ @patch("products.slack_app.backend.api.handle_posthog_link_unfurl")+ @patch("products.slack_app.backend.api.SLACK_PRIMARY_REGION_DOMAIN", "eu.posthog.com")+ @override_settings(DEBUG=False)+ def test_link_shared_in_primary_with_local_integration_handled_locally(self, mock_unfurl):+ # link_shared (unfurl) is not coding-agent specific and should still be handled locally+ # in either region when a slack integration is present.+ request = self.factory.post("/slack/event-callback/", HTTP_HOST="eu.posthog.com")+ link_shared_event = {"type": "link_shared", "channel": "C001", "links": []}++ from products.slack_app.backend.api import ROUTE_HANDLED_LOCALLY, route_posthog_code_event_to_relevant_region++ result = route_posthog_code_event_to_relevant_region(request, link_shared_event, "T12345")++ assert result == ROUTE_HANDLED_LOCALLY+ mock_unfurl.assert_called_once()+@patch("products.slack_app.backend.api.proxy_slack_event_to_secondary_region")@patch("products.slack_app.backend.api.SLACK_PRIMARY_REGION_DOMAIN", "eu.posthog.com")@override_settings(DEBUG=False)