: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(flags): show client/server runtime flags in person flags tab (#59073)
Dylan Martin83261951656b
diff --git a/posthog/api/feature_flag.py b/posthog/api/feature_flag.pyindex 18a9ac54cc50..de5396448789 100644--- a/posthog/api/feature_flag.py+++ b/posthog/api/feature_flag.py@@ -3457,6 +3457,7 @@ class FeatureFlagViewSet(token=self.team.api_token,distinct_id=distinct_id,groups=groups,+ evaluation_runtime="all",)# Result from Rust service is always a dictionary with a "flags" key. Parse it to get the flags data.diff --git a/posthog/api/services/flags_service.py b/posthog/api/services/flags_service.pyindex cf5b42fa2078..168d64b7453b 100644--- a/posthog/api/services/flags_service.py+++ b/posthog/api/services/flags_service.py@@ -25,6 +25,7 @@ def get_flags_from_service(flag_keys: list[str] | None = None,internal_request_token: str | None = None,override_flags_definitions: dict[str, dict[str, Any]] | None = None,+ evaluation_runtime: str | None = None,) -> dict[str, Any]:"""Proxy a request to the Rust feature flags service /flags endpoint.@@ -39,6 +40,8 @@ def get_flags_from_service(flag_keys: Optional list of specific flag keys to evaluate (default: None, evaluates all flags)internal_request_token: Optional token to mark request as internal (non-billable) (default: None)override_flags_definitions: Optional dict of flag key -> flag definition to override database flags (default: None)+ evaluation_runtime: Optional override for runtime filtering: "all" | "client" | "server".+ When None, the Rust service auto-detects from request headers (User-Agent, origin, sec-fetch-*).Returns:The full response from the flags service as a dict, typically containing:@@ -80,6 +83,9 @@ def get_flags_from_service(if override_flags_definitions:payload["override_flags_definitions"] = override_flags_definitions+ if evaluation_runtime:+ payload["evaluation_runtime"] = evaluation_runtime+params: dict[str, str] = {"v": "2"}if detailed_analysis:diff --git a/posthog/api/test/test_feature_flag.py b/posthog/api/test/test_feature_flag.pyindex 88c56e3118eb..dffe0dae81e1 100644--- a/posthog/api/test/test_feature_flag.py+++ b/posthog/api/test/test_feature_flag.py@@ -13437,3 +13437,53 @@ class TestFeatureFlagTestEvaluation(APIBaseTest, ClickhouseTestMixin):# Verify the mock was calledmock_reconstruct.assert_called_once()+++class TestFeatureFlagEvaluationReasons(APIBaseTest, ClickhouseTestMixin):+ @patch("posthog.api.feature_flag.get_flags_from_service")+ def test_evaluation_reasons_passes_runtime_all(self, mock_get_flags):+ """The Person → Feature flags tab must bypass Rust's header-based+ runtime detection — otherwise flags whose evaluation_runtime is+ "client" or "server" disappear from the tab."""+ mock_get_flags.return_value = {"flags": {}}++ response = self.client.get(+ f"/api/projects/{self.team.pk}/feature_flags/evaluation_reasons/",+ {"distinct_id": "user-1"},+ )++ self.assertEqual(response.status_code, status.HTTP_200_OK)+ self.assertEqual(mock_get_flags.call_args.kwargs["evaluation_runtime"], "all")++ @parameterized.expand(+ [+ ("all",),+ ("client",),+ ("server",),+ ]+ )+ @patch("posthog.api.feature_flag.get_flags_from_service")+ def test_evaluation_reasons_surfaces_flag_for_runtime(self, runtime, mock_get_flags):+ """Each stored runtime must round-trip through evaluation_reasons with+ its evaluation.reason intact — this is the shape+ relatedFeatureFlagsLogic.ts depends on."""+ flag = FeatureFlag.objects.create(team=self.team, key=f"flag-{runtime}", evaluation_runtime=runtime)+ mock_get_flags.return_value = {+ "flags": {+ flag.key: {+ "enabled": True,+ "variant": None,+ "reason": {"code": "condition_match", "condition_index": 0},+ },+ }+ }++ response = self.client.get(+ f"/api/projects/{self.team.pk}/feature_flags/evaluation_reasons/",+ {"distinct_id": "user-1"},+ )++ self.assertEqual(response.status_code, status.HTTP_200_OK)+ data = response.json()+ self.assertIn(flag.key, data)+ self.assertEqual(data[flag.key]["evaluation"]["reason"], "condition_match")