: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): widen copy-files retry budget for zombie compaction races (#84959)
Tom Owers3159304e4eb0
diff --git a/products/warehouse_sources/backend/temporal/data_imports/tests/test_util.py b/products/warehouse_sources/backend/temporal/data_imports/tests/test_util.pyindex 945e6c1684a0..8821e453a56a 100644--- a/products/warehouse_sources/backend/temporal/data_imports/tests/test_util.py+++ b/products/warehouse_sources/backend/temporal/data_imports/tests/test_util.py@@ -149,6 +149,34 @@ class TestPrepareS3FilesForQuerying:assert cp_file.await_count == util_module._COPY_FILES_MAX_ATTEMPTSassert refresh_file_uris.await_count == util_module._COPY_FILES_MAX_ATTEMPTS - 1+ async def test_retry_backoff_outlasts_documented_worst_case_compaction_time(self):+ # A zombie compact+vacuum pass can keep deleting source files for as long as its own+ # rewrite takes - documented up to ~45s for a pathological table in+ # core/delta/maintenance.py. Regression for the retry budget silently falling back under+ # that documented worst case (it did: 4 attempts only covered ~14s of backoff).+ cp_file = AsyncMock(side_effect=FileNotFoundError("s3://bucket/job/my_table/part-0.parquet"))+ s3 = _fake_s3(_cp_file=cp_file)+ refresh_file_uris = AsyncMock(return_value=["s3://bucket/job/my_table/part-0.parquet"])+ sleeps: list[float] = []++ async def _record_sleep(seconds: float) -> None:+ sleeps.append(seconds)++ with (+ patch.object(util_module, "aget_s3_client", return_value=_FakeS3CM(s3)),+ patch("asyncio.sleep", side_effect=_record_sleep),+ ):+ with pytest.raises(FileNotFoundError):+ await prepare_s3_files_for_querying(+ folder_path="job",+ table_name="my_table",+ file_uris=["s3://bucket/job/my_table/part-0.parquet"],+ delete_existing=False,+ refresh_file_uris=refresh_file_uris,+ )++ assert sum(sleeps) > 45+async def test_propagates_vanished_source_file_without_refresh_callback(self):# Callers that don't pass refresh_file_uris keep today's behavior: the race still# surfaces as an error instead of being retried blindly.diff --git a/products/warehouse_sources/backend/temporal/data_imports/util.py b/products/warehouse_sources/backend/temporal/data_imports/util.pyindex 3be1ffa7f489..3b5bd4853527 100644--- a/products/warehouse_sources/backend/temporal/data_imports/util.py+++ b/products/warehouse_sources/backend/temporal/data_imports/util.py@@ -66,9 +66,11 @@ S3_DELETE_TIME_BUFFER = 600# A zombie compaction+vacuum pass (a heartbeat-timed-out activity attempt still running) can keep# deleting source files for as long as its own rewrite takes - documented up to ~45s for a-# fragmented table in core/delta/maintenance.py - which can outlive a single retry. Bound the retries-# with backoff instead, mirroring _purge_s3_prefix's approach to the same class of race.-_COPY_FILES_MAX_ATTEMPTS = 4+# fragmented table in core/delta/maintenance.py, before vacuum even starts - which can outlive a+# single retry. Bound the retries with backoff instead, mirroring _purge_s3_prefix's approach to+# the same class of race. 6 attempts gives ~62s of cumulative backoff (2+4+8+16+32s), comfortably+# past that documented worst case; 4 attempts (~14s) wasn't.+_COPY_FILES_MAX_ATTEMPTS = 6def is_posthog_team(team_id: int) -> bool: