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): stop reporting the v3 lock takeover race to error tracking (#104766)

Tom Owers119aa63e74b4
diff --git a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/create_job_model.py b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/create_job_model.py
index eb034715bba3..8fe61a780b4b 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/create_job_model.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/create_job_model.py
@@ -11,7 +11,6 @@ from django.utils import timezone
import posthoganalytics
from structlog.contextvars import bind_contextvars
from temporalio import activity
-from temporalio.exceptions import ApplicationError
from posthog.exceptions_capture import capture_exception
from posthog.models.team.team import Team
@@ -89,6 +88,15 @@ class SourceOrSchemaDeletedError(NonReportableError):
"""
+class V3PipelineLockLostError(NonReportableError):
+ """Another run's lock takeover (see acquire_v3_lock.py) reassigned the v3 pipeline lock
+ away from this run before it reached job creation. The takeover path only steals from a
+ holder whose Temporal workflow already looks terminal, so a resumed run landing here is
+ the mechanism working as designed, not a defect — subclassing ``NonReportableError`` keeps
+ it out of error tracking, matching ``SourceOrSchemaDeletedError`` above.
+ """
+
+
def _statistics_stale(team_id: int, table: DataWarehouseTable | None) -> bool:
"""Whether column statistics need recomputing: no stats yet, or the freshest column row is older
than the recompute interval. Mirrors compute_table_statistics' own skip check so we don't spawn a
@@ -141,10 +149,7 @@ def _verify_v3_lock_still_held(team_id: int, schema_id: uuid.UUID) -> None:
if holder is None:
return
if holder != run_id:
- raise ApplicationError(
- "v3 pipeline lock lost to another run before job creation",
- non_retryable=True,
- )
+ raise V3PipelineLockLostError("v3 pipeline lock lost to another run before job creation")
# Per-run state, not configuration. `cdc_deferred_runs` is a notification queue that reaches
@@ -424,6 +429,10 @@ def create_external_data_job_model_activity(
person_property_sync_enabled=person_property_sync_enabled,
fast_return_eligible=fast_return_eligible,
)
+ except V3PipelineLockLostError:
+ # The takeover race the guard handles, not a defect — skip the generic handler's
+ # stack trace log, same reasoning as SourceOrSchemaDeletedError above.
+ raise
except Exception as e:
logger.exception(
f"External data job failed on create_external_data_job_model_activity for {str(inputs.source_id)} with error: {e}"
diff --git a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_create_job_model.py b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_create_job_model.py
index 77b5cd305723..fb0f34ae6b4b 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_create_job_model.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_create_job_model.py
@@ -8,7 +8,6 @@ from django.db import OperationalError
from django.utils import timezone
from parameterized import parameterized
-from temporalio.exceptions import ApplicationError
from posthog.models import Organization, Team
from posthog.temporal.common.posthog_client import is_expected_activity_failure
@@ -23,6 +22,7 @@ from products.warehouse_sources.backend.models.table import DataWarehouseTable
from products.warehouse_sources.backend.temporal.data_imports.workflow_activities.create_job_model import (
CreateExternalDataJobModelActivityInputs,
SourceOrSchemaDeletedError,
+ V3PipelineLockLostError,
_build_schema_snapshot,
_create_job,
_enrichment_pending,
@@ -88,9 +88,11 @@ class TestVerifyV3LockStillHeld:
mock_get_holder.return_value = holder
if expect_raise:
- with pytest.raises(ApplicationError) as exc_info:
+ with pytest.raises(V3PipelineLockLostError) as exc_info:
_verify_v3_lock_still_held(1, self.SCHEMA_ID)
- assert exc_info.value.non_retryable is True
+ # The takeover in acquire_v3_lock.py only steals from a terminal-looking holder, so
+ # this is the mechanism working as designed and must not open an error tracking issue.
+ assert is_expected_activity_failure(exc_info.value)
else:
_verify_v3_lock_still_held(1, self.SCHEMA_ID)