: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-imports): classify postgres cdc quota errors as non-retryable (#102797)
Tom Owers765e95fc0db2
diff --git a/products/warehouse_sources/backend/temporal/data_imports/cdc/errors.py b/products/warehouse_sources/backend/temporal/data_imports/cdc/errors.pyindex 57ee8ede73e1..5672d07d326f 100644--- a/products/warehouse_sources/backend/temporal/data_imports/cdc/errors.py+++ b/products/warehouse_sources/backend/temporal/data_imports/cdc/errors.py@@ -27,6 +27,7 @@ class CDCErrorCategory(enum.StrEnum):SSL_REQUIRED = "ssl_required"CONNECTION_FAILED = "connection_failed"HOST_UNREACHABLE = "host_unreachable"+ QUOTA_EXCEEDED = "quota_exceeded"SSH_TUNNEL_FAILED = "ssh_tunnel_failed"SLOT_MISSING = "slot_missing"SLOT_NOT_CONFIGURED = "slot_not_configured"@@ -119,6 +120,12 @@ _CATEGORY_DEFAULTS: dict[CDCErrorCategory, tuple[str, bool]] = {"change data capture once it's reachable.",False,),+ CDCErrorCategory.QUOTA_EXCEEDED: (+ "Your database provider blocked the connection because your account or project exceeded a "+ "usage quota. Upgrade your provider's plan or wait for the quota to reset, then re-enable "+ "change data capture.",+ False,+ ),CDCErrorCategory.SSH_TUNNEL_FAILED: ("Could not connect to your SSH tunnel — PostHog couldn't open a session to the SSH gateway. ""Check that the SSH host and port point to a reachable SSH server (not the database port), "diff --git a/products/warehouse_sources/backend/temporal/data_imports/cdc/tests/test_errors.py b/products/warehouse_sources/backend/temporal/data_imports/cdc/tests/test_errors.pyindex aa41b9d0b12b..a25261ee8c2f 100644--- a/products/warehouse_sources/backend/temporal/data_imports/cdc/tests/test_errors.py+++ b/products/warehouse_sources/backend/temporal/data_imports/cdc/tests/test_errors.py@@ -34,6 +34,7 @@ class TestCDCErrorInfo:(CDCErrorCategory.SSL_REQUIRED, False),(CDCErrorCategory.CONNECTION_FAILED, True),(CDCErrorCategory.HOST_UNREACHABLE, False),+ (CDCErrorCategory.QUOTA_EXCEEDED, False),(CDCErrorCategory.SLOT_MISSING, False),(CDCErrorCategory.SLOT_NOT_CONFIGURED, False),(CDCErrorCategory.PUBLICATION_MISSING, False),diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/cdc/errors.py b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/cdc/errors.pyindex e04ffd2e24e7..c4e6dedac76a 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/cdc/errors.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/cdc/errors.py@@ -47,6 +47,16 @@ _HOST_UNREACHABLE_MARKERS = ("enetunreach",)+# A managed provider (observed on Neon) blocks the connection once the account or project has+# exceeded a usage quota, reporting a plain libpq ERROR rather than a connection failure. Mirrors+# the non-retryable treatment on the batch path (PostgresSource.get_non_retryable_errors's+# "exceeded the compute time quota" / "exceeded the data transfer quota" entries), which use more+# specific wording for those two quota types; this is the more generic sibling. The block only+# lifts when the customer upgrades the plan or the quota resets, so without this marker it falls+# through to the generic CONNECTION_FAILED bucket below and retries indefinitely into the same+# wall. Match the stable quota phrase; it names no volatile host/IP/port detail.+_QUOTA_EXCEEDED_MARKER = "exceeded the quota"+# sshtunnel raises BaseSSHTunnelForwarderError("Could not establish session to SSH gateway") when it# can't open a session to the bastion — the SSH host/port is wrong or unreachable, the bastion is# down, or its firewall blocks PostHog's IPs. Deterministic for the configured tunnel, so it's@@ -111,6 +121,8 @@ def classify_postgres_cdc_error(exc: BaseException) -> CDCErrorCategory | None:return CDCErrorCategory.SSL_REQUIREDif any(marker in message for marker in _HOST_UNREACHABLE_MARKERS):return CDCErrorCategory.HOST_UNREACHABLE+ if _QUOTA_EXCEEDED_MARKER in message:+ return CDCErrorCategory.QUOTA_EXCEEDEDreturn CDCErrorCategory.CONNECTION_FAILEDreturn Nonediff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/cdc/tests/test_errors.py b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/cdc/tests/test_errors.pyindex 52cec67e0c1e..99e86f8a86e0 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/cdc/tests/test_errors.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/cdc/tests/test_errors.py@@ -44,6 +44,19 @@ class TestClassifyPostgresCDCError:psycopg.OperationalError("connection to server at localhost, port 5432 failed: Connection refused"),CDCErrorCategory.CONNECTION_FAILED,),+ (+ # Observed on a managed provider (Neon-style): the account or project exceeded a+ # usage quota, so the connection is blocked until the customer upgrades or the+ # quota resets. Must classify as QUOTA_EXCEEDED, not the generic CONNECTION_FAILED,+ # so it stops retrying instead of looping into the same wall.+ "account_quota_exceeded_is_non_retryable",+ psycopg.OperationalError(+ 'connection failed: connection to server at "203.0.113.1", port 5432 failed: '+ "ERROR: Your account or project has exceeded the quota. Upgrade your plan to "+ "increase limits."+ ),+ CDCErrorCategory.QUOTA_EXCEEDED,+ ),("network_unreachable_is_non_retryable_host",psycopg.OperationalError(