: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
fix(data-warehouse): explain a timed-out sync instead of showing Temporal's wording (#105114)
Tom Owers6cb5917d56af
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 8ee5a0234cef..4c6537c212a9 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@@ -13,7 +13,7 @@ from structlog.types import FilteringBoundLoggerfrom temporalio import activity, exceptions, workflowfrom temporalio.client import Clientfrom temporalio.common import RetryPolicy, WorkflowIDReusePolicy-from temporalio.exceptions import WorkflowAlreadyStartedError+from temporalio.exceptions import TimeoutType, WorkflowAlreadyStartedErrorfrom temporalio.workflow import ParentClosePolicy, start_child_workflow# TODO: remove dependency@@ -250,6 +250,20 @@ TRANSIENT_VENDOR_UNAVAILABLE_MESSAGE = ("Your source's API was temporarily unavailable, so this sync couldn't finish. The next sync runs on schedule.")+# An activity that ran past its start-to-close (or schedule-to-close) budget. Those budgets are a+# day for a full refresh and a week for an incremental run, so reaching one means the extraction+# itself cannot finish in the window rather than that something stalled.+SYNC_RUN_TOO_LONG_MESSAGE = (+ "This sync ran longer than PostHog allows and stopped before it finished. Switch this table to "+ "incremental sync, or sync less data, so the next run finishes in time."+)++# An activity that stopped heartbeating, or that no worker picked up in time. Both are PostHog-side+# and clear on their own, so the copy asks nothing of the customer.+SYNC_RUN_STALLED_MESSAGE = (+ "This sync stopped making progress on PostHog's side and did not finish. The next sync runs on schedule."+)+# A retryable failure that outlives its retries keeps whatever the driver said, so `latest_error`# ends up holding raw connection text — a psycopg "connection to server at <host>, port <port># failed: ..." line, a pymysql `(2013, ...)` tuple, a urllib3 connection-pool dump. None of it@@ -350,6 +364,14 @@ def _customer_facing_error(cause: BaseException | None) -> str:# sync retries on its next schedule.if getattr(cause, "type", None) == "RESTClientRetryableError":return TRANSIENT_SOURCE_ERROR_MESSAGE+ # A timed-out activity carries Temporal's own wording for its message ("activity StartToClose+ # timeout"), which names our orchestration rather than anything the customer can act on. Which+ # budget ran out decides the guidance: an exhausted run budget needs less data per run, while a+ # stalled or unclaimed activity is ours and recovers by itself.+ if isinstance(cause, exceptions.TimeoutError):+ if cause.type in (TimeoutType.START_TO_CLOSE, TimeoutType.SCHEDULE_TO_CLOSE):+ return SYNC_RUN_TOO_LONG_MESSAGE+ return SYNC_RUN_STALLED_MESSAGEmessage = getattr(cause, "message", None)return message or str(cause)diff --git a/products/warehouse_sources/backend/temporal/data_imports/tests/test_external_data_job_activities.py b/products/warehouse_sources/backend/temporal/data_imports/tests/test_external_data_job_activities.pyindex 637c0a4e7c57..c27e98b1af84 100644--- a/products/warehouse_sources/backend/temporal/data_imports/tests/test_external_data_job_activities.py+++ b/products/warehouse_sources/backend/temporal/data_imports/tests/test_external_data_job_activities.py@@ -7,7 +7,7 @@ from unittest import mockfrom django.test import SimpleTestCasefrom parameterized import parameterized-from temporalio.exceptions import ApplicationError, CancelledError+from temporalio.exceptions import ApplicationError, CancelledError, TimeoutError, TimeoutTypefrom temporalio.testing import ActivityEnvironmentfrom posthog.models import Organization, Team@@ -18,6 +18,8 @@ from products.warehouse_sources.backend.models.external_data_schema import Exterfrom products.warehouse_sources.backend.models.external_data_source import ExternalDataSourcefrom products.warehouse_sources.backend.temporal.data_imports.external_data_job import (CANCELLED_RUN_MESSAGE,+ SYNC_RUN_STALLED_MESSAGE,+ SYNC_RUN_TOO_LONG_MESSAGE,TRANSIENT_EGRESS_MESSAGE,TRANSIENT_POOLER_MESSAGE,TRANSIENT_SOURCE_CONNECTION_MESSAGE,@@ -65,6 +67,25 @@ class TestCustomerFacingError(SimpleTestCase):def test_missing_cause_does_not_show_the_customer_none(self) -> None:assert _customer_facing_error(None) == UNEXPECTED_ERROR_MESSAGE+ @parameterized.expand(+ [+ ("start_to_close", TimeoutType.START_TO_CLOSE, SYNC_RUN_TOO_LONG_MESSAGE),+ ("schedule_to_close", TimeoutType.SCHEDULE_TO_CLOSE, SYNC_RUN_TOO_LONG_MESSAGE),+ ("heartbeat", TimeoutType.HEARTBEAT, SYNC_RUN_STALLED_MESSAGE),+ ("schedule_to_start", TimeoutType.SCHEDULE_TO_START, SYNC_RUN_STALLED_MESSAGE),+ ("unknown", None, SYNC_RUN_STALLED_MESSAGE),+ ]+ )+ def test_timed_out_activity_does_not_surface_temporals_own_wording(+ self, _name: str, timeout_type: TimeoutType | None, expected: str+ ) -> None:+ # Temporal's message for a timed-out activity is "activity <Budget> timeout", which names our+ # orchestration and gives the customer nothing to act on.+ cause = TimeoutError("activity StartToClose timeout", type=timeout_type, last_heartbeat_details=[])+ result = _customer_facing_error(cause)+ assert result == expected+ assert "timeout" not in result+class TestIsAppDbFailure(SimpleTestCase):@parameterized.expand(