: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 unschedulable metrics in daily discovery (#109299)
Andersfd9a7b8a5495
diff --git a/posthog/temporal/experiments/README.md b/posthog/temporal/experiments/README.mdindex 96a2994e0e80..fa660a9fead5 100644--- a/posthog/temporal/experiments/README.md+++ b/posthog/temporal/experiments/README.md@@ -31,7 +31,7 @@ There are two parallel workflow systems:When a schedule triggers, it starts a workflow that:-1. Discovers which experiment-metric pairs need calculation+1. Discovers which experiment-metric pairs need calculation. It skips the metrics that `is_scheduled_metric` rejects, the same as recalculation discovery: legacy metrics without a `metric_type`, and metrics without a uuid2. Calculates each experiment's metrics in parallel, under one hour-wide concurrency limit3. Stores results in the database4. Assembles one completed metrics recalculation per experiment as soon as that experiment's own metrics finish (see below)diff --git a/posthog/temporal/experiments/activities.py b/posthog/temporal/experiments/activities.pyindex e19c79c8e35f..17a06ee7de90 100644--- a/posthog/temporal/experiments/activities.py+++ b/posthog/temporal/experiments/activities.py@@ -36,6 +36,7 @@ from products.experiments.backend.facade.timeseries import (backfill_experiment_timeseries,build_metric,is_daily_timeseries_metric,+ is_scheduled_metric,resolve_saved_metric_definition,sync_timeseries_recalculation,)@@ -96,6 +97,8 @@ def _get_experiment_regular_metrics_for_hour_sync(hour: int) -> list[ExperimentRexperiment_id=experiment.id,)continue+ if not is_scheduled_metric(metric):+ continuefingerprint = compute_metric_fingerprint(metric,@@ -397,6 +400,8 @@ def _get_experiment_saved_metrics_for_hour_sync(hour: int) -> list[ExperimentSavsaved_metric_id=saved_metric.id,)continue+ if not is_scheduled_metric(saved_metric.query):+ continue# Fingerprint the effective definition (with the link overrides), the same dict the calc# activity computes and every reader (timeseries sync, chart read) resolves. Hashing the rawdiff --git a/posthog/temporal/experiments/test_recalculation_time_filter.py b/posthog/temporal/experiments/test_recalculation_time_filter.pyindex f102e62fc266..bfac2b9aa416 100644--- a/posthog/temporal/experiments/test_recalculation_time_filter.py+++ b/posthog/temporal/experiments/test_recalculation_time_filter.py@@ -105,6 +105,36 @@ class TestRecalculationTimeFilter:assert experiment.id in {r.experiment_id for r in _get_saved_metrics_sync(hour=20)}assert experiment.id not in {r.experiment_id for r in _get_saved_metrics_sync(hour=2)}+ def test_discovery_skips_metrics_that_cannot_be_scheduled(self):+ org = Organization.objects.create(name="Test Org Legacy")+ team = Team.objects.create(organization=org, name="Team Legacy Metrics")+ user = User.objects.create(email="[email protected]")++ def mean_metric(uuid: str) -> dict:+ return {"metric_type": "mean", "uuid": uuid, "source": {"kind": "EventsNode", "event": "test"}}++ def legacy_metric(uuid: str) -> dict:+ return {+ "kind": "ExperimentTrendsQuery",+ "uuid": uuid,+ "count_query": {"kind": "TrendsQuery", "series": [{"kind": "EventsNode", "event": "test"}]},+ }++ experiment = _create_running_experiment(+ team, user, "legacy-metrics", metrics=[mean_metric("inline-mean"), legacy_metric("inline-legacy")]+ )+ for query in (mean_metric("saved-mean"), legacy_metric("saved-legacy")):+ saved_metric = ExperimentSavedMetric.objects.create(+ team=team, name=query["uuid"], query=query, created_by=user+ )+ ExperimentToSavedMetric.objects.create(experiment=experiment, saved_metric=saved_metric)++ inline = [r.metric_uuid for r in _get_metrics_sync(hour=2) if r.experiment_id == experiment.id]+ saved = [r.metric_uuid for r in _get_saved_metrics_sync(hour=2) if r.experiment_id == experiment.id]++ assert inline == ["inline-mean"]+ assert saved == ["saved-mean"]+def test_team_with_no_config_row_defaults_to_hour_2(self):org = Organization.objects.create(name="Test Org 2")team = Team.objects.create(organization=org, name="Team No Config")diff --git a/products/experiments/backend/facade/timeseries.py b/products/experiments/backend/facade/timeseries.pyindex f79e3470ad5d..0f97f566d4f0 100644--- a/products/experiments/backend/facade/timeseries.py+++ b/products/experiments/backend/facade/timeseries.py@@ -3,6 +3,7 @@from products.experiments.backend.metric_resolution import (build_metric,is_daily_timeseries_metric,+ is_scheduled_metric,resolve_saved_metric_definition,)from products.experiments.backend.timeseries_backfill import backfill_experiment_timeseries@@ -12,6 +13,7 @@ __all__ = ["backfill_experiment_timeseries","build_metric","is_daily_timeseries_metric",+ "is_scheduled_metric","resolve_saved_metric_definition","sync_timeseries_recalculation",]