: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-imports): retry delta table reset on transient S3 rate limits (#73407)
Tom Owers297b4e29bfca
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/extract.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/extract.pyindex b7faf622de95..44328dbeaaad 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/extract.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/extract.py@@ -494,6 +494,16 @@ async def handle_corrupted_delta_log(try:await delta_table_helper.reset_table()except Exception as e:+ if is_transient_object_store_error(e):+ # A rate-limited or connectivity blip purging the old table's S3 prefix isn't a bug —+ # the revive markers stay set, so the next sync attempt retries the same reset from+ # scratch. Escalating this through the non-retryable-error policy below would burn+ # through its attempt budget on pure S3 throttling and give up on a revivable schema.+ await logger.awarning(+ f"handle_corrupted_delta_log: reset_table transient object-store error, retrying next sync, "+ f"schema_id={schema.id}: {e}"+ )+ return False# A reset that can't even complete (e.g. the storage backend rejects the delete) leaves the# revive markers in place, so an unguarded re-raise here would repeat this exact same failing# reset on every subsequent sync attempt forever. Give up after a few identical failuresdiff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/test/test_extract.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/test/test_extract.pyindex e0e180a11671..30070ca96f09 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/test/test_extract.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/test/test_extract.py@@ -334,6 +334,32 @@ class TestHandleCorruptedDeltaLog:job.refresh_from_db()assert job.billable is True+ def test_reset_transient_object_store_error_retries_next_sync(self, team):+ # An S3 rate-limit blip purging the old table's prefix (see `_purge_s3_prefix`) is not a bug:+ # it must skip the non-retryable-error escalation above (which would burn through its attempt+ # budget on pure throttling) and leave the revive markers set so the next sync retries the+ # reset from scratch, instead of minting an error-tracking issue for a self-healing blip.+ schema, job = self._schema_and_job(team)+ reset_error = OSError("[Errno 16] Please reduce your request rate.")+ helper = MagicMock(+ is_table_corrupted=AsyncMock(return_value=True), reset_table=AsyncMock(side_effect=reset_error)+ )+ logger = self._logger()++ with (+ patch(f"{_EXTRACT_MODULE}.posthoganalytics"),+ patch(f"{_EXTRACT_MODULE}.capture_exception") as mock_capture,+ patch(f"{_EXTRACT_MODULE}.handle_non_retryable_error") as handle_mock,+ ):+ result = async_to_sync(handle_corrupted_delta_log)(schema, job, helper, logger)++ assert result is False+ mock_capture.assert_not_called()+ handle_mock.assert_not_called()+ logger.awarning.assert_awaited()+ job.refresh_from_db()+ assert job.billable is True+def test_revive_marker_resets_readable_table(self, team):# A hollow table — log opens fine but references data files gone from S3 — is invisible to# is_table_corrupted; the repartition scan marks it instead. The marker alone must trigger thediff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/delta_table_helper.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/delta_table_helper.pyindex 2e62d3493ca9..ed991bdb4327 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/delta_table_helper.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/delta_table_helper.py@@ -51,15 +51,19 @@ from products.warehouse_sources.backend.temporal.data_imports.pipelines.pipelineDEFAULT_COMPACT_FILES_PER_PARTITION_THRESHOLD = 200DEFAULT_COMPACT_TOTAL_FILES_THRESHOLD = 5000-# Substrings of the `OSError`s delta-rs's Rust `object_store` crate raises from-# `DeltaTable.is_deltatable()` when it can't reach or authenticate against our own S3-backed-# data-warehouse bucket (IMDS/STS blips, dispatch timeouts) — not a customer credential problem.-# Transient and self-recovering: the next maintenance pass re-lists from scratch, so these-# shouldn't be treated the same as a bug in our maintenance logic.+# Substrings of the `OSError`s raised talking to our own S3-backed data-warehouse bucket that are+# transient and self-recovering, not a bug in our code or a customer credential problem:+# - the first three come from delta-rs's Rust `object_store` crate inside `DeltaTable.is_deltatable()`+# (IMDS/STS blips, dispatch timeouts)+# - "Please reduce your request rate" is S3's SlowDown throttling response, surfaced by s3fs/aiobotocore+# when a bulk delete (e.g. `_purge_s3_prefix`) outruns the bucket's request-rate limit+# A retry (next maintenance pass, or next sync attempt) redoes the same idempotent operation from+# scratch, so these shouldn't be treated the same as a bug in our logic.TRANSIENT_OBJECT_STORE_ERRORS = ("an error occurred while loading credentials","the credential provider was not enabled","Generic S3 error",+ "Please reduce your request rate",)