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(klaviyo): stop logging self-recovering connection errors as bugs (#129402)

Tom Owers29b7005c0afe
diff --git a/products/warehouse_sources/sources/klaviyo/source.py b/products/warehouse_sources/sources/klaviyo/source.py
index da3e326b2501..4963c7ebd361 100644
--- a/products/warehouse_sources/sources/klaviyo/source.py
+++ b/products/warehouse_sources/sources/klaviyo/source.py
@@ -37,6 +37,20 @@ KLAVIYO_NEWER_VERSION_REQUIRED = (
"Needs a newer Klaviyo API version than your source uses. Contact PostHog support to upgrade the source."
)
+# `_fetch_page` (klaviyo.py) already retries a read timeout, a dropped connection, or a mid-stream
+# truncation via tenacity; requests/urllib3 report all three in this wording, with Klaviyo's fixed
+# API host rather than anything the customer configured. A failure that outlives that retry budget
+# still gets a full Temporal retry of the activity, so it must stay retryable.
+KLAVIYO_TRANSIENT_CONNECTION_MARKERS = (
+ "HTTPSConnectionPool(host='a.klaviyo.com'",
+ "Connection broken:",
+)
+
+KLAVIYO_TRANSIENT_CONNECTION_MESSAGE = (
+ "Klaviyo's API was slow to respond, so this sync run did not finish. This usually clears on "
+ "its own and the next sync runs on schedule."
+)
+
@SourceRegistry.register
class KlaviyoSource(ResumableSource[KlaviyoSourceConfig, KlaviyoResumeConfig]):
@@ -182,6 +196,12 @@ The campaign and flow performance tables (campaign_values_reports, flow_values_r
"requires Klaviyo API version": "This table needs a newer Klaviyo API version than your source uses. Contact PostHog support to upgrade the source, then re-enable this table.",
}
+ def get_retryable_errors(self) -> set[str]:
+ return set(KLAVIYO_TRANSIENT_CONNECTION_MARKERS)
+
+ def get_retry_exhausted_errors(self) -> dict[str, str]:
+ return dict.fromkeys(KLAVIYO_TRANSIENT_CONNECTION_MARKERS, KLAVIYO_TRANSIENT_CONNECTION_MESSAGE)
+
def get_schemas(
self,
config: KlaviyoSourceConfig,
diff --git a/products/warehouse_sources/sources/klaviyo/test_klaviyo.py b/products/warehouse_sources/sources/klaviyo/test_klaviyo.py
index 11fe289217f0..1d012b5b913f 100644
--- a/products/warehouse_sources/sources/klaviyo/test_klaviyo.py
+++ b/products/warehouse_sources/sources/klaviyo/test_klaviyo.py
@@ -195,6 +195,40 @@ class TestNonRetryableErrors:
assert expected_snippet in matches[0]
+class TestTransientConnectionErrorsStayRetryable:
+ @parameterized.expand(
+ [
+ (
+ "read_timeout",
+ "HTTPSConnectionPool(host='a.klaviyo.com', port=443): Read timed out. (read timeout=60.0)",
+ ),
+ (
+ "connection_error",
+ "HTTPSConnectionPool(host='a.klaviyo.com', port=443): Max retries exceeded with url: /api/events",
+ ),
+ (
+ "chunked_encoding",
+ "Connection broken: InvalidChunkLength(got length b'', 0 bytes read)",
+ ),
+ ]
+ )
+ def test_exhausted_connection_failure_keeps_retrying_with_a_friendly_message(
+ self, _name: str, observed_error: str
+ ) -> None:
+ # These are the exact exception strings `_fetch_page`'s tenacity retry already exhausts on
+ # (see TestFetchPageRetries below). They must never reach get_non_retryable_errors and
+ # disable the schema - a single slow Klaviyo response must not pause syncing for good - and
+ # once Temporal's own retries are also exhausted the stored message must stay friendly
+ # rather than the raw urllib3 text.
+ source = KlaviyoSource()
+ assert not error_message_matches(observed_error, source.get_non_retryable_errors().keys())
+ assert error_message_matches(observed_error, source.get_retryable_errors())
+ messages = [
+ message for pattern, message in source.get_retry_exhausted_errors().items() if pattern in observed_error
+ ]
+ assert messages and "clears on its own" in messages[0]
+
+
class TestFetchPageRetries:
@parameterized.expand(
[