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-warehouse): stop delta revive marker resurrecting after removal (#71531)

Tom Owers29208dc8f643
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.py
index f8f7083d74e2..f216ea912ccc 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
@@ -470,8 +470,10 @@ async def handle_corrupted_delta_log(
)
# The completed swap copied the full temp table over live, so any hollow-table
- # marker is stale now.
- await database_sync_to_async_pool(update_sync_type_config_keys)(
+ # marker is stale now. Refresh the in-memory config from the persisted result —
+ # this schema object keeps saving `sync_type_config` for the rest of the run, and
+ # a stale copy would write the marker back, re-arming the revive every sync.
+ schema.sync_type_config = await database_sync_to_async_pool(update_sync_type_config_keys)(
schema.id, schema.team_id, removes=["delta_revive_required"]
)
await logger.ainfo(
@@ -491,7 +493,10 @@ async def handle_corrupted_delta_log(
await delta_table_helper.reset_table()
await database_sync_to_async_pool(schema.update_sync_type_config_for_reset_pipeline)()
- await database_sync_to_async_pool(update_sync_type_config_keys)(
+ # Refresh the in-memory config from the persisted result — this schema object keeps saving
+ # `sync_type_config` for the rest of the run (incremental staging, partition bookkeeping), and
+ # a stale copy would write the marker back, re-arming a non-billable revive on every sync.
+ schema.sync_type_config = await database_sync_to_async_pool(update_sync_type_config_keys)(
schema.id, schema.team_id, removes=["repartition_pending", "repartition_swap", "delta_revive_required"]
)
was_billable = bool(job.billable)
diff --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.py
index 85155f8e2305..7b7ec5dd7fe9 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
@@ -287,6 +287,11 @@ class TestHandleCorruptedDeltaLog:
helper.reset_table.assert_awaited_once()
job.refresh_from_db()
assert job.billable is False
+ # The in-memory copy must be refreshed too: the pipeline keeps saving this same schema
+ # object for the rest of the run (incremental staging, partition bookkeeping), and a stale
+ # copy writes the marker back — re-arming a non-billable full rebuild on every sync.
+ assert "delta_revive_required" not in schema.sync_type_config
+ schema.stage_incremental_field_value("run-1", 5)
schema.refresh_from_db()
assert "delta_revive_required" not in schema.sync_type_config
assert ph.capture.call_args.kwargs["properties"]["outcome"] == "reset_rebuild"
@@ -296,8 +301,11 @@ class TestHandleCorruptedDeltaLog:
# rather than reset — the customer's data is recovered without a rebuild, so reset_table never runs
# and the job stays billable. Guards the salvage-from-temp branch against regressing to a reset.
schema, job = self._schema_and_job(team)
+ # A hollow-table marker can coexist with the interrupted swap (the repartition scan set it
+ # before the swap crashed) — the salvage must clear it in memory as well as in the DB.
schema.sync_type_config = {
- "repartition_swap": {"state": "ready", "temp_uri": "s3://bucket/temp", "live_uri": "s3://bucket/live"}
+ "repartition_swap": {"state": "ready", "temp_uri": "s3://bucket/temp", "live_uri": "s3://bucket/live"},
+ "delta_revive_required": {"reason": "repartition_scan_missing_data_file", "missing_path": "x/p.parquet"},
}
schema.save(update_fields=["sync_type_config"])
helper = MagicMock(
@@ -323,6 +331,12 @@ class TestHandleCorruptedDeltaLog:
helper.reset_table.assert_not_awaited()
job.refresh_from_db()
assert job.billable is True
+ # Same stale-copy guard as the reset path: a later full-config save off this schema object
+ # must not write the cleared marker back.
+ assert "delta_revive_required" not in schema.sync_type_config
+ schema.stage_incremental_field_value("run-1", 5)
+ schema.refresh_from_db()
+ assert "delta_revive_required" not in schema.sync_type_config
# A salvage must be observable too, tagged as recovered-from-temp with the rebuild left billable.
assert ph.capture.call_args.kwargs["event"] == "warehouse_delta_revived"
assert ph.capture.call_args.kwargs["properties"]["outcome"] == "salvaged"