: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(signals): keep eu users out of the recommended inbox sort experiment (#117927)
Andrew Maguireeb3dc5d6b9ca
diff --git a/products/signals/backend/ranking/inbox_sort.py b/products/signals/backend/ranking/inbox_sort.pyindex bb6a3f702a31..19720c494c61 100644--- a/products/signals/backend/ranking/inbox_sort.py+++ b/products/signals/backend/ranking/inbox_sort.py@@ -2,7 +2,7 @@A multivariate flag keyed by the requesting user picks the ranker. The variants `open`, `action` and `fixed` orderby the served head of the same name first. `control`, an unknown variant, or a flag that is off or fails to evaluate-gives the priority order.+gives the priority order. The EU instance gives the priority order without evaluating the flag.The merge key lets a client merge rows from different rankers without the raw score. It is the scoredecile then the priority rank, so it never says more about the score than one decimal place. Each@@ -20,6 +20,7 @@ import posthoganalyticsfrom posthog.models.team import Teamfrom posthog.models.user import User+from posthog.utils import get_instance_regionfrom products.signals.backend.models import AutonomyPriority@@ -45,6 +46,10 @@ _PRIORITY_SLOTS = len(AutonomyPriority.values) + 1def resolve_recommended_ranker(team: Team, user: User) -> InboxRanker:if not user.distinct_id:return "priority"+ # EU reports have no ranking scores, so a head variant there sorts the same as `control`. Evaluating the+ # flag would still log an exposure, and those no-difference exposures would dilute the US experiment.+ if get_instance_region() == "EU":+ return "priority"try:variant = posthoganalytics.get_feature_flag(RECOMMENDED_INBOX_SORT_FLAG,diff --git a/products/signals/backend/test/test_signal_report_api.py b/products/signals/backend/test/test_signal_report_api.pyindex 70a0c1418649..5584c6e1a4a8 100644--- a/products/signals/backend/test/test_signal_report_api.py+++ b/products/signals/backend/test/test_signal_report_api.py@@ -1375,14 +1375,17 @@ class TestSignalReportListAPI(APIBaseTest):@parameterized.expand([- ("flag_off", {"return_value": None}),- ("control", {"return_value": "control"}),- ("unknown_variant", {"return_value": "test"}),- ("non_recommended_head", {"return_value": "discuss"}),- ("flag_error", {"side_effect": RuntimeError("flags down")}),+ ("flag_off", {"return_value": None}, None),+ ("control", {"return_value": "control"}, None),+ ("unknown_variant", {"return_value": "test"}, None),+ ("non_recommended_head", {"return_value": "discuss"}, None),+ ("flag_error", {"side_effect": RuntimeError("flags down")}, None),+ ("eu_instance", {"return_value": "fixed"}, "EU"),])- def test_recommended_sort_uses_priority_order_unless_the_flag_serves_a_head(self, _name, flag_result):+ def test_recommended_sort_uses_priority_order_unless_the_flag_serves_a_head(+ self, _name, flag_result, cloud_deployment+ ):p2 = self._create_report(title="P2")p0 = self._create_report(title="P0")no_priority = self._create_report(title="No priority")@@ -1390,9 +1393,16 @@ class TestSignalReportListAPI(APIBaseTest):self._priority_artefact(p0, priority="P0")self._ranking_score_artefact(p2, scores={"fixed": 0.9})- with patch("products.signals.backend.ranking.inbox_sort.posthoganalytics.get_feature_flag", **flag_result):+ with (+ self.settings(CLOUD_DEPLOYMENT=cloud_deployment),+ patch(+ "products.signals.backend.ranking.inbox_sort.posthoganalytics.get_feature_flag", **flag_result+ ) as get_flag,+ ):response = self.client.get(self._list_url(status="ready", sort="recommended"))+ if cloud_deployment == "EU":+ get_flag.assert_not_called()assert response.status_code == status.HTTP_200_OKbody = response.json()assert body["ranker"] == "priority"