: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
revert(slack-app): undo slack integration kind unification for coding-agent mentions (#59720)
Vojta Bartošce40d8007358
diff --git a/posthog/temporal/ai/posthog_code_slack_interactivity.py b/posthog/temporal/ai/posthog_code_slack_interactivity.pyindex 86b5594b02bc..0ee783c2db50 100644--- a/posthog/temporal/ai/posthog_code_slack_interactivity.py+++ b/posthog/temporal/ai/posthog_code_slack_interactivity.py@@ -95,7 +95,9 @@ def process_posthog_code_task_termination_payload(payload: dict[str, Any]) -> Noreturntry:- integration = Integration.objects.get(id=integration_id, kind="slack", integration_id=slack_team_id)+ integration = Integration.objects.get(+ id=integration_id, kind="slack-posthog-code", integration_id=slack_team_id+ )except Integration.DoesNotExist:logger.warning("posthog_code_terminate_integration_not_found", integration_id=integration_id)returndiff --git a/posthog/temporal/ai/posthog_code_slack_mention.py b/posthog/temporal/ai/posthog_code_slack_mention.pyindex b09a0956ea11..1fb04a4d9a04 100644--- a/posthog/temporal/ai/posthog_code_slack_mention.py+++ b/posthog/temporal/ai/posthog_code_slack_mention.py@@ -360,7 +360,7 @@ def resolve_posthog_code_slack_user_activity(integration = Integration.objects.select_related("team", "team__organization").get(id=inputs.integration_id,- kind="slack",+ kind="slack-posthog-code",integration_id=inputs.slack_team_id,)slack = SlackIntegration(integration)@@ -386,7 +386,7 @@ def handle_posthog_code_rules_command_activity(integration = Integration.objects.select_related("team", "team__organization").get(id=inputs.integration_id,- kind="slack",+ kind="slack-posthog-code",integration_id=inputs.slack_team_id,)slack = SlackIntegration(integration)@@ -652,7 +652,7 @@ def collect_posthog_code_thread_messages_activity(integration = Integration.objects.select_related("team", "team__organization").get(id=inputs.integration_id,- kind="slack",+ kind="slack-posthog-code",integration_id=inputs.slack_team_id,)slack = SlackIntegration(integration)@@ -675,7 +675,7 @@ def select_posthog_code_repository_activity(integration = Integration.objects.select_related("team", "team__organization").get(id=inputs.integration_id,- kind="slack",+ kind="slack-posthog-code",integration_id=inputs.slack_team_id,)all_repos = _get_full_repo_names(integration)@@ -713,7 +713,7 @@ def post_posthog_code_no_repos_activity(integration = Integration.objects.select_related("team", "team__organization").get(id=inputs.integration_id,- kind="slack",+ kind="slack-posthog-code",integration_id=inputs.slack_team_id,)slack = SlackIntegration(integration)@@ -744,7 +744,7 @@ def post_posthog_code_repo_picker_activity(integration = Integration.objects.select_related("team", "team__organization").get(id=inputs.integration_id,- kind="slack",+ kind="slack-posthog-code",integration_id=inputs.slack_team_id,)slack = SlackIntegration(integration)@@ -788,7 +788,7 @@ def create_posthog_code_task_for_repo_activity(integration = Integration.objects.select_related("team", "team__organization").get(id=inputs.integration_id,- kind="slack",+ kind="slack-posthog-code",integration_id=inputs.slack_team_id,)slack = SlackIntegration(integration)@@ -914,7 +914,7 @@ def create_posthog_code_routing_rule_activity(integration = Integration.objects.select_related("team", "team__organization").get(id=inputs.integration_id,- kind="slack",+ kind="slack-posthog-code",integration_id=inputs.slack_team_id,)slack = SlackIntegration(integration)@@ -994,7 +994,7 @@ def forward_posthog_code_followup_activity(integration = Integration.objects.select_related("team", "team__organization").get(id=inputs.integration_id,- kind="slack",+ kind="slack-posthog-code",integration_id=inputs.slack_team_id,)slack = SlackIntegration(integration)@@ -1437,7 +1437,7 @@ def post_posthog_code_picker_timeout_activity(integration = Integration.objects.select_related("team", "team__organization").get(id=inputs.integration_id,- kind="slack",+ kind="slack-posthog-code",integration_id=inputs.slack_team_id,)slack = SlackIntegration(integration)@@ -1467,7 +1467,7 @@ def post_posthog_code_internal_error_activity(integration = Integration.objects.select_related("team", "team__organization").get(id=inputs.integration_id,- kind="slack",+ kind="slack-posthog-code",integration_id=inputs.slack_team_id,)slack = SlackIntegration(integration)diff --git a/products/slack_app/backend/api.py b/products/slack_app/backend/api.pyindex 572744b8ba6b..c77f49950049 100644--- a/products/slack_app/backend/api.py+++ b/products/slack_app/backend/api.py@@ -858,7 +858,9 @@ def _replace_repo_picker_message_with_selection() -> None:try:# nosemgrep: idor-lookup-without-team — Slack webhook: no team context; scoped by PK + kind + Slack team ID- integration = Integration.objects.get(id=integration_id, kind="slack", integration_id=slack_team_id)+ integration = Integration.objects.get(+ id=integration_id, kind="slack-posthog-code", integration_id=slack_team_id+ )slack = SlackIntegration(integration)text = f"Repository selected: `{selected_repo}`"slack.client.chat_update(@@ -890,7 +892,9 @@ def _replace_repo_picker_message_with_no_repo() -> None:try:# nosemgrep: idor-lookup-without-team — Slack webhook: no team context; scoped by PK + kind + Slack team ID- integration = Integration.objects.get(id=integration_id, kind="slack", integration_id=slack_team_id)+ integration = Integration.objects.get(+ id=integration_id, kind="slack-posthog-code", integration_id=slack_team_id+ )slack = SlackIntegration(integration)text = "Continuing without a repository."slack.client.chat_update(@@ -1222,31 +1226,34 @@ def route_posthog_code_event_to_relevant_region(slack_team_id: str,event_id: str | None = None,) -> str:- # The webhook serves the regular slack integration; app_mention activation is gated- # by the posthog-code-slack-availability feature flag rather than a separate kind.- local_match = (+ # One webhook endpoint serves both the notifications integration (kind="slack") and the+ # coding-agent integration (kind="slack-posthog-code"). What counts as a "local match" has+ # to depend on event type: app_mention needs the coding-agent integration specifically,+ # while link_shared (unfurl) works with either kind. Without this, a region that has only a+ # notifications install for a workspace would silently swallow mentions instead of+ # proxying to the region that holds the coding-agent install.+ integrations = list(Integration.objects.filter(- kind="slack",+ kind__in=["slack", "slack-posthog-code"],integration_id=slack_team_id,).select_related("team", "team__organization", "created_by").order_by("id")- .first())+ coding_agent_integration = next((i for i in integrations if i.kind == "slack-posthog-code"), None)+ any_integration = integrations[0] if integrations else Noneevent_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 event_type == "app_mention":+ local_match = coding_agent_integration+ else:+ local_match = any_integrationif 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):logger.info(- "slack_app_mention_flag_disabled",+ "posthog_code_event_flag_off",slack_team_id=slack_team_id,organization_id=str(local_match.team.organization_id),)@@ -1278,7 +1285,7 @@ def route_posthog_code_event_to_relevant_region(success = proxy_slack_event_to_secondary_region(request)return ROUTE_PROXIED if success else ROUTE_PROXY_FAILEDelse:- logger.warning("slack_app_integration_not_found", slack_team_id=slack_team_id)+ logger.warning("posthog_code_no_integration_found", slack_team_id=slack_team_id)return ROUTE_NO_INTEGRATION@@ -1319,15 +1326,15 @@ def posthog_code_event_handler(request: HttpRequest) -> HttpResponse:return HttpResponse(status=405)try:- slack_config = SlackIntegration.slack_config()- validate_slack_request(request, slack_config["SLACK_APP_SIGNING_SECRET"])+ posthog_code_config = SlackIntegration.posthog_code_slack_config()+ validate_slack_request(request, posthog_code_config["SLACK_POSTHOG_CODE_SIGNING_SECRET"])except SlackIntegrationError as e:- logger.warning("slack_event_invalid_request", error=str(e))+ logger.warning("posthog_code_event_invalid_request", error=str(e))return HttpResponse("Invalid request", status=403)retry_num = request.headers.get("X-Slack-Retry-Num")if retry_num:- logger.info("slack_event_retry", retry_num=retry_num)+ logger.info("posthog_code_event_retry", retry_num=retry_num)return HttpResponse(status=200)try:@@ -1456,7 +1463,7 @@ def _handle_repo_picker_options(payload: dict) -> JsonResponse:team_id = payload.get("team", {}).get("id")if team_id:fallback_integration = (- Integration.objects.filter(kind="slack", integration_id=team_id).order_by("id").first()+ Integration.objects.filter(kind="slack-posthog-code", integration_id=team_id).order_by("id").first())if fallback_integration:hinted_integration_id = fallback_integration.id@@ -1490,7 +1497,9 @@ def _handle_repo_picker_options(payload: dict) -> JsonResponse:if not integration_id:raise Integration.DoesNotExist# nosemgrep: idor-lookup-without-team — Slack webhook: no team context; scoped by PK + kind + Slack team ID- integration = Integration.objects.get(id=integration_id, kind="slack", integration_id=slack_team_id)+ integration = Integration.objects.get(+ id=integration_id, kind="slack-posthog-code", integration_id=slack_team_id+ )except Integration.DoesNotExist:logger.info("posthog_code_repo_picker_options_no_integration", context_token=context_token)return JsonResponse({"options": []})@@ -1567,7 +1576,9 @@ def _handle_repo_picker_submit(payload: dict) -> HttpResponse:try:# nosemgrep: idor-lookup-without-team — Slack webhook: no team context; scoped by PK + kind + Slack team ID- integration = Integration.objects.get(id=integration_id, kind="slack", integration_id=slack_team_id)+ integration = Integration.objects.get(+ id=integration_id, kind="slack-posthog-code", integration_id=slack_team_id+ )SlackIntegration(integration).client.chat_postMessage(channel=channel,thread_ts=thread_ts,@@ -1705,10 +1716,10 @@ def posthog_code_interactivity_handler(request: HttpRequest) -> HttpResponse:return HttpResponse(status=405)try:- slack_config = SlackIntegration.slack_config()- validate_slack_request(request, slack_config["SLACK_APP_SIGNING_SECRET"])+ posthog_code_config = SlackIntegration.posthog_code_slack_config()+ validate_slack_request(request, posthog_code_config["SLACK_POSTHOG_CODE_SIGNING_SECRET"])except SlackIntegrationError as e:- logger.warning("slack_interactivity_invalid_request", error=str(e))+ logger.warning("posthog_code_interactivity_invalid_request", error=str(e))return HttpResponse("Invalid request", status=403)try:@@ -1738,19 +1749,19 @@ def posthog_code_interactivity_handler(request: HttpRequest) -> HttpResponse:if slack_team_id and ctx_integration_id:local = Integration.objects.filter( # nosemgrep: idor-lookup-without-teamid=ctx_integration_id, # nosemgrep: idor-taint-user-input-to-model-get- kind="slack",+ kind="slack-posthog-code",integration_id=slack_team_id,).exists()elif slack_team_id and hinted_integration_id and hinted_user_id and requesting_user == hinted_user_id:local = Integration.objects.filter( # nosemgrep: idor-lookup-without-teamid=hinted_integration_id, # nosemgrep: idor-taint-user-input-to-model-get- kind="slack",+ kind="slack-posthog-code",integration_id=slack_team_id,).exists()elif slack_team_id and terminate_integration_id and (not terminate_user_id or requesting_user == terminate_user_id):local = Integration.objects.filter( # nosemgrep: idor-lookup-without-teamid=terminate_integration_id, # nosemgrep: idor-taint-user-input-to-model-get- kind="slack",+ kind="slack-posthog-code",integration_id=slack_team_id,).exists()diff --git a/products/slack_app/backend/tests/test_collect_thread_messages.py b/products/slack_app/backend/tests/test_collect_thread_messages.pyindex c884eac270da..704592b86017 100644--- a/products/slack_app/backend/tests/test_collect_thread_messages.py+++ b/products/slack_app/backend/tests/test_collect_thread_messages.py@@ -169,7 +169,7 @@ class TestCollectThreadMessages:self.team = Team.objects.create(organization=self.organization, name="Test Team")self.integration = Integration.objects.create(team=self.team,- kind="slack",+ kind="slack-posthog-code",integration_id="T12345",sensitive_config={"access_token": "xoxb-test"},)diff --git a/products/slack_app/backend/tests/test_followup_forwarding.py b/products/slack_app/backend/tests/test_followup_forwarding.pyindex dda4d32a7455..37731c22069e 100644--- a/products/slack_app/backend/tests/test_followup_forwarding.py+++ b/products/slack_app/backend/tests/test_followup_forwarding.py@@ -40,7 +40,9 @@ class TestSlackThreadTaskMapping(TestCase):self.org = Organization.objects.create(name="TestOrg")self.team = Team.objects.create(organization=self.org, name="TestTeam")self.user = User.objects.create(email="[email protected]")- self.integration = Integration.objects.create(team=self.team, kind="slack", integration_id="T_SLACK", config={})+ self.integration = Integration.objects.create(+ team=self.team, kind="slack-posthog-code", integration_id="T_SLACK", config={}+ )self.task = self.Task.objects.create(team=self.team,title="Test task",@@ -136,7 +138,9 @@ class TestCreatePostHogCodeTaskForRepoActivity(TestCase):self.org = Organization.objects.create(name="TestOrg")self.team = Team.objects.create(organization=self.org, name="TestTeam")self.user = User.objects.create(email="[email protected]", distinct_id="user-1")- self.integration = Integration.objects.create(team=self.team, kind="slack", integration_id="T_SLACK", config={})+ self.integration = Integration.objects.create(+ team=self.team, kind="slack-posthog-code", integration_id="T_SLACK", config={}+ )@patch("products.tasks.backend.temporal.client.execute_task_processing_workflow")@patch("posthog.models.integration.SlackIntegration")@@ -405,7 +409,9 @@ class TestForwardPostHogCodeFollowupActivity(TestCase):self.org = Organization.objects.create(name="TestOrg")self.team = Team.objects.create(organization=self.org, name="TestTeam")self.user = User.objects.create(email="[email protected]")- self.integration = Integration.objects.create(team=self.team, kind="slack", integration_id="T_SLACK", config={})+ self.integration = Integration.objects.create(+ team=self.team, kind="slack-posthog-code", integration_id="T_SLACK", config={}+ )self.task = self.Task.objects.create(team=self.team,title="Test task",diff --git a/products/slack_app/backend/tests/test_guess_repository.py b/products/slack_app/backend/tests/test_guess_repository.pyindex c17f6ed4cfa4..45f3125090f4 100644--- a/products/slack_app/backend/tests/test_guess_repository.py+++ b/products/slack_app/backend/tests/test_guess_repository.py@@ -40,7 +40,7 @@ class TestGetFullRepoNames:self.slack_integration = Integration.objects.create(team=self.team,- kind="slack",+ kind="slack-posthog-code",integration_id="T12345",sensitive_config={"access_token": "xoxb-test"},)@@ -163,7 +163,7 @@ class TestGetFullRepoNamesCache:self.team = Team.objects.create(organization=self.organization, name="Cache Team")self.slack_integration = Integration.objects.create(team=self.team,- kind="slack",+ kind="slack-posthog-code",integration_id="T_CACHE",sensitive_config={"access_token": "xoxb-cache"},)@@ -206,7 +206,7 @@ class TestGetFullRepoNamesCache:team_b = Team.objects.create(organization=org_b, name="Other Team")slack_b = Integration.objects.create(team=team_b,- kind="slack",+ kind="slack-posthog-code",integration_id="T_OTHER",sensitive_config={"access_token": "xoxb-other"},)@@ -323,7 +323,7 @@ class TestPostRepoPickerPrewarm:self.team = Team.objects.create(organization=self.organization, name="Prewarm Team")self.slack_integration = Integration.objects.create(team=self.team,- kind="slack",+ kind="slack-posthog-code",integration_id="T_PREWARM",sensitive_config={"access_token": "xoxb-prewarm"},)@@ -390,7 +390,7 @@ class TestSelectRepository:self.slack_integration = Integration.objects.create(team=self.team,- kind="slack",+ kind="slack-posthog-code",integration_id="T12345",sensitive_config={"access_token": "xoxb-test"},)@@ -748,7 +748,7 @@ class TestHandleRulesCommandActivity:self.integration = Integration.objects.create(team=self.team,- kind="slack",+ kind="slack-posthog-code",integration_id="T12345",sensitive_config={"access_token": "xoxb-test"},)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 8c83cb38f966..fa03bc212afd 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@@ -34,22 +34,22 @@ class TestPostHogCodeEventHandler(TestCase):**extra_headers,)- @patch("products.slack_app.backend.api.SlackIntegration.slack_config")+ @patch("products.slack_app.backend.api.SlackIntegration.posthog_code_slack_config")def test_url_verification(self, mock_config):- mock_config.return_value = {"SLACK_APP_SIGNING_SECRET": self.signing_secret}+ mock_config.return_value = {"SLACK_POSTHOG_CODE_SIGNING_SECRET": self.signing_secret}response = self._post_event({"type": "url_verification", "challenge": "test-challenge-123"})assert response.status_code == 200assert response.json() == {"challenge": "test-challenge-123"}- @patch("products.slack_app.backend.api.SlackIntegration.slack_config")+ @patch("products.slack_app.backend.api.SlackIntegration.posthog_code_slack_config")def test_invalid_signature(self, mock_config):- mock_config.return_value = {"SLACK_APP_SIGNING_SECRET": "different-secret"}+ mock_config.return_value = {"SLACK_POSTHOG_CODE_SIGNING_SECRET": "different-secret"}response = self._post_event({"type": "url_verification", "challenge": "test"})assert response.status_code == 403- @patch("products.slack_app.backend.api.SlackIntegration.slack_config")+ @patch("products.slack_app.backend.api.SlackIntegration.posthog_code_slack_config")def test_retry_returns_200(self, mock_config):- mock_config.return_value = {"SLACK_APP_SIGNING_SECRET": self.signing_secret}+ mock_config.return_value = {"SLACK_POSTHOG_CODE_SIGNING_SECRET": self.signing_secret}body = json.dumps({"type": "event_callback", "event": {"type": "app_mention"}}).encode()signature, ts = sign_slack_request(body, self.signing_secret)response = self.client.post(@@ -73,7 +73,7 @@ class TestPostHogCodeEventHandler(TestCase):])@patch("products.slack_app.backend.api.route_posthog_code_event_to_relevant_region")- @patch("products.slack_app.backend.api.SlackIntegration.slack_config")+ @patch("products.slack_app.backend.api.SlackIntegration.posthog_code_slack_config")def test_event_callback_dispatch(self,_name,@@ -84,7 +84,7 @@ class TestPostHogCodeEventHandler(TestCase):mock_config,mock_route,):- mock_config.return_value = {"SLACK_APP_SIGNING_SECRET": self.signing_secret}+ mock_config.return_value = {"SLACK_POSTHOG_CODE_SIGNING_SECRET": self.signing_secret}mock_route.return_value = route_resultpayload = {"type": "event_callback",@@ -107,7 +107,7 @@ class TestRoutePostHogCodeEventToRelevantRegion(TestCase):self.team = Team.objects.create(organization=self.organization, name="Test Team")self.posthog_code_integration = Integration.objects.create(team=self.team,- kind="slack",+ kind="slack-posthog-code",integration_id="T12345",sensitive_config={"access_token": "xoxb-posthog-code-test"},)@@ -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="us.posthog.com")+ request = self.factory.post("/slack/event-callback/", HTTP_HOST="eu.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="us.posthog.com")+ request = self.factory.post("/slack/event-callback/", HTTP_HOST="eu.posthog.com")mock_get_repos.return_value = repo_listfrom products.slack_app.backend.api import (@@ -238,6 +238,21 @@ class TestRoutePostHogCodeEventToRelevantRegion(TestCase):else:assert pending_picker is None+ @patch("products.slack_app.backend.api._posthog_code_enabled_for_integration", return_value=False)+ @patch("products.slack_app.backend.api.asyncio.run")+ @patch("products.slack_app.backend.api.sync_connect")+ @override_settings(DEBUG=False)+ def test_local_match_flag_off_skips_workflow(self, mock_sync_connect, mock_asyncio_run, _mock_flag):+ request = self.factory.post("/slack/event-callback/", HTTP_HOST="eu.posthog.com")++ 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, self.event, "T12345")++ assert result == ROUTE_HANDLED_LOCALLY+ mock_sync_connect.assert_not_called()+ mock_asyncio_run.assert_not_called()+@patch("products.slack_app.backend.api.handle_posthog_link_unfurl")@override_settings(DEBUG=False)def test_link_shared_routes_to_unfurl(self, mock_unfurl):@@ -253,18 +268,48 @@ 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.handle_posthog_link_unfurl")+ @override_settings(DEBUG=False)+ def test_link_shared_works_with_only_notifications_integration(self, mock_unfurl):+ # Delete the coding-agent integration and create a notifications-only integration for same workspace+ self.posthog_code_integration.delete()+ Integration.objects.create(+ team=self.team,+ kind="slack",+ integration_id="T12345",+ sensitive_config={"access_token": "xoxb-notifications"},+ )+ 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()+ # Don't assert on which integration row was passed: "first row by id" picking is a known+ # limitation for multi-team workspaces and shouldn't be baked into the test contract.+ passed_integration = mock_unfurl.call_args[0][1]+ assert passed_integration.integration_id == "T12345"+@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+ def test_app_mention_in_primary_with_only_notifications_proxies_to_secondary(+ self, mock_proxy, mock_sync_connect, mock_asyncio_run):- # 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.+ # Regression test: the coding-agent install may live in the other region. A notifications-only+ # row in the primary region must NOT short-circuit the proxy path for app_mention.+ self.posthog_code_integration.delete()+ Integration.objects.create(+ team=self.team,+ kind="slack",+ integration_id="T12345",+ sensitive_config={"access_token": "xoxb-notifications"},+ )mock_proxy.return_value = Truerequest = self.factory.post("/slack/event-callback/", HTTP_HOST="eu.posthog.com")@@ -277,21 +322,28 @@ class TestRoutePostHogCodeEventToRelevantRegion(TestCase):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")+ @patch("products.slack_app.backend.api.asyncio.run")+ @patch("products.slack_app.backend.api.sync_connect")@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": []}+ def test_app_mention_in_secondary_with_only_notifications_noop(self, mock_sync_connect, mock_asyncio_run):+ # In the secondary region with only a notifications install, app_mention should+ # report no_integration (no coding-agent install anywhere reachable from here).+ self.posthog_code_integration.delete()+ Integration.objects.create(+ team=self.team,+ kind="slack",+ integration_id="T12345",+ sensitive_config={"access_token": "xoxb-notifications"},+ )+ 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+ from products.slack_app.backend.api import ROUTE_NO_INTEGRATION, route_posthog_code_event_to_relevant_region- result = route_posthog_code_event_to_relevant_region(request, link_shared_event, "T12345")+ result = route_posthog_code_event_to_relevant_region(request, self.event, "T12345")- assert result == ROUTE_HANDLED_LOCALLY- mock_unfurl.assert_called_once()+ assert result == ROUTE_NO_INTEGRATION+ mock_sync_connect.assert_not_called()+ mock_asyncio_run.assert_not_called()@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")diff --git a/products/slack_app/backend/tests/test_posthog_code_interactivity.py b/products/slack_app/backend/tests/test_posthog_code_interactivity.pyindex 438821a835c7..da119f043061 100644--- a/products/slack_app/backend/tests/test_posthog_code_interactivity.py+++ b/products/slack_app/backend/tests/test_posthog_code_interactivity.py@@ -41,9 +41,9 @@ class TestPostHogCodeInteractivityHandler(TestCase):response = self.client.get("/slack/interactivity-callback/")assert response.status_code == 405- @patch("products.slack_app.backend.api.SlackIntegration.slack_config")+ @patch("products.slack_app.backend.api.SlackIntegration.posthog_code_slack_config")def test_invalid_signature_returns_403(self, mock_config):- mock_config.return_value = {"SLACK_APP_SIGNING_SECRET": "different-secret"}+ mock_config.return_value = {"SLACK_POSTHOG_CODE_SIGNING_SECRET": "different-secret"}response = self._post_interactivity({"type": "block_suggestion"})assert response.status_code == 403@@ -60,7 +60,7 @@ class TestRepoPickerOptions(TestCase):OrganizationMembership.objects.create(user=self.user, organization=self.organization)self.posthog_code_integration = Integration.objects.create(team=self.team,- kind="slack",+ kind="slack-posthog-code",integration_id="T12345",sensitive_config={"access_token": "xoxb-posthog-code-test"},)@@ -96,9 +96,9 @@ class TestRepoPickerOptions(TestCase):)@patch("products.slack_app.backend.api._get_full_repo_names")- @patch("products.slack_app.backend.api.SlackIntegration.slack_config")+ @patch("products.slack_app.backend.api.SlackIntegration.posthog_code_slack_config")def test_options_returns_filtered_repos(self, mock_config, mock_get_repos):- mock_config.return_value = {"SLACK_APP_SIGNING_SECRET": self.signing_secret}+ mock_config.return_value = {"SLACK_POSTHOG_CODE_SIGNING_SECRET": self.signing_secret}mock_get_repos.return_value = ["posthog/posthog", "posthog/posthog-js", "posthog/hogvm"]payload = {@@ -115,9 +115,9 @@ class TestRepoPickerOptions(TestCase):assert options[0]["value"] == "posthog/posthog-js"@patch("products.slack_app.backend.api._get_full_repo_names")- @patch("products.slack_app.backend.api.SlackIntegration.slack_config")+ @patch("products.slack_app.backend.api.SlackIntegration.posthog_code_slack_config")def test_options_empty_query_returns_all(self, mock_config, mock_get_repos):- mock_config.return_value = {"SLACK_APP_SIGNING_SECRET": self.signing_secret}+ mock_config.return_value = {"SLACK_POSTHOG_CODE_SIGNING_SECRET": self.signing_secret}mock_get_repos.return_value = ["posthog/posthog", "posthog/posthog-js"]payload = {@@ -131,9 +131,9 @@ class TestRepoPickerOptions(TestCase):assert response.status_code == 200assert len(response.json()["options"]) == 2- @patch("products.slack_app.backend.api.SlackIntegration.slack_config")+ @patch("products.slack_app.backend.api.SlackIntegration.posthog_code_slack_config")def test_options_wrong_user_returns_empty(self, mock_config):- mock_config.return_value = {"SLACK_APP_SIGNING_SECRET": self.signing_secret}+ mock_config.return_value = {"SLACK_POSTHOG_CODE_SIGNING_SECRET": self.signing_secret}payload = {"type": "block_suggestion",@@ -146,9 +146,9 @@ class TestRepoPickerOptions(TestCase):assert response.status_code == 200assert response.json()["options"] == []- @patch("products.slack_app.backend.api.SlackIntegration.slack_config")+ @patch("products.slack_app.backend.api.SlackIntegration.posthog_code_slack_config")def test_options_expired_token_returns_empty(self, mock_config):- mock_config.return_value = {"SLACK_APP_SIGNING_SECRET": self.signing_secret}+ mock_config.return_value = {"SLACK_POSTHOG_CODE_SIGNING_SECRET": self.signing_secret}cache.delete(f"posthog_code_repo_picker_ctx:{self.context_token}")payload = {@@ -165,11 +165,11 @@ class TestRepoPickerOptions(TestCase):@patch("posthog.models.integration.WebClient")@patch("products.slack_app.backend.api.asyncio.run")@patch("products.slack_app.backend.api.sync_connect")- @patch("products.slack_app.backend.api.SlackIntegration.slack_config")+ @patch("products.slack_app.backend.api.SlackIntegration.posthog_code_slack_config")def test_submit_signals_temporal_workflow(self, mock_config, mock_sync_connect, mock_asyncio_run, mock_webclient_class):- mock_config.return_value = {"SLACK_APP_SIGNING_SECRET": self.signing_secret}+ mock_config.return_value = {"SLACK_POSTHOG_CODE_SIGNING_SECRET": self.signing_secret}mock_webclient_class.return_value = MagicMock()self.context_payload["workflow_id"] = "posthog-code-mention-T12345:C001:1234.5678"cache.set(f"posthog_code_repo_picker_ctx:{self.context_token}", self.context_payload, timeout=900)@@ -199,11 +199,11 @@ class TestRepoPickerOptions(TestCase):@patch("posthog.models.integration.WebClient")@patch("products.slack_app.backend.api.asyncio.run")@patch("products.slack_app.backend.api.sync_connect")- @patch("products.slack_app.backend.api.SlackIntegration.slack_config")+ @patch("products.slack_app.backend.api.SlackIntegration.posthog_code_slack_config")def test_no_repo_button_signals_temporal_workflow(self, mock_config, mock_sync_connect, mock_asyncio_run, mock_webclient_class):- mock_config.return_value = {"SLACK_APP_SIGNING_SECRET": self.signing_secret}+ mock_config.return_value = {"SLACK_POSTHOG_CODE_SIGNING_SECRET": self.signing_secret}mock_webclient_class.return_value = MagicMock()self.context_payload["workflow_id"] = "posthog-code-mention-T12345:C001:1234.5678"cache.set(f"posthog_code_repo_picker_ctx:{self.context_token}", self.context_payload, timeout=900)@@ -233,9 +233,9 @@ class TestRepoPickerOptions(TestCase):assert "without a repository" in update_call["text"].lower()@patch("posthog.models.integration.WebClient")- @patch("products.slack_app.backend.api.SlackIntegration.slack_config")+ @patch("products.slack_app.backend.api.SlackIntegration.posthog_code_slack_config")def test_submit_without_workflow_id_posts_expired(self, mock_config, mock_webclient_class):- mock_config.return_value = {"SLACK_APP_SIGNING_SECRET": self.signing_secret}+ mock_config.return_value = {"SLACK_POSTHOG_CODE_SIGNING_SECRET": self.signing_secret}mock_client = MagicMock()mock_webclient_class.return_value = mock_clientself.context_payload.pop("workflow_id", None)@@ -263,7 +263,7 @@ class TestRepoPickerOptions(TestCase):@patch("posthog.models.integration.WebClient")@patch("products.slack_app.backend.api.asyncio.run")@patch("products.slack_app.backend.api.sync_connect")- @patch("products.slack_app.backend.api.SlackIntegration.slack_config")+ @patch("products.slack_app.backend.api.SlackIntegration.posthog_code_slack_config")def test_submit_signal_failure_posts_expired(self,mock_config,@@ -271,7 +271,7 @@ class TestRepoPickerOptions(TestCase):mock_asyncio_run,mock_webclient_class,):- mock_config.return_value = {"SLACK_APP_SIGNING_SECRET": self.signing_secret}+ mock_config.return_value = {"SLACK_POSTHOG_CODE_SIGNING_SECRET": self.signing_secret}mock_client = MagicMock()mock_webclient_class.return_value = mock_clientself.context_payload["workflow_id"] = "posthog-code-mention-T12345:C001:1234.5678"@@ -300,9 +300,9 @@ class TestRepoPickerOptions(TestCase):@patch("products.slack_app.backend.api.asyncio.run")@patch("products.slack_app.backend.api.sync_connect")- @patch("products.slack_app.backend.api.SlackIntegration.slack_config")+ @patch("products.slack_app.backend.api.SlackIntegration.posthog_code_slack_config")def test_terminate_action_starts_temporal_workflow(self, mock_config, mock_sync_connect, mock_asyncio_run):- mock_config.return_value = {"SLACK_APP_SIGNING_SECRET": self.signing_secret}+ mock_config.return_value = {"SLACK_POSTHOG_CODE_SIGNING_SECRET": self.signing_secret}payload = {"type": "block_actions",diff --git a/products/slack_app/backend/tests/test_resolve_slack_user.py b/products/slack_app/backend/tests/test_resolve_slack_user.pyindex 5e6ffaeb69fd..295fe1afe577 100644--- a/products/slack_app/backend/tests/test_resolve_slack_user.py+++ b/products/slack_app/backend/tests/test_resolve_slack_user.py@@ -23,7 +23,7 @@ class TestResolveSlackUser:self.integration = Integration.objects.create(team=self.team,- kind="slack",+ kind="slack-posthog-code",integration_id="T12345",sensitive_config={"access_token": "xoxb-test"},)diff --git a/products/slack_app/backend/tests/test_terminate.py b/products/slack_app/backend/tests/test_terminate.pyindex 80075894c5fa..a69ddcb0df9a 100644--- a/products/slack_app/backend/tests/test_terminate.py+++ b/products/slack_app/backend/tests/test_terminate.py@@ -27,7 +27,9 @@ class TestProcessPostHogCodeTaskTermination(TestCase):self.org = Organization.objects.create(name="TestOrg")self.team = Team.objects.create(organization=self.org, name="TestTeam")self.user = User.objects.create(email="[email protected]")- self.integration = Integration.objects.create(team=self.team, kind="slack", integration_id="T_SLACK", config={})+ self.integration = Integration.objects.create(+ team=self.team, kind="slack-posthog-code", integration_id="T_SLACK", config={}+ )self.task = self.Task.objects.create(team=self.team,title="Test task",diff --git a/products/tasks/backend/temporal/process_task/tests/test_forward_pending_message.py b/products/tasks/backend/temporal/process_task/tests/test_forward_pending_message.pyindex 4db77a8a004a..4c170e93ad9c 100644--- a/products/tasks/backend/temporal/process_task/tests/test_forward_pending_message.py+++ b/products/tasks/backend/temporal/process_task/tests/test_forward_pending_message.py@@ -47,7 +47,7 @@ class TestForwardPendingUserMessage(TestCase):)cls.slack_integration = Integration.objects.create(team=cls.team,- kind="slack",+ kind="slack-posthog-code",integration_id="T123",config={},)diff --git a/products/tasks/backend/temporal/slack_relay/tests/test_activities.py b/products/tasks/backend/temporal/slack_relay/tests/test_activities.pyindex 0ade4e2a7552..c2b68952e380 100644--- a/products/tasks/backend/temporal/slack_relay/tests/test_activities.py+++ b/products/tasks/backend/temporal/slack_relay/tests/test_activities.py@@ -50,7 +50,7 @@ class TestRelaySlackMessage(TestCase):)cls.integration = Integration.objects.create(team=cls.team,- kind="slack",+ kind="slack-posthog-code",integration_id="T123",config={},)diff --git a/products/tasks/backend/tests/test_api.py b/products/tasks/backend/tests/test_api.pyindex b74343f19f99..67007da65743 100644--- a/products/tasks/backend/tests/test_api.py+++ b/products/tasks/backend/tests/test_api.py@@ -3113,7 +3113,9 @@ class TestTaskRunAPI(BaseTaskAPITest):task = self.create_task()run = TaskRun.objects.create(task=task, team=self.team, status=TaskRun.Status.IN_PROGRESS)- integration = Integration.objects.create(team=self.team, kind="slack", integration_id="T_SLACK", config={})+ integration = Integration.objects.create(+ team=self.team, kind="slack-posthog-code", integration_id="T_SLACK", config={}+ )SlackThreadTaskMapping.objects.create(team=self.team,@@ -3162,7 +3164,9 @@ class TestTaskRunAPI(BaseTaskAPITest):task = self.create_task()run = TaskRun.objects.create(task=task, team=self.team, status=TaskRun.Status.IN_PROGRESS)- integration = Integration.objects.create(team=self.team, kind="slack", integration_id="T_SLACK", config={})+ integration = Integration.objects.create(+ team=self.team, kind="slack-posthog-code", integration_id="T_SLACK", config={}+ )SlackThreadTaskMapping.objects.create(team=self.team,@@ -3290,7 +3294,9 @@ class TestTaskRunAPI(BaseTaskAPITest):run = TaskRun.objects.create(task=task, team=self.team, status=TaskRun.Status.IN_PROGRESS)mock_execute_relay.return_value = "relay-1"- integration = Integration.objects.create(team=self.team, kind="slack", integration_id="T_SLACK", config={})+ integration = Integration.objects.create(+ team=self.team, kind="slack-posthog-code", integration_id="T_SLACK", config={}+ )SlackThreadTaskMapping.objects.create(team=self.team,integration=integration,@@ -3372,7 +3378,9 @@ class TestTaskRunAPI(BaseTaskAPITest):task = self.create_task()run = TaskRun.objects.create(task=task, team=self.team, status=TaskRun.Status.IN_PROGRESS)- integration = Integration.objects.create(team=self.team, kind="slack", integration_id="T_SLACK", config={})+ integration = Integration.objects.create(+ team=self.team, kind="slack-posthog-code", integration_id="T_SLACK", config={}+ )SlackThreadTaskMapping.objects.create(team=self.team,integration=integration,