: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
feat(experiments): report a deleted flag on a running experiment (#115624)
Marcel Poelkerbf852dfa3768
diff --git a/products/experiments/backend/health/checks/flag_state.py b/products/experiments/backend/health/checks/flag_state.pyindex 230fe7effc73..f1cd794de3ac 100644--- a/products/experiments/backend/health/checks/flag_state.py+++ b/products/experiments/backend/health/checks/flag_state.py@@ -21,14 +21,33 @@ RUNNING_BUT_NO_ROLLOUT = "running_but_no_rollout"RUNNING_BUT_SINGLE_VARIANT_SHIPPED = "running_but_single_variant_shipped"ENDED_BUT_MULTIPLE_VARIANTS_ROLLED_OUT = "ended_but_multiple_variants_rolled_out"NOT_STARTED_BUT_MULTIPLE_VARIANTS_ROLLED_OUT = "not_started_but_multiple_variants_rolled_out"+# pinned: the page sends it as `finding_variant` on its events, as the keys above. No banner uses it.+RUNNING_BUT_FLAG_DELETED = "running_but_flag_deleted"_NOT_RUNNING_BUT_EXPOSED_TITLE = "The experiment is not running, but users are exposed to multiple variants"def flag_state(ctx: HealthContext) -> ExperimentHealthFinding | None:flag = ctx.flag- # A deleted flag distributes no traffic, so flag-state findings don't apply.- if flag is None or flag.deleted:+ if flag is None:+ return None++ if flag.deleted:+ # A deleted flag distributes no traffic, so the other flag-state findings don't apply. This branch+ # comes before the paused one because a flag is often disabled before it is deleted. The page's own+ # rule returns nothing here, so this finding has no banner, and the page's events that compare the+ # two report it as a difference.+ if ctx.is_running:+ return _finding(+ code=ExperimentHealthFindingCode.FLAG_OFF_WHILE_RUNNING,+ subcode=RUNNING_BUT_FLAG_DELETED,+ title="The experiment is running, but its feature flag is deleted",+ detail=(+ "The linked feature flag is deleted, so no new users are being exposed. Users exposed "+ "earlier are still included in the results. Open the feature flag and restore it, or end "+ "the experiment with a conclusion."+ ),+ )return Nonezero_rollout = _has_zero_rollout(flag)diff --git a/products/experiments/backend/health/test/test_flag_state.py b/products/experiments/backend/health/test/test_flag_state.pyindex 539ca790f50e..925919d53bb6 100644--- a/products/experiments/backend/health/test/test_flag_state.py+++ b/products/experiments/backend/health/test/test_flag_state.py@@ -9,7 +9,8 @@ from products.experiments.backend.health.checks.flag_state import flag_statefrom products.experiments.backend.health.context import HealthContext, parse_flag_state# The flag documents and cases of the `experimentWarning` test in-# frontend/src/scenes/experiments/experimentLogic.test.ts, so that both sides answer alike.+# frontend/src/scenes/experiments/experimentLogic.test.ts, so that both sides answer alike. A running+# experiment with a deleted flag is the exception: only the server reports it.MULTIVARIANT = {"groups": [{"properties": [], "rollout_percentage": 100}],"multivariate": {@@ -121,6 +122,16 @@ class TestFlagState(TestCase):),("draft_zero_rollout", _context(DRAFT, active=True, filters=ZERO_ROLLOUT), None),("draft_flag_disabled", _context(DRAFT, active=False, filters=MULTIVARIANT), None),+ (+ "running_deleted_flag",+ _context(RUNNING, active=True, filters=MULTIVARIANT, deleted=True),+ (ExperimentHealthFindingCode.FLAG_OFF_WHILE_RUNNING, "running_but_flag_deleted", None),+ ),+ (+ "running_deleted_flag_disabled_first",+ _context(RUNNING, active=False, filters=MULTIVARIANT, deleted=True),+ (ExperimentHealthFindingCode.FLAG_OFF_WHILE_RUNNING, "running_but_flag_deleted", None),+ ),("ended_deleted_flag", _context(ENDED, active=True, filters=MULTIVARIANT, deleted=True), None),("draft_deleted_flag", _context(DRAFT, active=True, filters=MULTIVARIANT, deleted=True), None),("running_groups_are_null", _context(RUNNING, active=True, filters={**ZERO_ROLLOUT, "groups": None}), None),