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(experiments): preserve holdout when shipping a variant (#94901)

Juraj Majerik9e789948ea9b
diff --git a/products/feature_flags/backend/facade/api.py b/products/feature_flags/backend/facade/api.py
index b8f82ab2a49e..28f3ebbb688a 100644
--- a/products/feature_flags/backend/facade/api.py
+++ b/products/feature_flags/backend/facade/api.py
@@ -201,7 +201,7 @@ def _roll_out_variant(
catch_all["description"] = release_condition_description
groups = [catch_all, *groups]
- return {
+ new_filters = {
"aggregation_group_type_index": current_filters.get("aggregation_group_type_index"),
"payloads": current_filters.get("payloads", {}),
"multivariate": {
@@ -216,6 +216,11 @@ def _roll_out_variant(
},
"groups": groups,
}
+ # A holdout must keep excluding its users after the winner ships — that is its
+ # entire purpose (measuring shipped features against an unexposed baseline).
+ if current_filters.get("holdout"):
+ new_filters["holdout"] = current_filters["holdout"]
+ return new_filters
def ship_variant(
diff --git a/products/feature_flags/backend/test/test_facade.py b/products/feature_flags/backend/test/test_facade.py
index f430843fcb5b..3683d7d1975d 100644
--- a/products/feature_flags/backend/test/test_facade.py
+++ b/products/feature_flags/backend/test/test_facade.py
@@ -353,6 +353,27 @@ class TestRollOutVariant:
assert result["payloads"] == {}
assert result["aggregation_group_type_index"] is None
+ def test_transform_filters_preserves_holdout(self):
+ current_filters = {
+ "groups": [{"properties": [], "rollout_percentage": 100}],
+ "multivariate": {
+ "variants": [
+ {"key": "control", "rollout_percentage": 50},
+ {"key": "test", "rollout_percentage": 50},
+ ]
+ },
+ "holdout": {"id": 42, "exclusion_percentage": 5},
+ }
+
+ assert _roll_out_variant(current_filters, "test")["holdout"] == {"id": 42, "exclusion_percentage": 5}
+ assert _roll_out_variant(current_filters, "test", release_to_everyone=True)["holdout"] == {
+ "id": 42,
+ "exclusion_percentage": 5,
+ }
+
+ del current_filters["holdout"]
+ assert "holdout" not in _roll_out_variant(current_filters, "test")
+
def test_transform_filters_default_does_not_mutate_input(self):
"""Defensive: ensure the function returns a new groups list without mutating caller's filters."""
original_groups = [{"properties": [], "rollout_percentage": 50}]