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.

refactor(experiments): dispatch recalculation workflows from one place (#109294)

Andersc9eb7f1cb558
diff --git a/products/experiments/backend/admin/recalculation_panel.py b/products/experiments/backend/admin/recalculation_panel.py
index 701ab76e0cec..0f7b9151cf83 100644
--- a/products/experiments/backend/admin/recalculation_panel.py
+++ b/products/experiments/backend/admin/recalculation_panel.py
@@ -27,6 +27,7 @@ from products.experiments.backend.models.experiment import (
from products.experiments.backend.recalculation import (
_derive_counters,
get_run_results,
+ metrics_recalculation_workflow_id,
request_recalculation,
start_metrics_recalculation_workflow,
)
@@ -106,7 +107,7 @@ def temporal_workflow_url(recalculation_id: str) -> str:
so it resolves per region without hardcoding a slug."""
return (
f"https://cloud.temporal.io/namespaces/{settings.TEMPORAL_NAMESPACE}"
- f"/workflows/experiment-metrics-recalculation-{recalculation_id}"
+ f"/workflows/{metrics_recalculation_workflow_id(recalculation_id)}"
)
@@ -162,17 +163,12 @@ def start_recalculation_for_experiment(
recalculation_id = str(result["id"])
try:
- start_metrics_recalculation_workflow(recalculation_id, str(experiment.team.organization_id))
+ start_metrics_recalculation_workflow(
+ recalculation_id,
+ team_id=experiment.team_id,
+ organization_id=str(experiment.team.organization_id),
+ )
except Exception as e:
- # start_workflow can raise after the server accepted the start, so only roll back a row that is
- # still PENDING with no query_to; a run past mark_started proceeds untouched, and one caught in
- # the discovery window is terminated cleanly by the mark_started/mark_completed guards
- # (mirrors the API rollback).
- ExperimentMetricsRecalculation.objects.for_team(experiment.team_id).filter(
- id=recalculation_id,
- status=ExperimentMetricsRecalculation.Status.PENDING,
- query_to__isnull=True,
- ).update(status=ExperimentMetricsRecalculation.Status.FAILED)
messages.error(request, f"Created the row but failed to start the workflow (marked failed): {e}")
return HttpResponseRedirect(fallback_url)
diff --git a/products/experiments/backend/presentation/views.py b/products/experiments/backend/presentation/views.py
index 444449726c93..8591096f2386 100644
--- a/products/experiments/backend/presentation/views.py
+++ b/products/experiments/backend/presentation/views.py
@@ -123,6 +123,7 @@ from products.experiments.backend.recalculation import (
get_recalculation_by_id,
get_run_results,
request_recalculation,
+ start_metrics_recalculation_workflow,
)
from products.experiments.backend.running_time_calculator import (
BaselineStats,
@@ -151,9 +152,6 @@ from products.experiments.backend.setup_context import (
SetupContextInputs,
build_setup_context,
)
-from products.experiments.backend.temporal.models import (
- ExperimentMetricsRecalculationWorkflowInputs as MetricsRecalcInputs,
-)
from products.feature_flags.backend.models.evaluation_context import FeatureFlagEvaluationContext
from products.feature_flags.backend.models.feature_flag import FeatureFlag
from products.tasks.backend.facade import api as tasks_facade
@@ -1400,36 +1398,11 @@ class EnterpriseExperimentsViewSet(
is_existing = result.get("is_existing", False)
if not is_existing:
- recalculation_id = str(result["id"])
- try:
- temporal = sync_connect()
- asyncio.run(
- temporal.start_workflow(
- "experiment-metrics-recalculation-workflow",
- MetricsRecalcInputs(
- recalculation_id=recalculation_id,
- fairness_key=str(experiment.team.organization_id),
- ),
- id=f"experiment-metrics-recalculation-{recalculation_id}",
- task_queue=settings.EXPERIMENTS_RECALCULATION_TASK_QUEUE,
- )
- )
- except Exception:
- # team-scoped filter: defense in depth so the rollback can never reach across teams even if
- # recalculation_id were ever sourced from somewhere less trusted than the row we just created.
- # start_workflow can raise after the server accepted the start (e.g. RPC deadline on the
- # response leg), so only roll back a row that is still PENDING with no query_to. A row past
- # mark_started belongs to its running workflow and proceeds untouched. In the narrow window
- # where only discovery ran, the rollback wins deliberately: the mark_started and
- # mark_completed guards then terminate that orphan cleanly, and the client's retry of the
- # failed POST starts the replacement.
- ExperimentMetricsRecalculation.objects.filter(
- team=self.team,
- id=recalculation_id,
- status=ExperimentMetricsRecalculation.Status.PENDING,
- query_to__isnull=True,
- ).update(status=ExperimentMetricsRecalculation.Status.FAILED)
- raise
+ start_metrics_recalculation_workflow(
+ str(result["id"]),
+ team_id=experiment.team_id,
+ organization_id=str(experiment.team.organization_id),
+ )
return Response(
ExperimentMetricsRecalculationJobSerializer(result).data,
diff --git a/products/experiments/backend/recalculation.py b/products/experiments/backend/recalculation.py
index bc7eea4dfe6d..37843a3a6492 100644
--- a/products/experiments/backend/recalculation.py
+++ b/products/experiments/backend/recalculation.py
@@ -39,7 +39,10 @@ from products.experiments.backend.models.experiment import (
ExperimentMetricsRecalculation,
)
from products.experiments.backend.result_serialization import strip_step_sessions
-from products.experiments.backend.temporal.models import ExperimentMetricsRecalculationWorkflowInputs
+from products.experiments.backend.temporal.models import (
+ METRICS_RECALCULATION_WORKFLOW_NAME,
+ ExperimentMetricsRecalculationWorkflowInputs,
+)
from products.experiments.backend.temporal.recalc_fingerprint import compute_recalc_fingerprint
from products.experiments.backend.temporal.recalculation_logic import discover_experiment_metrics
@@ -47,8 +50,9 @@ from products.experiments.backend.temporal.recalculation_logic import discover_e
# stale and a fresh recalc is allowed. Sized to be safely above the workflow's worst-case end-to-end runtime
# (discovery retries + per-metric calc retries + progress activities) so a legitimately-slow run can finish
# without being clobbered, but tight enough that an operator can recover within an hour if the workflow
-# never started (Temporal connect failure, transient infra issue, etc.). See the rollback in views.py for the
-# happy-path failure handling; this TTL is the defense-in-depth backstop if that rollback itself fails.
+# never started (Temporal connect failure, transient infra issue, etc.). See the rollback in
+# start_metrics_recalculation_workflow for the happy-path failure handling; this TTL is the defense-in-depth
+# backstop if that rollback itself fails.
_STALE_RECALC_THRESHOLD = timedelta(minutes=30)
# A daily timeseries point older than this no longer stands in for a recalculation on the cold-start read. The
@@ -63,7 +67,7 @@ _recalculation_reuse_counter = Counter(
)
# Fires whenever the 30-min staleness threshold marks a PENDING/IN_PROGRESS row FAILED so the experiment
# can recalculate again. A sustained climb is a leading indicator of Temporal connect failures or the
-# rollback path in views.py itself failing.
+# rollback in start_metrics_recalculation_workflow itself failing.
_recalculation_stale_cleanup_counter = Counter(
"experiment_metrics_recalculation_stale_rows_cleaned",
"Stale recalc rows force-failed to release the per-experiment uniqueness constraint.",
@@ -213,27 +217,53 @@ def build_job_payload(
return payload
+def metrics_recalculation_workflow_id(recalculation_id: str) -> str:
+ """Temporal workflow id of a recalculation run. The start, the cancel and the admin's Temporal link all
+ find a running workflow by this id, so a format change orphans the workflows that are already running."""
+ return f"experiment-metrics-recalculation-{recalculation_id}"
+
+
def cancel_recalculation_workflow(recalculation_id: str) -> None:
"""Best-effort cancel of a single recalc's Temporal workflow. Swallows failures (already-finished or
never-started runs) so callers can pair it with a status write without the cancel masking that write."""
_cancel_superseded_workflows([recalculation_id])
-def start_metrics_recalculation_workflow(recalculation_id: str, organization_id: str) -> None:
- """Dispatch the recalculation Temporal workflow for an already-created pending row. Mirrors the API's
- start path (task queue + org-scoped fairness key) so the admin and the viewset stay in step."""
- temporal = sync_connect()
- asyncio.run(
- temporal.start_workflow(
- "experiment-metrics-recalculation-workflow",
- ExperimentMetricsRecalculationWorkflowInputs(
- recalculation_id=recalculation_id,
- fairness_key=organization_id,
- ),
- id=f"experiment-metrics-recalculation-{recalculation_id}",
- task_queue=settings.EXPERIMENTS_RECALCULATION_TASK_QUEUE,
+def start_metrics_recalculation_workflow(recalculation_id: str, *, team_id: int, organization_id: str) -> None:
+ """Dispatch the recalculation Temporal workflow for a row that request_recalculation just created.
+
+ Start every recalculation workflow through this function, so the workflow name and id, the task queue,
+ the org-scoped fairness key and the rollback stay in one place. If the start fails, the row is marked
+ FAILED when it is safe to do so, and the exception propagates to the caller.
+ """
+ try:
+ temporal = sync_connect()
+ asyncio.run(
+ temporal.start_workflow(
+ METRICS_RECALCULATION_WORKFLOW_NAME,
+ ExperimentMetricsRecalculationWorkflowInputs(
+ recalculation_id=recalculation_id,
+ fairness_key=organization_id,
+ ),
+ id=metrics_recalculation_workflow_id(recalculation_id),
+ task_queue=settings.EXPERIMENTS_RECALCULATION_TASK_QUEUE,
+ )
)
- )
+ except Exception:
+ # team-scoped filter: defense in depth so the rollback can never reach across teams even if
+ # recalculation_id were ever sourced from somewhere less trusted than the row we just created.
+ # start_workflow can raise after the server accepted the start (e.g. RPC deadline on the
+ # response leg), so only roll back a row that is still PENDING with no query_to. A row past
+ # mark_started belongs to its running workflow and proceeds untouched. In the narrow window
+ # where only discovery ran, the rollback wins deliberately: the mark_started and
+ # mark_completed guards then terminate that orphan cleanly, and the caller's retry (a new
+ # POST, or the admin action again) starts the replacement.
+ ExperimentMetricsRecalculation.objects.for_team(team_id).filter(
+ id=recalculation_id,
+ status=ExperimentMetricsRecalculation.Status.PENDING,
+ query_to__isnull=True,
+ ).update(status=ExperimentMetricsRecalculation.Status.FAILED)
+ raise
def _cancel_superseded_workflows(recalculation_ids: list[str]) -> None:
@@ -245,7 +275,7 @@ def _cancel_superseded_workflows(recalculation_ids: list[str]) -> None:
return
for recalculation_id in recalculation_ids:
try:
- handle = temporal.get_workflow_handle(f"experiment-metrics-recalculation-{recalculation_id}")
+ handle = temporal.get_workflow_handle(metrics_recalculation_workflow_id(recalculation_id))
asyncio.run(handle.cancel())
except Exception:
# Expected for rows whose workflow never started (Temporal connect failure) or already finished.
diff --git a/products/experiments/backend/temporal/ARCHITECTURE.md b/products/experiments/backend/temporal/ARCHITECTURE.md
index 9faf3d524c57..90e06ea680d3 100644
--- a/products/experiments/backend/temporal/ARCHITECTURE.md
+++ b/products/experiments/backend/temporal/ARCHITECTURE.md
@@ -41,7 +41,8 @@ sequenceDiagram
Service->>DB: lock experiment, create or fetch active run
DB-->>Service: row (id, status)
Service-->>API: payload + is_existing
- API->>Workflow: start_workflow(recalculation_id)
+ API->>Service: start_metrics_recalculation_workflow(recalculation_id)
+ Service->>Workflow: start_workflow(recalculation_id)
API-->>FE: 201 (or 200 if reusing active run)
Worker->>Workflow: wrap execute (latency + finished counter)
diff --git a/products/experiments/backend/temporal/models.py b/products/experiments/backend/temporal/models.py
index 00bec875e738..b480b178f724 100644
--- a/products/experiments/backend/temporal/models.py
+++ b/products/experiments/backend/temporal/models.py
@@ -29,6 +29,9 @@ ALL_OUTCOMES: tuple[CanaryOutcome, ...] = (
# Cap CanaryMetricResult.detail so a pathological error message can't bloat the Temporal payload.
MAX_CANARY_DETAIL_LENGTH = 1000
+# Open executions and the workflow_type metric label carry this name, so a rename strands running workflows.
+METRICS_RECALCULATION_WORKFLOW_NAME = "experiment-metrics-recalculation-workflow"
+
# Max attempts per metric before it's marked failed on the recalculation workflow.
MAX_METRIC_ATTEMPTS = 8
diff --git a/products/experiments/backend/temporal/recalculation_metrics.py b/products/experiments/backend/temporal/recalculation_metrics.py
index c67a2a066904..346c91857af7 100644
--- a/products/experiments/backend/temporal/recalculation_metrics.py
+++ b/products/experiments/backend/temporal/recalculation_metrics.py
@@ -24,8 +24,8 @@ from temporalio.worker import (
from posthog.temporal.ai_observability.metrics import ExecutionTimeRecorder
-# The workflow type name (matches @workflow.defn(name=...) in recalculation_workflow).
-_RECALCULATION_WORKFLOW_TYPE = "experiment-metrics-recalculation-workflow"
+from products.experiments.backend.temporal.models import METRICS_RECALCULATION_WORKFLOW_NAME
+
# Activity type names (the registered activity function names).
_RECALCULATION_ACTIVITY_TYPES = {
"discover_experiment_metrics",
@@ -88,7 +88,7 @@ def increment_workflow_finished(status: str) -> None:
`workflow_type` is attached so dashboards stay scoped when other experiments workflows ship later.
"""
workflow.metric_meter().with_additional_attributes(
- {"status": status, "workflow_type": _RECALCULATION_WORKFLOW_TYPE}
+ {"status": status, "workflow_type": METRICS_RECALCULATION_WORKFLOW_NAME}
).create_counter(
"experiment_metrics_recalculation_workflow_finished",
"Number of experiment metrics recalculation workflows that reached a terminal state.",
@@ -111,7 +111,7 @@ class _ActivityInboundInterceptor(ActivityInboundInterceptor):
return await super().execute_activity(input)
meter = activity.metric_meter().with_additional_attributes(
- {"activity_type": activity_type, "workflow_type": _RECALCULATION_WORKFLOW_TYPE}
+ {"activity_type": activity_type, "workflow_type": METRICS_RECALCULATION_WORKFLOW_NAME}
)
# Queue-pressure signal (see bucket comment above). Per-attempt scheduling time, so retry backoff
# (including the intentional quota-wait delays) doesn't read as queue pressure.
@@ -135,7 +135,7 @@ class _ActivityInboundInterceptor(ActivityInboundInterceptor):
description="Execution latency for experiment metrics recalculation activities.",
histogram_attributes={
"activity_type": activity_type,
- "workflow_type": _RECALCULATION_WORKFLOW_TYPE,
+ "workflow_type": METRICS_RECALCULATION_WORKFLOW_NAME,
},
):
result = await super().execute_activity(input)
@@ -162,10 +162,10 @@ class _ActivityInboundInterceptor(ActivityInboundInterceptor):
class _WorkflowInboundInterceptor(WorkflowInboundInterceptor):
async def execute_workflow(self, input: ExecuteWorkflowInput) -> typing.Any:
- if workflow.info().workflow_type != _RECALCULATION_WORKFLOW_TYPE:
+ if workflow.info().workflow_type != METRICS_RECALCULATION_WORKFLOW_NAME:
return await super().execute_workflow(input)
workflow.metric_meter().with_additional_attributes(
- {"workflow_type": _RECALCULATION_WORKFLOW_TYPE}
+ {"workflow_type": METRICS_RECALCULATION_WORKFLOW_NAME}
).create_counter(
"experiment_metrics_recalculation_workflow_started",
"Number of experiment metrics recalculation workflows started.",
@@ -174,7 +174,7 @@ class _WorkflowInboundInterceptor(WorkflowInboundInterceptor):
with ExecutionTimeRecorder(
"experiment_metrics_recalculation_workflow_execution_latency",
description="End-to-end execution latency for the experiment metrics recalculation workflow.",
- histogram_attributes={"workflow_type": _RECALCULATION_WORKFLOW_TYPE},
+ histogram_attributes={"workflow_type": METRICS_RECALCULATION_WORKFLOW_NAME},
):
return await super().execute_workflow(input)
except BaseException:
diff --git a/products/experiments/backend/temporal/recalculation_workflow.py b/products/experiments/backend/temporal/recalculation_workflow.py
index a45a371c4163..a9c7e8c1b2a2 100644
--- a/products/experiments/backend/temporal/recalculation_workflow.py
+++ b/products/experiments/backend/temporal/recalculation_workflow.py
@@ -11,6 +11,7 @@ with temporalio.workflow.unsafe.imports_passed_through():
from products.experiments.backend.temporal.models import (
MAX_METRIC_ATTEMPTS,
METRIC_CALC_ACTIVITY_TIMEOUT_SECONDS,
+ METRICS_RECALCULATION_WORKFLOW_NAME,
RECALCULATION_PROGRESS_ACTIVITY_TIMEOUT_SECONDS,
RECALCULATION_RETRY_BACKOFF_COEFFICIENT,
RECALCULATION_RETRY_INITIAL_INTERVAL_SECONDS,
@@ -26,7 +27,7 @@ with temporalio.workflow.unsafe.imports_passed_through():
from products.experiments.backend.temporal.recalculation_metrics import increment_workflow_finished
[email protected](name="experiment-metrics-recalculation-workflow")
[email protected](name=METRICS_RECALCULATION_WORKFLOW_NAME)
class ExperimentMetricsRecalculationWorkflow(PostHogWorkflow):
"""Recalculate all metrics for an experiment on demand.
diff --git a/products/experiments/backend/test/test_metrics_recalculation_api.py b/products/experiments/backend/test/test_metrics_recalculation_api.py
index de6e22d0233a..20b189ef5c61 100644
--- a/products/experiments/backend/test/test_metrics_recalculation_api.py
+++ b/products/experiments/backend/test/test_metrics_recalculation_api.py
@@ -4,6 +4,7 @@ import time_machine
from posthog.test.base import APIBaseTest
from unittest import mock
+from django.conf import settings
from django.utils import timezone
from parameterized import parameterized
@@ -16,6 +17,7 @@ from products.experiments.backend.models.experiment import (
ExperimentMetricResult,
ExperimentMetricsRecalculation,
)
+from products.experiments.backend.temporal.models import ExperimentMetricsRecalculationWorkflowInputs
from products.experiments.backend.temporal.recalc_fingerprint import compute_recalc_fingerprint
from products.feature_flags.backend.models.feature_flag import FeatureFlag
@@ -72,8 +74,8 @@ class TestMetricsRecalculationAPI(APIBaseTest):
# POST /metrics_recalculation/
# ------------------------------------------------------------------
- @mock.patch("products.experiments.backend.presentation.views.sync_connect")
- @mock.patch("products.experiments.backend.presentation.views.asyncio.run")
+ @mock.patch("products.experiments.backend.recalculation.sync_connect")
+ @mock.patch("products.experiments.backend.recalculation.asyncio.run")
def test_post_creates_and_starts_workflow(self, mock_run, mock_connect):
exp = self._launched_experiment()
resp = self.client.post(self._post_url(exp.id), {"trigger": "manual"}, format="json")
@@ -82,9 +84,17 @@ class TestMetricsRecalculationAPI(APIBaseTest):
assert body["status"] == "pending"
assert ExperimentMetricsRecalculation.objects.filter(experiment=exp).count() == 1
assert mock_run.called
+ mock_connect.return_value.start_workflow.assert_called_once_with(
+ "experiment-metrics-recalculation-workflow",
+ ExperimentMetricsRecalculationWorkflowInputs(
+ recalculation_id=body["id"], fairness_key=str(self.organization.id)
+ ),
+ id=f"experiment-metrics-recalculation-{body['id']}",
+ task_queue=settings.EXPERIMENTS_RECALCULATION_TASK_QUEUE,
+ )
- @mock.patch("products.experiments.backend.presentation.views.sync_connect")
- @mock.patch("products.experiments.backend.presentation.views.asyncio.run")
+ @mock.patch("products.experiments.backend.recalculation.sync_connect")
+ @mock.patch("products.experiments.backend.recalculation.asyncio.run")
def test_post_from_mcp_client_attributes_trigger_to_agent(self, mock_run, mock_connect):
exp = self._launched_experiment()
resp = self.client.post(self._post_url(exp.id), format="json", headers={"X-PostHog-Client": "mcp"})
@@ -94,8 +104,8 @@ class TestMetricsRecalculationAPI(APIBaseTest):
== ExperimentMetricsRecalculation.Trigger.AGENT_MCP
)
- @mock.patch("products.experiments.backend.presentation.views.sync_connect")
- @mock.patch("products.experiments.backend.presentation.views.asyncio.run")
+ @mock.patch("products.experiments.backend.recalculation.sync_connect")
+ @mock.patch("products.experiments.backend.recalculation.asyncio.run")
def test_post_without_mcp_header_honors_body_trigger(self, mock_run, mock_connect):
exp = self._launched_experiment()
resp = self.client.post(self._post_url(exp.id), {"trigger": "manual"}, format="json")
@@ -105,8 +115,8 @@ class TestMetricsRecalculationAPI(APIBaseTest):
== ExperimentMetricsRecalculation.Trigger.MANUAL
)
- @mock.patch("products.experiments.backend.presentation.views.sync_connect")
- @mock.patch("products.experiments.backend.presentation.views.asyncio.run")
+ @mock.patch("products.experiments.backend.recalculation.sync_connect")
+ @mock.patch("products.experiments.backend.recalculation.asyncio.run")
def test_each_endpoint_returns_only_its_own_fields(self, mock_run, mock_connect):
exp = self._launched_experiment()
created = self.client.post(self._post_url(exp.id), {"trigger": "manual"}, format="json").json()
@@ -122,8 +132,8 @@ class TestMetricsRecalculationAPI(APIBaseTest):
assert latest["active_run"] == {"id": created["id"], "status": "pending"}
assert {"is_existing", "trigger"}.isdisjoint(latest)
- @mock.patch("products.experiments.backend.presentation.views.sync_connect")
- @mock.patch("products.experiments.backend.presentation.views.asyncio.run")
+ @mock.patch("products.experiments.backend.recalculation.sync_connect")
+ @mock.patch("products.experiments.backend.recalculation.asyncio.run")
def test_post_is_idempotent_returns_200(self, mock_run, mock_connect):
exp = self._launched_experiment()
first = self.client.post(self._post_url(exp.id), {"trigger": "manual"}, format="json")
@@ -133,8 +143,8 @@ class TestMetricsRecalculationAPI(APIBaseTest):
assert second.json()["id"] == first.json()["id"]
assert ExperimentMetricsRecalculation.objects.filter(experiment=exp).count() == 1
- @mock.patch("products.experiments.backend.presentation.views.sync_connect")
- @mock.patch("products.experiments.backend.presentation.views.asyncio.run")
+ @mock.patch("products.experiments.backend.recalculation.sync_connect")
+ @mock.patch("products.experiments.backend.recalculation.asyncio.run")
def test_post_rejects_unlaunched_experiment(self, mock_run, mock_connect):
exp = Experiment.objects.create(
team=self.team, created_by=self.user, feature_flag=self._flag("unlaunched"), name="draft"
@@ -142,10 +152,8 @@ class TestMetricsRecalculationAPI(APIBaseTest):
resp = self.client.post(self._post_url(exp.id), {"trigger": "manual"}, format="json")
assert resp.status_code == status.HTTP_400_BAD_REQUEST
- @mock.patch(
- "products.experiments.backend.presentation.views.sync_connect", side_effect=RuntimeError("temporal down")
- )
- @mock.patch("products.experiments.backend.presentation.views.asyncio.run")
+ @mock.patch("products.experiments.backend.recalculation.sync_connect", side_effect=RuntimeError("temporal down"))
+ @mock.patch("products.experiments.backend.recalculation.asyncio.run")
def test_post_marks_failed_when_workflow_start_errors(self, mock_run, mock_connect):
# When the workflow start fails, the view marks the freshly-created row FAILED then re-raises.
# The DRF test client converts the exception into a 500 response rather than propagating it.
@@ -155,8 +163,8 @@ class TestMetricsRecalculationAPI(APIBaseTest):
row = ExperimentMetricsRecalculation.objects.get(experiment=exp)
assert row.status == ExperimentMetricsRecalculation.Status.FAILED
- @mock.patch("products.experiments.backend.presentation.views.sync_connect")
- @mock.patch("products.experiments.backend.presentation.views.asyncio.run")
+ @mock.patch("products.experiments.backend.recalculation.sync_connect")
+ @mock.patch("products.experiments.backend.recalculation.asyncio.run")
def test_post_rollback_spares_row_already_started_by_workflow(self, mock_run, mock_connect):
# start_workflow can raise after Temporal accepted the start (RPC failure on the response leg).
# By then the worker may have run mark_started; flipping that row to FAILED would release the
@@ -340,7 +348,7 @@ class TestMetricsRecalculationAPI(APIBaseTest):
assert resp.status_code == status.HTTP_404_NOT_FOUND
@time_machine.travel("2026-09-01T12:00:00Z", tick=False)
- @mock.patch("products.experiments.backend.presentation.views.sync_connect")
+ @mock.patch("products.experiments.backend.recalculation.sync_connect")
def test_get_latest_fallback_does_not_start_a_workflow(self, mock_connect):
# GET stays a pure read: the fallback path must never connect to Temporal.
exp = self._launched_experiment(flag_key="ts-pure-read")
diff --git a/pyproject.toml b/pyproject.toml
index cd677d01410d..1aa01b3e33ef 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -718,7 +718,6 @@ ignore_imports = [
"products.experiments.backend.presentation.views -> products.experiments.backend.session_context",
"products.experiments.backend.presentation.views -> products.experiments.backend.session_event_deltas",
"products.experiments.backend.presentation.views -> products.experiments.backend.setup_context",
- "products.experiments.backend.presentation.views -> products.experiments.backend.temporal.models",
"products.experiments.backend.presentation.views -> products.feature_flags.backend.models.evaluation_context",
"products.experiments.backend.presentation.views -> products.feature_flags.backend.models.feature_flag",
# TODO: data_warehouse presentation wave — the structural move landed the viewsets under