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.

feat(experiments): add precompute enrollment census workflow (#88455)

Juraj Majerik24427cc3824f
diff --git a/posthog/temporal/schedule.py b/posthog/temporal/schedule.py
index 67c19e51dbcd..4a02e7bccd67 100644
--- a/posthog/temporal/schedule.py
+++ b/posthog/temporal/schedule.py
@@ -96,7 +96,10 @@ from products.error_tracking.backend.facade.temporal import (
create_error_tracking_symbol_set_cleanup_schedule,
create_error_tracking_weekly_digest_schedule,
)
-from products.experiments.backend.temporal.schedule import create_experiment_precompute_canary_schedule
+from products.experiments.backend.temporal.schedule import (
+ create_experiment_precompute_canary_schedule,
+ create_experiment_precompute_enrollment_census_schedule,
+)
from products.exports.backend.temporal.subscriptions.types import ScheduleAllSubscriptionsWorkflowInputs
from products.logs.backend.facade.temporal import create_logs_volume_tick_schedule
from products.managed_warehouse.backend.facade.temporal import DucklakeCompactionInput
@@ -877,6 +880,7 @@ schedules = [
create_experiment_regular_metrics_schedules,
create_experiment_saved_metrics_schedules,
create_experiment_precompute_canary_schedule,
+ create_experiment_precompute_enrollment_census_schedule,
cleanup_cohort_calculation_schedules,
create_ingestion_acceptance_test_schedule,
create_warehouse_sources_queue_partition_management_schedule,
diff --git a/products/experiments/backend/temporal/__init__.py b/products/experiments/backend/temporal/__init__.py
index 83160f053f88..36023b69df0e 100644
--- a/products/experiments/backend/temporal/__init__.py
+++ b/products/experiments/backend/temporal/__init__.py
@@ -4,6 +4,10 @@ from products.experiments.backend.temporal.canary_activities import (
sample_experiment_canary_targets,
)
from products.experiments.backend.temporal.canary_workflow import ExperimentPrecomputeCanaryWorkflow
+from products.experiments.backend.temporal.enrollment_census_activities import run_experiment_enrollment_census
+from products.experiments.backend.temporal.enrollment_census_workflow import (
+ ExperimentPrecomputeEnrollmentCensusWorkflow,
+)
from products.experiments.backend.temporal.recalculation_activities import (
calculate_experiment_metric_for_recalculation,
discover_experiment_metrics,
@@ -23,12 +27,14 @@ EXPERIMENT_CANARY_ACTIVITIES = [
WORKFLOWS = [
ExperimentMetricsRecalculationWorkflow,
*EXPERIMENT_CANARY_WORKFLOWS,
+ ExperimentPrecomputeEnrollmentCensusWorkflow,
]
ACTIVITIES = [
discover_experiment_metrics,
calculate_experiment_metric_for_recalculation,
update_recalculation_progress,
*EXPERIMENT_CANARY_ACTIVITIES,
+ run_experiment_enrollment_census,
]
__all__ = [
@@ -38,9 +44,11 @@ __all__ = [
"WORKFLOWS",
"ExperimentMetricsRecalculationWorkflow",
"ExperimentPrecomputeCanaryWorkflow",
+ "ExperimentPrecomputeEnrollmentCensusWorkflow",
"calculate_experiment_metric_for_recalculation",
"discover_experiment_metrics",
"report_experiment_canary_results",
+ "run_experiment_enrollment_census",
"run_experiment_metric_canary",
"sample_experiment_canary_targets",
"update_recalculation_progress",
diff --git a/products/experiments/backend/temporal/enrollment_census_activities.py b/products/experiments/backend/temporal/enrollment_census_activities.py
new file mode 100644
index 000000000000..d8572d6b662f
--- /dev/null
+++ b/products/experiments/backend/temporal/enrollment_census_activities.py
@@ -0,0 +1,21 @@
+import temporalio.activity
+
+from posthog.sync import database_sync_to_async
+
+from products.experiments.backend.temporal.enrollment_census_logic import run_enrollment_census_sync
+from products.experiments.backend.temporal.models import ExperimentPrecomputeEnrollmentCensusInputs
+
+
+async def run_experiment_enrollment_census(inputs: ExperimentPrecomputeEnrollmentCensusInputs) -> dict:
+ """Run the census and log the report; returns counts for the workflow result."""
+
+ def _run() -> dict:
+ report = run_enrollment_census_sync(window_days=inputs.window_days)
+ return {
+ "evaluated_teams": report.evaluated_teams,
+ "candidates": len(report.candidates),
+ "excluded": len(report.excluded),
+ }
+
+ return await database_sync_to_async(_run)()
diff --git a/products/experiments/backend/temporal/enrollment_census_logic.py b/products/experiments/backend/temporal/enrollment_census_logic.py
new file mode 100644
index 000000000000..ef91fbb727ef
--- /dev/null
+++ b/products/experiments/backend/temporal/enrollment_census_logic.py
@@ -0,0 +1,248 @@
+"""Census of teams whose experiment queries would benefit from precomputation.
+
+Finds teams whose experiment metric reads run as direct event scans only because the
+team is not enrolled in precomputation (`experiment_precompute_skip_reason = 'team_disabled'`),
+measures their pain over a trailing window, and reports the ones crossing the enrollment
+criteria. Report-only: this module never writes to `TeamExperimentsConfig`.
+"""
+
+from django.db.models import Count
+
+import structlog
+
+from posthog.clickhouse.client import sync_execute
+from posthog.dataclasses import frozen
+
+from products.experiments.backend.models.experiment import Experiment
+
+logger = structlog.get_logger(__name__)
+
+CENSUS_WINDOW_DAYS = 14
+
+# A team must have this many direct-scan reads in the window for precomputation to have
+# enough repeat traffic to amortize its builds. Nightly recalculation counts, deliberately:
+# recalc is where precompute saves the most.
+MIN_DIRECT_READS = 50
+
+# Pain thresholds. Any one qualifies a team (given MIN_DIRECT_READS).
+SLOW_READ_MS = 15_000
+SLOW_READ_FRACTION = 0.10
+TOTAL_READ_BYTES_THRESHOLD = 5 * 10**12 # 5 TB rescanned per window
+HARD_FAILURE_CODES = (159, 241) # TIMEOUT_EXCEEDED, MEMORY_LIMIT_EXCEEDED
+HARD_FAILURES_THRESHOLD = 5
+
+# A single read this large means the team's full-window scans approach the per-query byte
+# cap, so precompute build INSERTs over the same events likely would too. Enrolling such a
+# team burns ClickHouse on failing builds (error 307) with no speedup; keep them out until
+# build window chunking can handle them.
+BUILD_CAP_EXCLUSION_BYTES = int(2.5 * 10**12)
+
+EXCLUSION_BUILD_BYTE_CAP = "build_byte_cap"
+
+# Reads query_log_archive, not system.query_log: the archive outlives query_log's short
+# retention and stores log_comment as a typed JSON column. The lc_product prefilter keeps
+# the scan small enough for one query over the full window; the raw system.query_log
+# needed day-chunking to stay under the per-query byte cap.
+# Slow-read and duration stats only count successful reads — failed ones have truncated durations.
+CENSUS_SQL = """
+ SELECT
+ team_id,
+ count() AS direct_reads,
+ countIf(query_duration_ms > %(slow_read_ms)s AND exception_code = 0) AS slow_reads,
+ max(read_bytes) AS max_read_bytes,
+ sum(read_bytes) AS total_read_bytes,
+ countIf(exception_code IN %(hard_failure_codes)s) AS hard_failures,
+ uniqExact(lc_experiment_id) AS experiment_count
+ FROM query_log_archive
+ WHERE event_date >= toDate(now() - INTERVAL %(window_days)s DAY)
+ AND event_time > now() - INTERVAL %(window_days)s DAY
+ AND lc_product = 'experiments'
+ AND toString(log_comment.experiment_query_surface) = 'metric'
+ AND ifNull(toString(log_comment.experiment_exposures_path), '') = 'direct_scan'
+ AND ifNull(toString(log_comment.experiment_precompute_skip_reason), '') = 'team_disabled'
+ AND is_initial_query
+ AND toInt8(type) > 1
+ GROUP BY team_id
+ HAVING direct_reads >= %(min_direct_reads)s
+ SETTINGS skip_unavailable_shards=1
+"""
+
+
+@frozen
+class TeamDirectScanStats:
+ """Aggregated direct-scan pain for one team over the census window."""
+
+ team_id: int
+ direct_reads: int
+ slow_reads: int
+ max_read_bytes: int
+ total_read_bytes: int
+ hard_failures: int
+ experiment_count: int
+
+
+@frozen
+class EnrollmentCandidate:
+ stats: TeamDirectScanStats
+ reasons: tuple[str, ...]
+ # Projected nightly build load: recalculation, not human views, is what turns
+ # enrollment into daily spend.
+ running_experiments: int
+ running_metrics: int
+
+
+@frozen
+class ExcludedTeam:
+ stats: TeamDirectScanStats
+ reason: str
+
+
+@frozen
+class TeamRunningLoad:
+ running_experiments: int
+ running_metrics: int
+
+
+@frozen
+class EnrollmentCensusReport:
+ window_days: int
+ evaluated_teams: int
+ candidates: tuple[EnrollmentCandidate, ...]
+ excluded: tuple[ExcludedTeam, ...]
+
+
+def qualifying_reasons(stats: TeamDirectScanStats) -> tuple[str, ...]:
+ """Which enrollment criteria the team crosses; empty means it does not qualify."""
+ if stats.direct_reads < MIN_DIRECT_READS:
+ return ()
+ reasons = []
+ if stats.slow_reads / stats.direct_reads > SLOW_READ_FRACTION:
+ reasons.append("slow_reads")
+ if stats.total_read_bytes > TOTAL_READ_BYTES_THRESHOLD:
+ reasons.append("scan_volume")
+ if stats.hard_failures >= HARD_FAILURES_THRESHOLD:
+ reasons.append("hard_failures")
+ return tuple(reasons)
+
+
+def exclusion_reason(stats: TeamDirectScanStats) -> str | None:
+ if stats.max_read_bytes > BUILD_CAP_EXCLUSION_BYTES:
+ return EXCLUSION_BUILD_BYTE_CAP
+ return None
+
+
+def fetch_direct_scan_stats(window_days: int) -> list[TeamDirectScanStats]:
+ rows = sync_execute(
+ CENSUS_SQL,
+ {
+ "window_days": window_days,
+ "slow_read_ms": SLOW_READ_MS,
+ "hard_failure_codes": HARD_FAILURE_CODES,
+ "min_direct_reads": MIN_DIRECT_READS,
+ },
+ )
+ return [
+ TeamDirectScanStats(
+ team_id=row[0],
+ direct_reads=row[1],
+ slow_reads=row[2],
+ max_read_bytes=row[3],
+ total_read_bytes=row[4],
+ hard_failures=row[5],
+ experiment_count=row[6],
+ )
+ for row in rows
+ ]
+
+
+def running_experiment_load(team_ids: list[int]) -> dict[int, TeamRunningLoad]:
+ """Per team: running experiment count and metric count across them.
+
+ Counts inline, secondary, and saved metrics — the same set nightly recalculation
+ resolves — so the projected build load matches what enrollment would actually run.
+ """
+ load: dict[int, TeamRunningLoad] = {}
+ experiments = (
+ Experiment.objects.filter(team_id__in=team_ids, start_date__isnull=False, end_date__isnull=True)
+ .exclude(deleted=True)
+ .annotate(saved_metric_count=Count("experimenttosavedmetric"))
+ .values_list("team_id", "metrics", "metrics_secondary", "saved_metric_count")
+ )
+ for team_id, metrics, metrics_secondary, saved_metric_count in experiments:
+ current = load.get(team_id, TeamRunningLoad(running_experiments=0, running_metrics=0))
+ load[team_id] = TeamRunningLoad(
+ running_experiments=current.running_experiments + 1,
+ running_metrics=current.running_metrics
+ + len(metrics or [])
+ + len(metrics_secondary or [])
+ + saved_metric_count,
+ )
+ return load
+
+
+def build_census_report(stats: list[TeamDirectScanStats], window_days: int) -> EnrollmentCensusReport:
+ qualified: list[tuple[TeamDirectScanStats, tuple[str, ...]]] = []
+ excluded: list[ExcludedTeam] = []
+ for team_stats in stats:
+ reasons = qualifying_reasons(team_stats)
+ if not reasons:
+ continue
+ exclusion = exclusion_reason(team_stats)
+ if exclusion is not None:
+ excluded.append(ExcludedTeam(stats=team_stats, reason=exclusion))
+ continue
+ qualified.append((team_stats, reasons))
+
+ load = running_experiment_load([team_stats.team_id for team_stats, _ in qualified])
+ no_load = TeamRunningLoad(running_experiments=0, running_metrics=0)
+ candidates = tuple(
+ EnrollmentCandidate(
+ stats=team_stats,
+ reasons=reasons,
+ running_experiments=load.get(team_stats.team_id, no_load).running_experiments,
+ running_metrics=load.get(team_stats.team_id, no_load).running_metrics,
+ )
+ for team_stats, reasons in sorted(qualified, key=lambda pair: -pair[0].total_read_bytes)
+ )
+ return EnrollmentCensusReport(
+ window_days=window_days,
+ evaluated_teams=len(stats),
+ candidates=candidates,
+ excluded=tuple(excluded),
+ )
+
+
+def run_enrollment_census_sync(window_days: int = CENSUS_WINDOW_DAYS) -> EnrollmentCensusReport:
+ stats = fetch_direct_scan_stats(window_days)
+ report = build_census_report(stats, window_days)
+
+ for candidate in report.candidates:
+ logger.info(
+ "experiment_precompute_enrollment_candidate",
+ team_id=candidate.stats.team_id,
+ reasons=list(candidate.reasons),
+ direct_reads=candidate.stats.direct_reads,
+ slow_reads=candidate.stats.slow_reads,
+ total_read_bytes=candidate.stats.total_read_bytes,
+ max_read_bytes=candidate.stats.max_read_bytes,
+ hard_failures=candidate.stats.hard_failures,
+ experiment_count=candidate.stats.experiment_count,
+ running_experiments=candidate.running_experiments,
+ running_metrics=candidate.running_metrics,
+ )
+ for excluded_team in report.excluded:
+ logger.info(
+ "experiment_precompute_enrollment_excluded",
+ team_id=excluded_team.stats.team_id,
+ reason=excluded_team.reason,
+ max_read_bytes=excluded_team.stats.max_read_bytes,
+ total_read_bytes=excluded_team.stats.total_read_bytes,
+ )
+ logger.info(
+ "experiment_precompute_enrollment_census_finished",
+ window_days=report.window_days,
+ evaluated_teams=report.evaluated_teams,
+ candidates=len(report.candidates),
+ excluded=len(report.excluded),
+ )
+ return report
diff --git a/products/experiments/backend/temporal/enrollment_census_workflow.py b/products/experiments/backend/temporal/enrollment_census_workflow.py
new file mode 100644
index 000000000000..1f013533fa02
--- /dev/null
+++ b/products/experiments/backend/temporal/enrollment_census_workflow.py
@@ -0,0 +1,39 @@
+import json
+from datetime import timedelta
+
+import temporalio.workflow
+from temporalio.common import RetryPolicy
+
+from posthog.temporal.common.base import PostHogWorkflow
+
+with temporalio.workflow.unsafe.imports_passed_through():
+ from products.experiments.backend.temporal.enrollment_census_activities import run_experiment_enrollment_census
+ from products.experiments.backend.temporal.models import (
+ ENROLLMENT_CENSUS_WORKFLOW_NAME,
+ ExperimentPrecomputeEnrollmentCensusInputs,
+ )
+
+
[email protected](name=ENROLLMENT_CENSUS_WORKFLOW_NAME)
+class ExperimentPrecomputeEnrollmentCensusWorkflow(PostHogWorkflow):
+ """Report which teams would qualify for experiment precomputation enrollment.
+
+ Report-only: candidates and exclusions are logged (one line per team, queryable in Loki);
+ nothing is written. See ``enrollment_census_logic`` for the criteria.
+ """
+
+ @staticmethod
+ def parse_inputs(inputs: list[str]) -> ExperimentPrecomputeEnrollmentCensusInputs:
+ loaded = json.loads(inputs[0]) if inputs else {}
+ return ExperimentPrecomputeEnrollmentCensusInputs(**loaded)
+
+ @temporalio.workflow.run
+ async def run(self, inputs: ExperimentPrecomputeEnrollmentCensusInputs) -> dict:
+ result = await temporalio.workflow.execute_activity(
+ run_experiment_enrollment_census,
+ inputs,
+ start_to_close_timeout=timedelta(minutes=10),
+ retry_policy=RetryPolicy(maximum_attempts=3),
+ )
+ temporalio.workflow.logger.info(f"experiment precompute enrollment census finished: {result}")
+ return result
diff --git a/products/experiments/backend/temporal/models.py b/products/experiments/backend/temporal/models.py
index c2ac8dedcfa4..4cef702dd478 100644
--- a/products/experiments/backend/temporal/models.py
+++ b/products/experiments/backend/temporal/models.py
@@ -190,3 +190,14 @@ class RecalculationProgressUpdate:
# 'experiment results refresh completed' analytics event with real counts.
succeeded_metrics: int | None = None
failed_metrics: int | None = None
+
+
+ENROLLMENT_CENSUS_WORKFLOW_NAME = "experiment-precompute-enrollment-census"
+
+
[email protected](frozen=True)
+class ExperimentPrecomputeEnrollmentCensusInputs:
+ """Input to the enrollment census workflow. Report-only: the census logs which teams
+ would qualify for precomputation enrollment; it never enrolls anyone."""
+
+ window_days: int = 14
diff --git a/products/experiments/backend/temporal/schedule.py b/products/experiments/backend/temporal/schedule.py
index 96ce939b4c4b..81aff65a0c46 100644
--- a/products/experiments/backend/temporal/schedule.py
+++ b/products/experiments/backend/temporal/schedule.py
@@ -13,9 +13,15 @@ from temporalio.client import (
from posthog.temporal.common.schedule import a_create_schedule, a_schedule_exists, a_update_schedule
-from products.experiments.backend.temporal.models import CANARY_WORKFLOW_NAME, ExperimentPrecomputeCanaryInputs
+from products.experiments.backend.temporal.models import (
+ CANARY_WORKFLOW_NAME,
+ ENROLLMENT_CENSUS_WORKFLOW_NAME,
+ ExperimentPrecomputeCanaryInputs,
+ ExperimentPrecomputeEnrollmentCensusInputs,
+)
CANARY_SCHEDULE_ID = "experiment-precompute-canary-schedule"
+ENROLLMENT_CENSUS_SCHEDULE_ID = "experiment-precompute-enrollment-census-schedule"
async def create_experiment_precompute_canary_schedule(client: Client) -> None:
@@ -43,3 +49,29 @@ async def create_experiment_precompute_canary_schedule(client: Client) -> None:
await a_update_schedule(client, CANARY_SCHEDULE_ID, schedule)
else:
await a_create_schedule(client, CANARY_SCHEDULE_ID, schedule, trigger_immediately=False)
+
+
+async def create_experiment_precompute_enrollment_census_schedule(client: Client) -> None:
+ """Daily report of teams that would qualify for precomputation enrollment. Report-only."""
+ schedule = Schedule(
+ action=ScheduleActionStartWorkflow(
+ ENROLLMENT_CENSUS_WORKFLOW_NAME,
+ ExperimentPrecomputeEnrollmentCensusInputs(),
+ id=f'{ENROLLMENT_CENSUS_SCHEDULE_ID}-{{{{.ScheduledTime.Format "2006-01-02"}}}}',
+ task_queue=settings.GENERAL_PURPOSE_TASK_QUEUE,
+ ),
+ spec=ScheduleSpec(
+ calendars=[
+ ScheduleCalendarSpec(
+ comment="Daily at 6 AM UTC",
+ hour=[ScheduleRange(start=6, end=6)],
+ )
+ ]
+ ),
+ policy=SchedulePolicy(overlap=ScheduleOverlapPolicy.SKIP),
+ )
+
+ if await a_schedule_exists(client, ENROLLMENT_CENSUS_SCHEDULE_ID):
+ await a_update_schedule(client, ENROLLMENT_CENSUS_SCHEDULE_ID, schedule)
+ else:
+ await a_create_schedule(client, ENROLLMENT_CENSUS_SCHEDULE_ID, schedule, trigger_immediately=False)
diff --git a/products/experiments/backend/temporal/test_enrollment_census_logic.py b/products/experiments/backend/temporal/test_enrollment_census_logic.py
new file mode 100644
index 000000000000..b280a5a4ffae
--- /dev/null
+++ b/products/experiments/backend/temporal/test_enrollment_census_logic.py
@@ -0,0 +1,99 @@
+import uuid
+from datetime import timedelta
+from typing import Any
+
+from freezegun import freeze_time
+from posthog.test.base import BaseTest
+
+from django.utils import timezone
+
+from parameterized import parameterized
+
+from products.experiments.backend.models.experiment import Experiment, ExperimentSavedMetric, ExperimentToSavedMetric
+from products.experiments.backend.temporal.enrollment_census_logic import (
+ BUILD_CAP_EXCLUSION_BYTES,
+ EXCLUSION_BUILD_BYTE_CAP,
+ TeamDirectScanStats,
+ TeamRunningLoad,
+ build_census_report,
+ running_experiment_load,
+)
+from products.feature_flags.backend.models.feature_flag import FeatureFlag
+
+
+def _stats(**overrides: Any) -> TeamDirectScanStats:
+ defaults: dict[str, Any] = {
+ "team_id": 1,
+ "direct_reads": 100,
+ "slow_reads": 0,
+ "max_read_bytes": 10**9,
+ "total_read_bytes": 10**11,
+ "hard_failures": 0,
+ "experiment_count": 3,
+ }
+ defaults.update(overrides)
+ return TeamDirectScanStats(**defaults)
+
+
+class TestEnrollmentCensusCriteria(BaseTest):
+ @parameterized.expand(
+ [
+ ("scan_volume", _stats(total_read_bytes=6 * 10**12), ("scan_volume",)),
+ ("slow_read_fraction", _stats(slow_reads=11), ("slow_reads",)),
+ ("hard_failures", _stats(hard_failures=5), ("hard_failures",)),
+ ("below_all_thresholds", _stats(slow_reads=10, hard_failures=4), ()),
+ ("too_few_reads", _stats(direct_reads=49, slow_reads=49, total_read_bytes=6 * 10**12), ()),
+ ]
+ )
+ def test_candidate_criteria(
+ self, _name: str, stats: TeamDirectScanStats, expected_reasons: tuple[str, ...]
+ ) -> None:
+ report = build_census_report([stats], window_days=14)
+ if expected_reasons:
+ assert len(report.candidates) == 1
+ assert report.candidates[0].reasons == expected_reasons
+ else:
+ assert report.candidates == ()
+ assert report.excluded == ()
+
+ def test_build_cap_team_is_excluded_not_enrolled(self) -> None:
+ stats = _stats(total_read_bytes=50 * 10**12, max_read_bytes=BUILD_CAP_EXCLUSION_BYTES + 1)
+ report = build_census_report([stats], window_days=14)
+ assert report.candidates == ()
+ assert len(report.excluded) == 1
+ assert report.excluded[0].reason == EXCLUSION_BUILD_BYTE_CAP
+
+ def test_candidates_ordered_by_total_bytes_descending(self) -> None:
+ small = _stats(team_id=1, total_read_bytes=6 * 10**12)
+ large = _stats(team_id=2, total_read_bytes=9 * 10**12)
+ report = build_census_report([small, large], window_days=14)
+ assert [candidate.stats.team_id for candidate in report.candidates] == [2, 1]
+
+ @freeze_time("2026-01-15")
+ def test_build_load_counts_running_experiments_and_all_metric_kinds(self) -> None:
+ def _experiment(metrics: list[dict], **kwargs: Any) -> Experiment:
+ return Experiment.objects.create(
+ team=self.team,
+ created_by=self.user,
+ feature_flag=FeatureFlag.objects.create(
+ team=self.team, created_by=self.user, key=f"flag-{uuid.uuid4().hex[:8]}"
+ ),
+ name="exp",
+ metrics=metrics,
+ start_date=timezone.now() - timedelta(days=3),
+ **kwargs,
+ )
+
+ running = _experiment(
+ metrics=[{"kind": "ExperimentMetric"}] * 2, metrics_secondary=[{"kind": "ExperimentMetric"}]
+ )
+ saved = ExperimentSavedMetric.objects.create(
+ team=self.team, name="saved", query={"kind": "ExperimentMetric", "metric_type": "funnel"}
+ )
+ ExperimentToSavedMetric.objects.create(experiment=running, saved_metric=saved, metadata={"type": "primary"})
+ _experiment(metrics=[{"kind": "ExperimentMetric"}], end_date=timezone.now())
+ _experiment(metrics=[{"kind": "ExperimentMetric"}], deleted=True)
+
+ assert running_experiment_load([self.team.id]) == {
+ self.team.id: TeamRunningLoad(running_experiments=1, running_metrics=4)
+ }
diff --git a/products/experiments/backend/temporal/test_registration.py b/products/experiments/backend/temporal/test_registration.py
index b74f73829c8b..91cba04a6ed8 100644
--- a/products/experiments/backend/temporal/test_registration.py
+++ b/products/experiments/backend/temporal/test_registration.py
@@ -1,5 +1,8 @@
from products.experiments.backend.temporal import ACTIVITIES, WORKFLOWS
from products.experiments.backend.temporal.canary_workflow import ExperimentPrecomputeCanaryWorkflow
+from products.experiments.backend.temporal.enrollment_census_workflow import (
+ ExperimentPrecomputeEnrollmentCensusWorkflow,
+)
from products.experiments.backend.temporal.recalculation_workflow import ExperimentMetricsRecalculationWorkflow
@@ -12,8 +15,13 @@ def test_activities_registered():
"sample_experiment_canary_targets",
"run_experiment_metric_canary",
"report_experiment_canary_results",
+ "run_experiment_enrollment_census",
}
def test_workflow_registered():
- assert WORKFLOWS == [ExperimentMetricsRecalculationWorkflow, ExperimentPrecomputeCanaryWorkflow]
+ assert WORKFLOWS == [
+ ExperimentMetricsRecalculationWorkflow,
+ ExperimentPrecomputeCanaryWorkflow,
+ ExperimentPrecomputeEnrollmentCensusWorkflow,
+ ]
diff --git a/tach.toml b/tach.toml
index 053559c64513..678f58c70224 100644
--- a/tach.toml
+++ b/tach.toml
@@ -1016,6 +1016,7 @@ expose = [
"backend\\.temporal\\.WORKFLOWS",
"backend\\.temporal\\.recalculation_metrics.*",
"backend\\.temporal\\.schedule\\.create_experiment_precompute_canary_schedule",
+ "backend\\.temporal\\.schedule\\.create_experiment_precompute_enrollment_census_schedule",
]
from = [
"products.experiments",