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(langsmith): stop retrying on oversized API page response (#90874)

Tom Owersa4a7fedc28e3
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/langsmith/langsmith.py b/products/warehouse_sources/backend/temporal/data_imports/sources/langsmith/langsmith.py
index 87b24748192d..d023691d87b6 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/langsmith/langsmith.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/langsmith/langsmith.py
@@ -35,6 +35,10 @@ INSECURE_SCHEME_ERROR = "LangSmith host must use https"
# cursor we've already paged is stuck or hostile; retrying re-hits the same cursor, so fail for good.
REPEATED_CURSOR_ERROR = "LangSmith returned a repeated pagination cursor"
+# Raised (and registered non-retryable) when a page body exceeds MAX_RESPONSE_BYTES. The same page
+# is re-requested on every retry, so the cap is hit again deterministically — stop immediately.
+RESPONSE_TOO_LARGE_ERROR = "LangSmith API returned an oversized response"
+
# Cap the decoded body of any single LangSmith response. `host` is user-controlled, so a hostile
# server could otherwise stream an unbounded body and exhaust a shared import worker's memory. Set
# well above any realistic page (runs pages carry full LLM inputs/outputs) so it only trips on a
@@ -113,7 +117,7 @@ def _read_capped_body(response: requests.Response, cap: int = MAX_RESPONSE_BYTES
for chunk in response.iter_content(chunk_size=READ_CHUNK_BYTES):
buffer.extend(chunk)
if len(buffer) > cap:
- raise LangSmithResponseTooLargeError(f"LangSmith API returned an oversized response (> {cap} bytes)")
+ raise LangSmithResponseTooLargeError(f"{RESPONSE_TOO_LARGE_ERROR} (> {cap} bytes)")
return bytes(buffer)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/langsmith/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/langsmith/source.py
index 8971dcc91b9a..b9e48d612de0 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/langsmith/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/langsmith/source.py
@@ -23,6 +23,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.generated_
from products.warehouse_sources.backend.temporal.data_imports.sources.langsmith.langsmith import (
DEFAULT_BASE_URL,
REPEATED_CURSOR_ERROR,
+ RESPONSE_TOO_LARGE_ERROR,
LangSmithResumeConfig,
langsmith_source,
normalize_base_url,
@@ -100,6 +101,7 @@ Leave the **Host** field blank for the US cloud (`api.smith.langchain.com`). Set
"401 Client Error": "Your LangSmith API key is invalid or has been revoked. Create a new API key in your LangSmith settings, then reconnect.",
"403 Client Error": "Your LangSmith API key does not have access to this workspace. Check the key's workspace scope, then reconnect.",
REPEATED_CURSOR_ERROR: "LangSmith kept returning the same pagination cursor, so the import was stopped to avoid looping. This usually means the host is misconfigured — check the Host field, then reconnect.",
+ RESPONSE_TOO_LARGE_ERROR: "A page of runs data from the LangSmith API exceeded 256 MB. This usually means individual traces contain very large inputs or outputs. Contact PostHog support for next steps.",
}
def get_schemas(
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/langsmith/tests/test_langsmith_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/langsmith/tests/test_langsmith_source.py
index 45701c33a096..3d9d47924cc1 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/langsmith/tests/test_langsmith_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/langsmith/tests/test_langsmith_source.py
@@ -6,6 +6,9 @@ from posthog.schema import SourceFieldInputConfig, SourceFieldInputConfigType
from products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs.langsmith import (
LangSmithSourceConfig,
)
+from products.warehouse_sources.backend.temporal.data_imports.sources.langsmith.langsmith import (
+ RESPONSE_TOO_LARGE_ERROR,
+)
from products.warehouse_sources.backend.temporal.data_imports.sources.langsmith.source import LangSmithSource
@@ -103,6 +106,12 @@ class TestLangSmithSource:
# A stale watermark must not leak into a full-refresh run.
assert kwargs["db_incremental_field_last_value"] is None
+ def test_oversized_response_is_non_retryable(self):
+ # Retrying an oversized page re-requests the same data and hits the same cap every time,
+ # so the error must be registered as non-retryable to stop immediately.
+ non_retryable = self.source.get_non_retryable_errors()
+ assert any(RESPONSE_TOO_LARGE_ERROR in key for key in non_retryable)
+
def test_documented_tables_render_from_static_catalog(self):
# lists_tables_without_credentials must expose the table catalog (+ canonical descriptions)
# for the public docs <SourceTables /> component without needing credentials.