: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): surface terminal repartition give-ups in error tracking (#87429)
Tom Owers7d3a5e328063
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/repartition.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/repartition.pyindex 340b3f70da76..7ea61c5f9c2e 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/repartition.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/repartition.py@@ -165,6 +165,19 @@ class RepartitionSupersededError(Exception):"""+class RepartitionAttemptsExhausted(Exception):+ """Every one of `MAX_REPARTITION_ATTEMPTS` rewrites was charged but none survived to record an+ outcome, so the controller gives up and backs the table off to the daily cooldown.++ Each attempt is charged before the rewrite runs and refunded on a clean stand-down (supersession,+ cancellation, transient infra), so reaching the cap this way means every attempt was hard-killed+ mid-run — worker OOM, activity timeout, or an eviction that didn't surface as a cancellation —+ before it could fail cleanly or checkpoint progress. Terminal, and unlike a caught failure it+ carries no underlying exception, so the give-up path constructs and captures this to keep the most+ severe repartition outcome visible in error tracking rather than silently abandoned.+ """++@dataclasses.dataclass(frozen=True)class RepartitionTarget:"""The partition scheme to rewrite a table into. `partition_mode=None` means auto-detect."""diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/test_repartition_controller.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/test_repartition_controller.pyindex 612055bc2d98..8223363eb746 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/test_repartition_controller.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/test_repartition_controller.py@@ -33,6 +33,7 @@ from products.warehouse_sources.backend.temporal.data_imports import workload_refrom products.warehouse_sources.backend.temporal.data_imports.pipelines.core import repartition_controller as ctrlfrom products.warehouse_sources.backend.temporal.data_imports.pipelines.core.consts import PARTITION_KEYfrom products.warehouse_sources.backend.temporal.data_imports.pipelines.core.repartition import (+ RepartitionAttemptsExhausted,RepartitionSupersededError,RepartitionUnpartitionableError,)@@ -955,6 +956,46 @@ class TestRepartitionActivity:schema.refresh_from_db()assert schema.repartition_pending is None+ @pytest.mark.parametrize("trigger_reason", ["coarsening", "admin"])+ def test_give_up_reports_to_error_tracking(self, team, trigger_reason):+ # The give-up path fires when the cap is already spent by attempts that were hard-killed before+ # they could record an outcome. It is the only terminal repartition path that never ran+ # `_handle_failure` (which captures), so without an explicit capture here the most severe+ # outcome — a table the controller has abandoned — is invisible in error tracking.+ schema = _make_schema(team, {})+ schema.set_repartition_pending(+ {+ "partition_mode": "md5",+ "partition_count": 4,+ "partition_keys": ["id"],+ "trigger_reason": trigger_reason,+ "attempts": ctrl.MAX_REPARTITION_ATTEMPTS,+ }+ )+ rewrite = AsyncMock()+ with (+ patch.object(repartition_table, "HeartbeaterSync"),+ patch.object(repartition_table, "repartition_table_in_place", new=rewrite),+ patch.object(repartition_table, "capture_repartition_event") as capture,+ patch.object(repartition_table, "capture_exception") as capture_exception,+ patch.object(repartition_table, "is_auto_repartition_enabled", return_value=True),+ # A coarsening trigger answers to the coarsen flag, not the repartition one; without this the+ # activity releases the queued rewrite before reaching the give-up.+ patch.object(repartition_table, "is_auto_coarsen_enabled", return_value=True),+ ):+ ActivityEnvironment().run(maybe_repartition_table_activity, self._inputs(team, schema))++ # The cap was already spent, so no rewrite is attempted — this is the pre-run give-up.+ rewrite.assert_not_called()+ capture_exception.assert_called_once()+ assert isinstance(capture_exception.call_args.args[0], RepartitionAttemptsExhausted)+ failed = [c.args[1] for c in capture.call_args_list if c.args[0] == "warehouse_repartition_failed"]+ assert len(failed) == 1+ assert failed[0]["final"] is True+ assert failed[0]["error_type"] == "RepartitionAttemptsExhausted"+ schema.refresh_from_db()+ assert schema.repartition_pending is None+@pytest.mark.parametrize("cancel_exc", [asyncio.CancelledError(), CancelledError()])def test_cancellation_propagates_and_is_not_recorded(self, team, cancel_exc):# A worker-shutdown cancellation — whether it arrives as a real asyncio.CancelledError or wrappeddiff --git a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/repartition_table.py b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/repartition_table.pyindex 95c81bc0465d..2a1a6d4cdf26 100644--- a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/repartition_table.py+++ b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/repartition_table.py@@ -39,6 +39,7 @@ from products.warehouse_sources.backend.temporal.data_imports.pipelines.core.del)from products.warehouse_sources.backend.temporal.data_imports.pipelines.core.delta.table import DeltaTableReffrom products.warehouse_sources.backend.temporal.data_imports.pipelines.core.repartition import (+ RepartitionAttemptsExhausted,RepartitionBudgetExceededError,RepartitionSupersededError,RepartitionTarget,@@ -673,17 +674,26 @@ def _give_up(schema.clear_repartition_swap()schema.clear_repartition_rewrite()schema.stamp_last_repartition_at()+ error = RepartitionAttemptsExhausted(+ f"repartition gave up after {MAX_REPARTITION_ATTEMPTS} attempts that did not survive to record "+ f"an outcome (trigger_reason={trigger_reason})"+ )props = base_event_props(schema, schema.source, inputs.job_id)props.update({"trigger_reason": trigger_reason,"attempts": int((pending or {}).get("attempts", 0)),"final": True,- "error_type": "RepartitionAttemptsExhausted",- "error_message": "attempts exhausted without any surviving to record an outcome",+ "error_type": type(error).__name__,+ "error_message": str(error),})capture_repartition_event("warehouse_repartition_failed", props)+ # Terminal, and the only terminal path that did not already report to error tracking: every attempt+ # was hard-killed before it could run `_handle_failure` (which captures). Capture here too so a table+ # the controller has abandoned surfaces as an issue instead of only a metric — the sync context is+ # already bound (bind_job_context) so the issue is attributed to the connector and table.+ capture_exception(error)DELTA_REPARTITION_TOTAL.labels(team_id=str(inputs.team_id), outcome="failed").inc()