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.

fix(data-imports): stamp the full-run marker on a zero-batch v3 run (#93715)

Daniel RC34d41925241a
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.py
index 54020ea2e80b..dd5bd45cd21d 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
@@ -1,5 +1,6 @@
import time
import asyncio
+import datetime
from typing import TYPE_CHECKING, Any, Generic
import pyarrow as pa
@@ -502,6 +503,26 @@ class PipelineV3(Generic[ResumableData]):
str(self._job.id), self._job.team_id, self._schema.id, pa_table.num_rows, self._logger
)
+ async def _stamp_full_run(self) -> None:
+ """Record that this run took the full extraction path, for the fast-return valve.
+
+ Writes only `last_full_run_at`, which `_fast_return_eligible` is the sole reader of.
+ `last_synced_at` is deliberately left alone: it feeds data freshness, the schemas UI and
+ the signals watermark (`partition_field > last_synced_at`), so moving it on a run that
+ loaded nothing would narrow the next run's signal window.
+
+ Best-effort: a bookkeeping failure must not fail an otherwise successful sync, which is
+ how the observed-columns write above treats the same risk.
+ """
+ try:
+ await database_sync_to_async_pool(update_sync_type_config_keys)(
+ self._schema.id,
+ self._job.team_id,
+ updates={"last_full_run_at": datetime.datetime.now(datetime.UTC).isoformat()},
+ )
+ except Exception:
+ await self._logger.aexception("V3 Pipeline: Failed to stamp last_full_run_at")
+
async def _finalize(self, row_count: int) -> None:
# Column-picker bookkeeping — a failure here must not fail an otherwise successful sync.
if self._observed_columns:
@@ -518,6 +539,11 @@ class PipelineV3(Generic[ResumableData]):
total_batches = len(self._batch_results)
if total_batches == 0:
+ # A zero-batch run still ran the full extraction, which is what the fast-return
+ # valve counts. Post-load stamps this on every other path but never runs here: with
+ # no batches the load consumer is never notified. Without this a v3 schema whose
+ # source stays quiet could never satisfy `_fast_return_eligible`.
+ await self._stamp_full_run()
self._logger.debug("V3 Pipeline: No batches extracted, skipping finalization")
return
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/test_pipeline.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/test_pipeline.py
index 41a1a7b3b3bc..a2ec372381fc 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/test_pipeline.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/test_pipeline.py
@@ -15,6 +15,7 @@ def _make_logger() -> MagicMock:
logger.ainfo = AsyncMock()
logger.awarning = AsyncMock()
logger.aerror = AsyncMock()
+ logger.aexception = AsyncMock()
logger.exception = MagicMock()
return logger
@@ -309,3 +310,31 @@ class TestCDCSeqProvenanceSurvivesStaging:
buf.seek(0)
assert has_engine_seq(pq.read_table(buf))
+
+
+class TestZeroBatchRunStampsTheFullRunMarker:
+ @pytest.mark.asyncio
+ async def test_a_run_that_extracted_nothing_still_counts_as_a_full_run(self) -> None:
+ pipeline = _make_pipeline()
+ pipeline._batch_results = []
+
+ with patch(
+ "products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline_v3.pipeline.update_sync_type_config_keys",
+ new=MagicMock(),
+ ) as update:
+ await pipeline._finalize(row_count=0)
+
+ update.assert_called_once()
+ assert "last_full_run_at" in update.call_args.kwargs["updates"]
+ assert "extra_model_fields" not in update.call_args.kwargs
+
+ @pytest.mark.asyncio
+ async def test_a_bookkeeping_failure_does_not_fail_the_sync(self) -> None:
+ pipeline = _make_pipeline()
+ pipeline._batch_results = []
+
+ with patch(
+ "products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline_v3.pipeline.update_sync_type_config_keys",
+ new=MagicMock(side_effect=RuntimeError("pooler is down")),
+ ):
+ await pipeline._finalize(row_count=0)