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): retry Langfuse resource-limit 422s as transient (#72022)

Tom Owers10bcce200c75
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/langfuse/langfuse.py b/products/warehouse_sources/backend/temporal/data_imports/sources/langfuse/langfuse.py
index 92f2f70681ab..ffa74555fc8e 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/langfuse/langfuse.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/langfuse/langfuse.py
@@ -328,7 +328,11 @@ def get_rows(
url, params=params, auth=auth, timeout=REQUEST_TIMEOUT_SECONDS, allow_redirects=False, stream=True
)
- if response.status_code == 429 or response.status_code >= 500:
+ # Langfuse maps a ClickHouse resource limit (memory/timeout) to 422 with an "Request timed
+ # out" body; genuine request-validation failures come back as 400. Deep offset pagination on
+ # the traces endpoint can trip that resource limit, so 422 is a transient upstream error —
+ # retry it through the backoff/resume machinery rather than crashing the sync.
+ if response.status_code in (422, 429) or response.status_code >= 500:
retry_after = _parse_retry_after(response) if response.status_code == 429 else None
raise LangfuseRetryableError(
f"Langfuse API error (retryable): status={response.status_code}, endpoint={endpoint}",
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/langfuse/tests/test_langfuse.py b/products/warehouse_sources/backend/temporal/data_imports/sources/langfuse/tests/test_langfuse.py
index 2e2097ece75c..0a60387b248a 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/langfuse/tests/test_langfuse.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/langfuse/tests/test_langfuse.py
@@ -470,6 +470,22 @@ class TestGetRows:
# Only the first page's (legitimate) continuation was saved.
assert manager.save_state.call_count == 1
+ def test_resource_limit_422_is_retried_then_recovers(self):
+ # Langfuse maps a transient ClickHouse resource/timeout to 422 (validation errors are 400).
+ # A 422 must flow through the backoff and recover, not surface as a fatal HTTPError that
+ # fails the sync. Patch the wait so the retry doesn't sleep.
+ manager = self._manager()
+ with mock.patch.object(langfuse_module, "_retry_wait", return_value=0):
+ rows, session = self._run(
+ manager,
+ [
+ _response(status_code=422, json_data={"error": "Request timed out"}),
+ _page([{"id": "t1"}], page=1, total_pages=1),
+ ],
+ )
+ assert [r["id"] for r in rows] == ["t1"]
+ assert session.get.call_count == 2
+
def test_page_limit_raises_after_checkpointing_next_page(self):
# A hostile host reporting ever-more totalPages would otherwise keep the loop alive until
# the activity timeout. The run must abort at the cap — retryably, with the next page