: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
chore(warehouse-sources): give run-finalization ownership one named home (#77630)
estefania55a0269ee88f
diff --git a/products/warehouse_sources/backend/temporal/data_imports/external_data_job.py b/products/warehouse_sources/backend/temporal/data_imports/external_data_job.pyindex 4b234967200b..2be35769656c 100644--- a/products/warehouse_sources/backend/temporal/data_imports/external_data_job.py+++ b/products/warehouse_sources/backend/temporal/data_imports/external_data_job.py@@ -593,6 +593,10 @@ class ExternalDataJobWorkflow(PostHogWorkflow):**timeout_params,) # type: ignore+ # Run-finalization ownership (terminal status write, v3 lock release, post-import+ # start) — the full contract lives on the PipelineResult docstring. False on every+ # failure path by construction: a raising activity returns no result, so this line+ # is never reached and the workflow finalizes in `finally`.consumer_manages_job_status = pipeline_result.get("consumer_manages_job_status", False)skip_post_import_activities = pipeline_result.get("skip_post_import_activities", False)diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/typings.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/typings.pyindex 6b6177fd1527..166538fbee4b 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/typings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/typings.py@@ -2,6 +2,27 @@ from typing import NotRequired, TypedDictclass PipelineResult(TypedDict):+ """The import activity's report back to `ExternalDataJobWorkflow`.++ `consumer_manages_job_status` is the run-finalization ownership contract. Exactly one party+ writes the terminal job status, releases the v3 sync lock, and starts the post-import+ workflow:++ - False / absent (v2, and every failure path — an activity that raises returns no result):+ the workflow finalizes in its `finally` block.+ - True: the v3 load consumer finalizes after loading the final batch, and the workflow must+ keep its hands off all three.++ It is a runtime value, not a pure property of `ExternalDataJob.pipeline_version`, for one+ reason: a v3 extraction that produced zero batches never notifies the load consumer, so the+ consumer cannot finalize a run it will never hear about — the workflow must. PipelineV3+ therefore reports True iff at least one batch reached the queue. The two other producers of+ True (`import_data_sync`'s terminal-retry skip, and the CDC-handled-externally path) are+ runs some other party already finalized, where True likewise means "workflow: hands off".+ Making this a pure version property requires an empty-final-batch queue message so the+ consumer hears about every v3 run — deferred until the v2 pipeline is deleted.+ """+should_trigger_cdp_producer: boolconsumer_manages_job_status: NotRequired[bool]skip_post_import_activities: NotRequired[bool]diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/pipeline.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/pipeline.pyindex 518309e723a8..badbfb5244b4 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/pipeline.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/pipeline.py@@ -367,9 +367,14 @@ class PipelineV3(Generic[ResumableData]):await self._finalize(row_count=row_count)+ # With zero batches, `_finalize` sent no final-batch notification, so the load+ # consumer will never hear about this run and cannot finalize it — the workflow must.+ # See the PipelineResult docstring for the full ownership contract.+ consumer_will_hear_about_this_run = len(self._batch_results) > 0+return {"should_trigger_cdp_producer": await self._sinks.cdp_producer.should_run(),- "consumer_manages_job_status": len(self._batch_results) > 0,+ "consumer_manages_job_status": consumer_will_hear_about_this_run,}except Exception:status = "error"diff --git a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/import_data_sync.py b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/import_data_sync.pyindex ac3c08629e7f..af1e770e6247 100644--- a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/import_data_sync.py+++ b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/import_data_sync.py@@ -123,6 +123,8 @@ async def import_data_activity_sync(inputs: ImportDataActivityInputs) -> Pipelinstatus=model.status,attempt=attempt,)+ # The consumer already finalized this run (that's how it became terminal), so the+ # workflow must not overwrite the status or release the lock — see PipelineResult.return PipelineResult(should_trigger_cdp_producer=False,consumer_manages_job_status=True,@@ -279,6 +281,8 @@ async def import_data_activity_sync(inputs: ImportDataActivityInputs) -> Pipelinexcept Exception:await logger.awarning("Failed to pause per-schema schedule for CDC streaming schema")+ # This activity finalized the job itself just above, so the workflow must not+ # write a second terminal status — see PipelineResult for the ownership contract.return PipelineResult(should_trigger_cdp_producer=False,consumer_manages_job_status=True,@@ -463,7 +467,7 @@ async def _run(if use_v3:from products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline_v3 import PipelineV3- logger.info("Running V3 pipeline (feature flag enabled)")+ logger.info("Running V3 pipeline (persisted job.pipeline_version is V3)")pipeline: PipelineV3 | PipelineNonDLT = PipelineV3(source_response,logger,