From 996810d560cb900c54c7ecfbb383009cf1194a9d Mon Sep 17 00:00:00 2001 From: Matt Van Horn Date: Tue, 10 Mar 2026 01:06:02 -0700 Subject: [PATCH 1/2] fix(client): narrow retry exception handling to transport errors The retry loop previously caught `Exception`, which inadvertently intercepted application-level exceptions like Celery's `SoftTimeLimitExceeded`. Narrow the catch to `httpx.TransportError` and `OSError`, which covers all network/transport failures while allowing non-network exceptions to propagate immediately. Fixes #2737 Co-Authored-By: Claude Opus 4.6 --- src/openai/_base_client.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/openai/_base_client.py b/src/openai/_base_client.py index cf4571bf45..82e1b06ab8 100644 --- a/src/openai/_base_client.py +++ b/src/openai/_base_client.py @@ -1021,8 +1021,8 @@ def request( log.debug("Raising timeout error") raise APITimeoutError(request=request) from err - except Exception as err: - log.debug("Encountered Exception", exc_info=True) + except (httpx.TransportError, OSError) as err: + log.debug("Encountered transport error", exc_info=True) if remaining_retries > 0: self._sleep_for_retry( @@ -1620,8 +1620,8 @@ async def request( log.debug("Raising timeout error") raise APITimeoutError(request=request) from err - except Exception as err: - log.debug("Encountered Exception", exc_info=True) + except (httpx.TransportError, OSError) as err: + log.debug("Encountered transport error", exc_info=True) if remaining_retries > 0: await self._sleep_for_retry( From c90c5cd4eb65149cba74c3bc002dbb75ad446c4b Mon Sep 17 00:00:00 2001 From: Matt Van Horn Date: Tue, 10 Mar 2026 08:06:43 -0700 Subject: [PATCH 2/2] Widen retry handler to httpx.RequestError to catch all request-phase errors httpx.TransportError missed TooManyRedirects and DecodingError which are also httpx.RequestError subclasses. Using RequestError catches all request-phase failures while still excluding unrelated exceptions. Co-Authored-By: Claude Opus 4.6 --- src/openai/_base_client.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/openai/_base_client.py b/src/openai/_base_client.py index 82e1b06ab8..92ed7f56b8 100644 --- a/src/openai/_base_client.py +++ b/src/openai/_base_client.py @@ -1021,8 +1021,8 @@ def request( log.debug("Raising timeout error") raise APITimeoutError(request=request) from err - except (httpx.TransportError, OSError) as err: - log.debug("Encountered transport error", exc_info=True) + except (httpx.RequestError, OSError) as err: + log.debug("Encountered request error", exc_info=True) if remaining_retries > 0: self._sleep_for_retry( @@ -1620,8 +1620,8 @@ async def request( log.debug("Raising timeout error") raise APITimeoutError(request=request) from err - except (httpx.TransportError, OSError) as err: - log.debug("Encountered transport error", exc_info=True) + except (httpx.RequestError, OSError) as err: + log.debug("Encountered request error", exc_info=True) if remaining_retries > 0: await self._sleep_for_retry(