: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(experiments): skip paused experiments in scheduled recalculation (#111336)
Rodrigo Iloro1148900d0e0b
diff --git a/products/experiments/backend/temporal/scheduled_recalculation_logic.py b/products/experiments/backend/temporal/scheduled_recalculation_logic.pyindex 3a38d45ee732..6e6593b94522 100644--- a/products/experiments/backend/temporal/scheduled_recalculation_logic.py+++ b/products/experiments/backend/temporal/scheduled_recalculation_logic.py@@ -79,6 +79,8 @@ def find_scheduled_recalculation_candidates() -> ScheduledRecalculationDiscoveryDeliberately applies no metrics filter: an experiment with no metrics gets a run, and therecalculation workflow completes it immediately.++ An exposure-frozen experiment stays eligible, because its metric events keep arriving."""# Deferred: importing this module runs posthog/temporal/experiments/__init__.py, which pulls# activities.py, which imports back into products.experiments.backend.facade.timeseries.@@ -94,6 +96,9 @@ def find_scheduled_recalculation_candidates() -> ScheduledRecalculationDiscoverytime_filter,deleted=False,status=Experiment.Status.RUNNING,+ # A paused experiment keeps status RUNNING and only deactivates its flag, so the stored+ # status alone would select one that collects no new data.+ feature_flag__active=True,start_date__gte=now - timedelta(days=EXPERIMENT_RECALCULATION_MAX_AGE_DAYS),start_date__lte=now - MIN_EXPERIMENT_AGE,)diff --git a/products/experiments/backend/temporal/test_scheduled_recalculation_logic.py b/products/experiments/backend/temporal/test_scheduled_recalculation_logic.pyindex ceed71978aa5..cdb46ef6d841 100644--- a/products/experiments/backend/temporal/test_scheduled_recalculation_logic.py+++ b/products/experiments/backend/temporal/test_scheduled_recalculation_logic.py@@ -16,7 +16,12 @@ from posthog.models.scoping import team_scopefrom posthog.models.team import Teamfrom products.experiments.backend.hogql_queries import MULTIPLE_VARIANT_KEY-from products.experiments.backend.models.experiment import Experiment, ExperimentHoldout, ExperimentMetricsRecalculation+from products.experiments.backend.models.experiment import (+ EXPOSURE_FROZEN_GROUP_KEY,+ Experiment,+ ExperimentHoldout,+ ExperimentMetricsRecalculation,+)from products.experiments.backend.models.team_experiments_config import TeamExperimentsConfigfrom products.experiments.backend.temporal.scheduled_recalculation_logic import (EXPERIMENT_RECALCULATION_MAX_AGE_DAYS,@@ -124,6 +129,32 @@ class TestScheduledRecalculationLogic(BaseTest):assert experiment.status == expected_statusassert experiment.id not in self._candidate_ids(2)+ @parameterized.expand(+ [+ ("paused", False, False),+ ("active", True, True),+ ]+ )+ def test_a_paused_experiment_is_excluded(self, _name: str, flag_active: bool, expected: bool):+ # Pausing leaves status RUNNING and only deactivates the flag, so this is the one+ # exclusion the stored status cannot express.+ experiment = self._experiment()+ experiment.feature_flag.active = flag_active+ experiment.feature_flag.save()+ assert experiment.status == Experiment.Status.RUNNING+ assert (experiment.id in self._candidate_ids(2)) is expected++ def test_an_exposure_frozen_experiment_is_still_a_candidate(self):+ # Frozen exposure closes enrollment but metric events keep arriving, so the results+ # still move and the experiment stays worth recalculating.+ experiment = self._experiment()+ flag = experiment.feature_flag+ flag.filters = {"groups": [{"properties": [], "rollout_percentage": 100, EXPOSURE_FROZEN_GROUP_KEY: True}]}+ flag.save()+ experiment.refresh_from_db()+ assert experiment.is_exposure_frozen+ assert experiment.id in self._candidate_ids(2)+@parameterized.expand([("too_new", 3, False),