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(openrouter): retry 408 request timeouts instead of failing the sync (#79549)

Tom Owers17df29cdd289
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/openrouter/openrouter.py b/products/warehouse_sources/backend/temporal/data_imports/sources/openrouter/openrouter.py
index 67ac16fa1535..89f83e600826 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/openrouter/openrouter.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/openrouter/openrouter.py
@@ -61,7 +61,9 @@ def _build_url(path: str, params: Optional[dict[str, Any]] = None) -> str:
def _fetch(session: requests.Session, url: str, headers: dict[str, str], logger: FilteringBoundLogger) -> dict:
response = session.get(url, headers=headers, timeout=REQUEST_TIMEOUT)
- if response.status_code == 429 or response.status_code >= 500:
+ # 408 is a transient request timeout on OpenRouter's side; retry it like 429/5xx rather than
+ # letting it raise_for_status() into a fatal, non-retried HTTPError.
+ if response.status_code in (408, 429) or response.status_code >= 500:
raise OpenRouterRetryableError(f"OpenRouter API error (retryable): status={response.status_code}, url={url}")
if not response.ok:
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/openrouter/tests/test_openrouter.py b/products/warehouse_sources/backend/temporal/data_imports/sources/openrouter/tests/test_openrouter.py
index 30631c744a00..cf7eafb0d36f 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/openrouter/tests/test_openrouter.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/openrouter/tests/test_openrouter.py
@@ -47,7 +47,7 @@ class TestFetch:
with mock.patch.object(openrouter._fetch.retry, "wait", return_value=0): # type: ignore[attr-defined]
yield
- @pytest.mark.parametrize("status_code", [429, 500, 502, 503])
+ @pytest.mark.parametrize("status_code", [408, 429, 500, 502, 503])
def test_retries_then_succeeds_on_transient_status(self, status_code):
session = mock.Mock()
session.get.side_effect = [_response(status_code), _response(200, {"data": []})]