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): retry transient RPC timeouts starting the V3 post-import hand-off (#76365)

Tom Owers620685ad635e
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/load/processor.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/load/processor.py
index 8612cf38c099..864aa8f7892a 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/load/processor.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/load/processor.py
@@ -14,6 +14,8 @@ import posthoganalytics
from asgiref.sync import async_to_sync
from temporalio.common import WorkflowIDReusePolicy
from temporalio.exceptions import WorkflowAlreadyStartedError
+from temporalio.service import RPCError, RPCStatusCode
+from tenacity import retry, retry_if_exception, stop_after_attempt, wait_exponential_jitter
from posthog.exceptions_capture import capture_exception
from posthog.utils import get_machine_id
@@ -451,6 +453,14 @@ def _mark_job_completed(export_signal: ExportSignalMessage) -> None:
_release_pipeline_lock_for_job(export_signal)
+def _is_retryable_temporal_rpc_error(exc: BaseException) -> bool:
+ # These fire-and-forget starts run outside a Temporal workflow, so unlike
+ # `workflow.start_child_workflow` they get none of the server-side retry a durable
+ # workflow command would have — a bare client RPC timeout would otherwise drop the
+ # trigger permanently.
+ return isinstance(exc, RPCError) and exc.status in (RPCStatusCode.DEADLINE_EXCEEDED, RPCStatusCode.UNAVAILABLE)
+
+
def _trigger_ducklake_register_data_imports(export_signal: ExportSignalMessage, prepared_queryable_folder: str) -> None:
"""Fire-and-forget start of `ducklake-register.data-imports` after a V3 final batch lands.
@@ -481,6 +491,12 @@ def _trigger_ducklake_register_data_imports(export_signal: ExportSignalMessage,
# Connect and start inside one event loop: sync_connect() builds the client in
# asgiref's loop, and the start would then run on the loop async_to_sync spins up
# here. Start is fire-and-forget — we only need the start ack, not the result.
+ @retry(
+ retry=retry_if_exception(_is_retryable_temporal_rpc_error),
+ stop=stop_after_attempt(3),
+ wait=wait_exponential_jitter(initial=1, max=5),
+ reraise=True,
+ )
async def _start() -> None:
temporal = await async_connect()
await temporal.start_workflow(
@@ -557,6 +573,12 @@ def _trigger_post_import_workflow(export_signal: ExportSignalMessage) -> None:
# Connect and start inside one event loop (see the DuckLake trigger above).
# ALLOW_DUPLICATE_FAILED_ONLY keyed by job id: a redelivered final batch can't
# double-run a completed post-import, but can retry a failed one.
+ @retry(
+ retry=retry_if_exception(_is_retryable_temporal_rpc_error),
+ stop=stop_after_attempt(3),
+ wait=wait_exponential_jitter(initial=1, max=5),
+ reraise=True,
+ )
async def _start() -> None:
temporal = await async_connect()
await temporal.start_workflow(
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/load/test_processor.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/load/test_processor.py
index 81c2c5bb9452..972f70dbfc2d 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/load/test_processor.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/load/test_processor.py
@@ -8,6 +8,7 @@ import pyarrow as pa
from deltalake import DeltaTable, write_deltalake
from parameterized import parameterized
from temporalio.exceptions import WorkflowAlreadyStartedError
+from temporalio.service import RPCError, RPCStatusCode
from products.warehouse_sources.backend.temporal.data_imports.cdc.batcher import (
CDC_OP_COLUMN,
@@ -593,6 +594,58 @@ class TestPostImportTrigger:
assert mock_capture.called is expect_captured
+ def _signal(self) -> MagicMock:
+ signal = MagicMock()
+ signal.sync_type = "incremental"
+ signal.cdc_write_mode = None
+ signal.team_id = 1
+ signal.job_id = "job-1"
+ signal.schema_id = "schema-1"
+ signal.source_id = "source-1"
+ return signal
+
+ @patch(f"{_PROCESSOR}.capture_exception")
+ @patch("posthog.temporal.common.client.async_connect", new_callable=AsyncMock)
+ def test_transient_rpc_timeout_is_retried_and_recovers(
+ self,
+ mock_connect: AsyncMock,
+ mock_capture: MagicMock,
+ ) -> None:
+ # This start runs as a bare client RPC outside a Temporal workflow, so it gets
+ # none of the server-side retry a `workflow.start_child_workflow` command would
+ # have — a single transient timeout must not drop the trigger permanently.
+ client = MagicMock()
+ client.start_workflow = AsyncMock(
+ side_effect=[RPCError("Timeout expired", RPCStatusCode.DEADLINE_EXCEEDED, b""), None]
+ )
+ mock_connect.return_value = client
+
+ _trigger_post_import_workflow(self._signal())
+
+ assert client.start_workflow.call_count == 2
+ mock_capture.assert_not_called()
+
+ @patch(f"{_PROCESSOR}.capture_exception")
+ @patch("posthog.temporal.common.client.async_connect", new_callable=AsyncMock)
+ def test_persistent_rpc_timeout_is_captured_after_retries_exhausted(
+ self,
+ mock_connect: AsyncMock,
+ mock_capture: MagicMock,
+ ) -> None:
+ client = MagicMock()
+ client.start_workflow = AsyncMock(side_effect=RPCError("Timeout expired", RPCStatusCode.DEADLINE_EXCEEDED, b""))
+ mock_connect.return_value = client
+
+ _trigger_post_import_workflow(self._signal())
+
+ assert client.start_workflow.call_count == 3
+ mock_capture.assert_called_once()
+ # tenacity defaults to wrapping the last attempt in a RetryError once retries are
+ # exhausted; `reraise=True` must be set so the underlying RPCError reaches capture
+ # instead, keeping the error-tracking issue actionable.
+ captured_exception = mock_capture.call_args[0][0]
+ assert isinstance(captured_exception, RPCError)
+
# Regression guard for #70476: pyarrow 21+ string_view broke delta pushdown on string PKs.
class TestEnrichCdcRows: