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): stop retrying a MotherDuck sync that hits an out-of-memory wall (#117120)

Tom Owers5838c94857ee
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/motherduck/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/motherduck/source.py
index 43d64b9569d2..1865f55646e2 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/motherduck/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/motherduck/source.py
@@ -114,6 +114,20 @@ class MotherduckSource(SQLSource[MotherduckSourceConfig]):
MOTHERDUCK_ERROR_CLASSES["Invalid Input Error"]: _CONNECTION_DETAILS_MESSAGE,
"Invalid MotherDuck token": None,
"UNAUTHENTICATED": "Your MotherDuck token is invalid or expired. Generate a new access token and reconnect.",
+ # Raised uncaught from `get_rows`/discovery queries (they run outside `connect()`'s
+ # translation), so the raw DuckDB class prefix reaches here. DuckDB's own local 2GB
+ # `memory_limit` (`DUCKDB_LOCAL_CONFIG`) can raise the identical "Out of Memory Error"
+ # class for a failure entirely on our side, so match the remote duckling's own capacity
+ # guidance rather than the bare class name: that phrase only appears when MotherDuck's
+ # compute instance, not our worker, ran out of memory — a ceiling on the customer's
+ # account, same as the Postgres/MySQL/ClickHouse source-side OOM entries. Retrying
+ # re-runs the same query against the same duckling.
+ "duckling size": (
+ "MotherDuck ran out of memory running this sync's query. This usually means the "
+ "duckling (MotherDuck's compute instance) is too small for the amount of data being "
+ "read. Use a larger duckling size, or narrow the sync (switch to incremental, or "
+ "sync fewer tables/columns), then resync."
+ ),
}
def get_retryable_errors(self) -> set[str]:
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/motherduck/tests/test_motherduck.py b/products/warehouse_sources/backend/temporal/data_imports/sources/motherduck/tests/test_motherduck.py
index 52114e424024..e59dce8b73cb 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/motherduck/tests/test_motherduck.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/motherduck/tests/test_motherduck.py
@@ -320,6 +320,41 @@ class TestMotherDuck:
assert not error_message_matches(str(exc_info.value), source.get_non_retryable_errors())
assert error_message_matches(str(exc_info.value), source.get_retryable_errors())
+ @pytest.mark.parametrize(
+ "message,expect_non_retryable",
+ [
+ (
+ "Out of Memory Error: failed to offload data block of size 256.0 KiB "
+ "(244.0 GiB/244.0 GiB used).\n\nConsider using a larger duckling size than Standard "
+ "or optimizing your query to reduce memory usage.",
+ True,
+ ),
+ (
+ # DuckDB's own local `memory_limit` (`DUCKDB_LOCAL_CONFIG`) raises the identical
+ # exception class for a failure entirely inside our worker, carrying no duckling
+ # guidance. Must not be blamed on the customer's MotherDuck account.
+ "Out of Memory Error: failed to allocate data of size 64.0 KiB (2.0 GiB/2.0 GiB used).",
+ False,
+ ),
+ ],
+ ids=["remote_duckling_exhausted", "local_worker_allocation_failure"],
+ )
+ def test_out_of_memory_classification_depends_on_where_it_happened(
+ self, impl, source, message, expect_non_retryable
+ ):
+ # Reproduces the real path: `get_rows` raises the driver exception uncaught (it runs
+ # outside `connect()`'s translation), so classification has to match what actually
+ # reaches the activity, not a hand-written string read back against the error map.
+ metadata_conn, streaming_conn = self._pipeline_mocks([(["id"],)], 1, [pa.RecordBatch.from_pydict({"id": [1]})])
+ streaming_conn.to_arrow_reader.side_effect = duckdb.OutOfMemoryException(message)
+
+ with patch(_CONNECT_PATH, side_effect=[metadata_conn, streaming_conn]):
+ response = impl.build_pipeline(_make_config(), _make_inputs(schema_name="users"))
+ with pytest.raises(duckdb.OutOfMemoryException) as exc_info:
+ list(response.items())
+
+ assert error_message_matches(str(exc_info.value), source.get_non_retryable_errors()) is expect_non_retryable
+
def test_validate_credentials_requires_an_access_token(self, source):
ok, message = source.validate_credentials(_make_config(access_token=""), team_id=1)
assert ok is False