From fe81b84b31a18f98d9177d9c15cbb7ccfcf0b956 Mon Sep 17 00:00:00 2001 From: jesus Date: Mon, 7 Sep 2026 09:59:35 +0000 Subject: [PATCH] fix(http_handler): avoid recursive streamed error unwrapping Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- litellm/llms/custom_httpx/llm_http_handler.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/litellm/llms/custom_httpx/llm_http_handler.py b/litellm/llms/custom_httpx/llm_http_handler.py index f84d4d7c85f..df82ed52359 100644 --- a/litellm/llms/custom_httpx/llm_http_handler.py +++ b/litellm/llms/custom_httpx/llm_http_handler.py @@ -311,16 +311,15 @@ def _collect_ws_project_quota_callbacks() -> tuple[ProjectQuotaCallback, ...]: ) -def _find_base_llm_exception(error: BaseException, depth: int = 0) -> BaseLLMException | None: - if depth >= 10: - return None - if isinstance(error, BaseLLMException): - return error - - cause: Final = error.__cause__ - if cause is None: - return None - return _find_base_llm_exception(cause, depth + 1) +def _find_base_llm_exception(error: BaseException) -> BaseLLMException | None: + current: BaseException | None = error + for _ in range(10): + if current is None: + return None + if isinstance(current, BaseLLMException): + return current + current = current.__cause__ # rebind-ok: traverse the bounded exception cause chain + return None class BaseLLMHTTPHandler: