: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(warehouse-sources): keep exhausted langsmith retries out of error tracking (#98077)
posthog[bot]29bf60f18a3f
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.pyindex eb235c7804fe..0872d82d670f 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@@ -31,6 +31,10 @@ HOST_NOT_ALLOWED_ERROR = "LangSmith host is not allowed"# Returned when a cloud connection would send the API key over plaintext HTTP.INSECURE_SCHEME_ERROR = "LangSmith host must use https"+# Raised (and registered retryable) when the API answers 429 or 5xx. `_fetch_page` retries it+# inline; once that budget exhausts, Temporal retries the activity from the saved checkpoint.+RETRYABLE_API_ERROR = "LangSmith API error (retryable)"+# Raised (and registered non-retryable) when the host loops the runs cursor. A host that returns a# 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"@@ -339,7 +343,7 @@ def _fetch_page(# 429 and transient 5xx are retryable (runs/query rate limits are tight: 10 req/10s on# windows up to 7 days, 3 req/10s beyond); auth/permission errors below are not.if response.status_code == 429 or response.status_code >= 500:- raise LangSmithRetryableError(f"LangSmith API error (retryable): status={response.status_code}, url={url}")+ raise LangSmithRetryableError(f"{RETRYABLE_API_ERROR}: status={response.status_code}, url={url}")# Redirects are disabled as an SSRF boundary; a 3xx means the host tried to bounce the# authenticated request elsewhere, so fail instead of parsing (or following) it.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.pyindex 2cd158ab5eec..6c79a95c220c 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@@ -24,6 +24,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.langsmith.DEFAULT_BASE_URL,REPEATED_CURSOR_ERROR,RESPONSE_TOO_LARGE_ERROR,+ RETRYABLE_API_ERROR,RUNS_PAGE_TOO_LARGE_ERROR,LangSmithResumeConfig,langsmith_source,@@ -111,6 +112,27 @@ Leave the **Host** field blank for the US cloud (`api.smith.langchain.com`). SetRUNS_PAGE_TOO_LARGE_ERROR: "A single LangSmith trace was too large to import, so the runs sync stopped. This usually means one trace has an unusually large input or output. Contact support so we can help unblock the sync.",}+ def get_retryable_errors(self) -> set[str]:+ # `_fetch_page` already retries a 429/5xx (the RETRYABLE_API_ERROR sentinel), a dropped+ # connection, and a read timeout up to 5 attempts. Once that budget exhausts, 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 LangSmith),+ # so match only the stable, host-independent parts of the message.+ return {+ RETRYABLE_API_ERROR,+ # A read timeout, plus the wrapper urllib3 puts around one it retried itself, which+ # leaves the timeout nested inside as the cause.+ "Read timed out",+ "Max retries exceeded with url",+ # A dropped connection arrives without that wrapper in both places it can happen. The+ # shared retry policy retries GET/HEAD/OPTIONS only, so urllib3 re-raises the drop bare+ # on the runs/query POST and requests reports "Connection aborted". A drop after the+ # headers, while `_read_capped_body` streams the body, is past the retry path already+ # and reports "Connection broken".+ "Connection aborted",+ "Connection broken",+ }+def get_schemas(self,config: LangSmithSourceConfig,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.pyindex de6979330c60..9a3de93212aa 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@@ -8,6 +8,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.generated_)from products.warehouse_sources.backend.temporal.data_imports.sources.langsmith.langsmith import (RESPONSE_TOO_LARGE_ERROR,+ RETRYABLE_API_ERROR,)from products.warehouse_sources.backend.temporal.data_imports.sources.langsmith.source import LangSmithSource@@ -120,6 +121,27 @@ class TestLangSmithSource:assert message is not Noneassert "Host field" in message+ @pytest.mark.parametrize(+ "observed_error",+ [+ "HTTPSConnectionPool(host='api.smith.langchain.com', port=443): Max retries exceeded with "+ 'url: /api/v1/runs/query (Caused by ReadTimeoutError("HTTPSConnectionPool('+ "host='api.smith.langchain.com', port=443): Read timed out. (read timeout=60)\"))",+ f"{RETRYABLE_API_ERROR}: status=429, url=https://api.smith.langchain.com/api/v1/runs/query",+ "('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))",+ '("Connection broken: IncompleteRead(1048576 bytes read, 4194304 more expected)", '+ "IncompleteRead(1048576 bytes read, 4194304 more expected))",+ ],+ )+ def test_exhausted_inline_retries_are_classified_retryable(self, observed_error):+ # `_fetch_page` retries a read timeout, a 429/5xx, and a dropped connection itself, and+ # Temporal then retries the activity from the saved pagination checkpoint. The failure is+ # self-recovering, so it must match here to be logged at warning instead of reaching error+ # tracking. The last two cases carry no urllib3 wrapper: the shared retry policy skips the+ # runs/query POST, and a drop while `_read_capped_body` streams the body happens after the+ # headers arrive.+ assert any(pattern in observed_error for pattern in self.source.get_retryable_errors())+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.