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-imports): skip a snapshot file deleted by a concurrent compaction (#97284)

Tom Owersc48652b468d2
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/person_property_sync.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/person_property_sync.py
index a07f674a2392..163b04a7ab7d 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/person_property_sync.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/person_property_sync.py
@@ -258,7 +258,13 @@ async def _merge_snapshot_files(s3_client, file_keys: list[str]) -> dict[str, st
them oldest-first). Decodes off the event loop so a large parquet can't starve the heartbeater."""
hashes: dict[str, str] = {}
for key in file_keys:
- data = await s3_client._cat_file(_s3_uri(key))
+ try:
+ data = await s3_client._cat_file(_s3_uri(key))
+ except FileNotFoundError:
+ # A concurrent _write_snapshot_hashes compacted this file into a new one and deleted it
+ # after we listed the folder but before we read it. Its rows survive in that new file (or
+ # whichever one replaces it next run) — skip rather than fail the whole read.
+ continue
for record in await asyncio.to_thread(_decode_parquet_rows, data):
hashes[record["distinct_id"]] = record["sent_hash"]
return hashes
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/person_property_sync_test.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/person_property_sync_test.py
index aaa831c0dcc6..87bca87a62a3 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/person_property_sync_test.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/person_property_sync_test.py
@@ -355,7 +355,10 @@ class _FakeS3:
return entries
async def _cat_file(self, path):
- return self.store[pps._s3_key(path)]
+ key = pps._s3_key(path)
+ if key not in self.store:
+ raise FileNotFoundError(path)
+ return self.store[key]
async def _pipe_file(self, path, data):
self._clock += 1
@@ -412,6 +415,20 @@ class TestSnapshotCompaction:
assert len(keys) == 1
assert hashes == {"a": "h2", "b": "h2"}
+ @pytest.mark.asyncio
+ async def test_read_tolerates_file_deleted_by_concurrent_compaction(self):
+ """A concurrent _write_snapshot_hashes run can merge a listed file into a new one and delete it
+ between our listing and our read of it — the read must skip the vanished file, not crash."""
+ fake = _FakeS3()
+ with _fake_s3_patch(fake):
+ await pps._write_snapshot_hashes(1, _SCHEMA, "src", "job-1", {"a": "h1"})
+ keys = await pps._list_snapshot_files(fake, pps._snapshot_prefix(1, _SCHEMA, "src"))
+ await fake._rm(keys)
+
+ hashes = await pps._merge_snapshot_files(fake, keys)
+
+ assert hashes == {}
+
class TestGroupTarget:
"""The group branch: a group source produces a $groupidentify-shaped intent and checks group