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(clickhouse): treat exceeded result-size limits as non-retryable (#106050)

Tom Owers35b56f147e3f
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/source.py
index 4b4329483b2c..61da18de99c8 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/source.py
@@ -325,6 +325,16 @@ class ClickHouseSource(SimpleSource[ClickHouseSourceConfig], SSHTunnelMixin, Val
# something we can change our side, so retrying just re-loads an
# already disk-pressured server.
"Code: 243": "Your ClickHouse server ran out of disk space while we were reading a table (it couldn't reserve space for a temporary file). Try scaling up your ClickHouse service or freeing disk space, or sync a smaller table or use an incremental sync, then resume.",
+ # TOO_MANY_ROWS_OR_BYTES (code 396) — the source server's own `max_result_bytes`/
+ # `max_result_rows` limit rejected our extraction query because the table
+ # (or incremental window) is larger than that limit allows. Like Code: 241
+ # and Code: 243 this is a capacity/config limit on the customer's database,
+ # not something we can change our side, so retrying just replays the same
+ # oversized query against the same limit. We match the ClickHouse error-code
+ # name rather than "Code: 396" because some ClickHouse-compatible endpoints
+ # (e.g. Tinybird) wrap this error without the usual "Code: NNN. DB::Exception:"
+ # native wording.
+ "TOO_MANY_ROWS_OR_BYTES": "Your ClickHouse server's result size limit was exceeded while reading this table. Raise the max_result_bytes/max_result_rows limit for the user PostHog connects with, sync fewer columns, or switch this table to an incremental sync so each run reads a smaller window, then resume.",
# Raised from the shared `evolve_pyarrow_schema` in `pipelines/core/arrow_utils.py`
# when an integer column's source type was widened (e.g. `Int32` → `Int64`) after
# the destination table was created with the narrower type. Delta Lake can't widen
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/test_clickhouse.py b/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/test_clickhouse.py
index 4c9194bfd221..7e951254b6f8 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/test_clickhouse.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/test_clickhouse.py
@@ -675,6 +675,13 @@ class TestClickHouseSourceNonRetryableErrors:
"Received ClickHouse exception, code: 243 (for url https://host:8443)\n Code: 243. "
"DB::Exception: Failed to reserve 1048576 bytes for temporary file: reason cannot evict "
"enough space: While executing BufferingToFileSink. (NOT_ENOUGH_SPACE)",
+ # TOO_MANY_ROWS_OR_BYTES (code 396) — the source server's own result-size
+ # limit rejected the extraction query. Some ClickHouse-compatible endpoints
+ # (e.g. Tinybird) wrap this without the usual "Code: NNN. DB::Exception:"
+ # native wording, so the match must not depend on that shape.
+ "Received ClickHouse exception, code: 396, server response: [Error] Limit for result "
+ "exceeded, max bytes: 500.00 MiB, current bytes: 501.03 MiB. (TOO_MANY_ROWS_OR_BYTES) "
+ "(query_id=abc123) (for url https://host:8443)",
# Source table no longer exists at sync time — dropped/renamed, or a materialized
# view's `.inner_id.<uuid>` inner table whose UUID changed when the view was recreated.
"Table soax_stage..inner_id.8c612ff0-b72c-4b20-8ea5-405ed002c2f6 not found or has no columns",