: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): stop repartition re-flag loop on terminal skips (#73489)
Tom Owerse2bff30849ee
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/repartition_controller.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/repartition_controller.pyindex d011c2be697c..e17f3f5224b5 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/repartition_controller.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/repartition_controller.py@@ -277,6 +277,12 @@ async def maybe_flag_for_repartition(partition_count=len(partition_bytes),)capture_exception(Exception(f"Repartition needed but skipped for schema {schema.id}: {reason}"))+ # Engage the cooldown even though no rewrite happened: the trigger (over budget or repeated+ # OOMs) is still true next sync and the table's scheme can't go finer, so without this we+ # re-measure, re-emit the skip event, and re-alert on every 5-minute sync forever. The+ # cooldown re-evaluates at most daily; a real change to the table clears it via a later+ # successful repartition.+ await asyncio.to_thread(schema.stamp_last_repartition_at)returnpending = {**target.to_dict(), "trigger_reason": trigger_reason, "attempts": 0}diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/test_repartition_controller.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/test_repartition_controller.pyindex 3e4611a29fa4..7194d6767193 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/test_repartition_controller.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/test_repartition_controller.py@@ -184,6 +184,30 @@ class TestRepartitionDetection:assert schema.repartition_pending is Noneassert capture.call_args.args[0] == "warehouse_repartition_skipped"assert capture.call_args.args[1]["reason"] == "unpartitionable_no_keys"+ # A table with no usable partition target must engage the cooldown, otherwise detection+ # re-measures and re-emits the skip on every 5-minute sync forever (the loop we're fixing).+ assert schema.last_repartition_at is not None++ def test_unpartitionable_skip_does_not_reflag_next_sync(self, team):+ # Regression: the terminal skip stamps the cooldown so the immediately-following sync is a+ # no-op instead of re-emitting flagged/skipped — this is the every-5-minute loop guard.+ schema = _make_schema(team, {})+ with tempfile.TemporaryDirectory() as d:+ delta = _write_unpartitioned_delta(f"{d}/u")+ with (+ patch.object(ctrl, "target_partition_bytes", return_value=1),+ patch.object(ctrl, "is_auto_repartition_enabled", return_value=True),+ patch.object(ctrl, "capture_repartition_event") as capture,+ ):+ self._detect(team, schema, delta)+ first_pass_events = [c.args[0] for c in capture.call_args_list]+ capture.reset_mock()+ schema.refresh_from_db()+ self._detect(team, schema, delta)+ second_pass_events = [c.args[0] for c in capture.call_args_list]++ assert "warehouse_repartition_skipped" in first_pass_events+ assert second_pass_events == []def test_unpartitioned_over_budget_with_keys_enables_partitioning(self, team):# An unpartitioned table that's over budget but HAS a usable key must be flagged to become@@ -408,6 +432,9 @@ class TestRepartitionActivity:schema.refresh_from_db()assert schema.repartition_pending is Noneassert "warehouse_repartition_skipped" in [c.args[0] for c in capture.call_args_list]+ # Clearing pending alone re-arms the loop — detection re-flags the unchanged table next sync.+ # The cooldown stamp is what actually stops the flag → start → skip churn every 5 minutes.+ assert schema.last_repartition_at is not Nonedef test_failure_increments_attempts_without_clearing(self, team):schema = _make_schema(team, {})diff --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 de09b976cdea..2cebc37c0125 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@@ -290,9 +290,14 @@ def _maybe_repartition_table(inputs: RepartitionActivityInputs, logger: FilterinDELTA_REPARTITION_TOTAL.labels(team_id=str(inputs.team_id), outcome="superseded").inc()returnexcept RepartitionUnpartitionableError as e:- # Terminal: the table can't be partitioned. Clear the flag so we don't retry every run.+ # Terminal: the table can't be partitioned on its keys. Clear the flag AND engage the cooldown —+ # clearing `repartition_pending` alone re-arms the loop, because detection re-flags on the very+ # next sync (the OOM/size trigger is still true and the table's scheme is unchanged), so the+ # table churns flag → start → skip every 5 minutes forever. The cooldown re-evaluates at most+ # daily instead.schema.refresh_from_db(fields=["sync_type_config"])schema.clear_repartition_pending()+ schema.stamp_last_repartition_at()props = base_event_props(schema, schema.source, inputs.job_id)props.update({"trigger_reason": trigger_reason, "reason": str(e)})capture_repartition_event("warehouse_repartition_skipped", props)