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(langfuse): retry an interrupted chunked transfer (#127954)

Tom Owersdff8b91a1268
diff --git a/products/warehouse_sources/sources/langfuse/langfuse.py b/products/warehouse_sources/sources/langfuse/langfuse.py
index e3f4b5d3249e..a5409700e2a1 100644
--- a/products/warehouse_sources/sources/langfuse/langfuse.py
+++ b/products/warehouse_sources/sources/langfuse/langfuse.py
@@ -427,7 +427,14 @@ def get_rows(
session = make_tracked_session(retry=Retry(total=0))
@retry_with_deadline(
- retry=retry_if_exception_type((LangfuseRetryableError, requests.ReadTimeout, requests.ConnectionError)),
+ retry=retry_if_exception_type(
+ (
+ LangfuseRetryableError,
+ requests.ReadTimeout,
+ requests.ConnectionError,
+ requests.exceptions.ChunkedEncodingError,
+ )
+ ),
stop=stop_after_attempt(MAX_RETRIES),
wait=_retry_wait,
reraise=True,
diff --git a/products/warehouse_sources/sources/langfuse/source.py b/products/warehouse_sources/sources/langfuse/source.py
index f2a685e0bff3..702a0c07bc22 100644
--- a/products/warehouse_sources/sources/langfuse/source.py
+++ b/products/warehouse_sources/sources/langfuse/source.py
@@ -190,16 +190,17 @@ Find your project API keys in your Langfuse **Project settings > API Keys**. Set
def get_retryable_errors(self) -> set[str]:
# `get_rows`'s tenacity retry already retries a 429/422/5xx (the "Langfuse API error
- # (retryable)" sentinel), a dropped connection, and a read timeout up to MAX_RETRIES. Once
- # that budget exhausts, urllib3 wraps the failure as "Max retries exceeded with url" (with
- # the read timeout nested inside as its cause), and Temporal retries the whole activity from
- # the saved pagination checkpoint, so the failure is transient and self-recovering. The host
- # is customer-controlled (self-hosted Langfuse), so match only the stable, host-independent
- # parts of the message.
+ # (retryable)" sentinel), a dropped connection, a read timeout, and an interrupted chunked
+ # transfer up to MAX_RETRIES. Once that budget exhausts, urllib3 wraps the failure as "Max
+ # retries exceeded with url" (with the read timeout nested inside as its cause), and Temporal
+ # retries the whole activity from the saved pagination checkpoint, so the failure is
+ # transient and self-recovering. The host is customer-controlled (self-hosted Langfuse), so
+ # match only the stable, host-independent parts of the message.
return {
"Langfuse API error (retryable)",
"Read timed out",
"Max retries exceeded with url",
+ "Connection broken",
}
def get_schemas(
diff --git a/products/warehouse_sources/sources/langfuse/tests/test_langfuse.py b/products/warehouse_sources/sources/langfuse/tests/test_langfuse.py
index 20c998f39415..863c05c3ba66 100644
--- a/products/warehouse_sources/sources/langfuse/tests/test_langfuse.py
+++ b/products/warehouse_sources/sources/langfuse/tests/test_langfuse.py
@@ -4,6 +4,8 @@ from typing import Any, Optional
import pytest
from unittest import mock
+import requests
+
from products.warehouse_sources.sources.langfuse import langfuse as langfuse_module
from products.warehouse_sources.sources.langfuse._config import LangfuseSourceConfig
from products.warehouse_sources.sources.langfuse.langfuse import (
@@ -337,6 +339,23 @@ class TestGetRows:
assert len(result.requests) == 2
assert result.raised is None
+ def test_chunked_encoding_error_during_body_read_is_retried_then_recovers(self):
+ # An interrupted chunked transfer raises requests.ChunkedEncodingError, not ConnectionError
+ # or ReadTimeout, so it must be in the fetch_page retry's exception tuple too or a single
+ # dropped connection fails the whole sync instead of retrying the page.
+ result = _driver().run(
+ "traces",
+ [
+ requests.exceptions.ChunkedEncodingError(
+ "Connection broken: IncompleteRead(20474 bytes read, 12278 more expected)"
+ ),
+ _page([{"id": "t1"}], page=1, total_pages=1),
+ ],
+ api_version="v1",
+ )
+ assert [r["id"] for r in result.rows] == ["t1"]
+ assert result.raised is None
+
def test_keyset_checkpoint_carries_the_advanced_filter(self):
# Resume reuses the saved from_value verbatim, so a checkpoint that kept the ORIGINAL bound
# next to page 1 would restart the whole walk on the next activity attempt.
diff --git a/products/warehouse_sources/sources/langfuse/tests/test_langfuse_source.py b/products/warehouse_sources/sources/langfuse/tests/test_langfuse_source.py
index d35b380ce2e7..2ea470360f4a 100644
--- a/products/warehouse_sources/sources/langfuse/tests/test_langfuse_source.py
+++ b/products/warehouse_sources/sources/langfuse/tests/test_langfuse_source.py
@@ -45,6 +45,13 @@ class TestLangfuseSource:
)
assert any(pattern in observed_error for pattern in self.source.get_retryable_errors())
+ def test_exhausted_chunked_transfer_error_is_classified_retryable(self):
+ # Matches the message requests raises when a chunked body breaks mid-transfer and
+ # get_rows's tenacity retry exhausts its budget — keeps this transient, self-recovering
+ # failure out of error tracking instead of reaching `logger.aexception`.
+ observed_error = "Connection broken: IncompleteRead(20474 bytes read, 12278 more expected)"
+ assert any(pattern in observed_error for pattern in self.source.get_retryable_errors())
+
@pytest.mark.parametrize(
"api_version, expected",
[