From 3791abf4bbc9153fdfc9d8a3d5cab849cb754393 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 28 Apr 2026 22:54:58 +0000 Subject: [PATCH] fix(passthrough): log when streaming spend-tracking flush fails to schedule Address Greptile feedback: the bare `except Exception: pass` in the finally blocks of _sync_streaming / _async_streaming silently dropped errors from executor.submit() / asyncio.create_task() (e.g. saturated thread pool, closed event loop). Since the entire point of the fix is that spend tracking should not silently lose data, mirror the peer streaming_handler.py logging pattern so any scheduling failure is diagnosable in production. Co-authored-by: Mateo Wang --- litellm/passthrough/main.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/litellm/passthrough/main.py b/litellm/passthrough/main.py index 9b669d1c2c8..c4c9aea6f64 100644 --- a/litellm/passthrough/main.py +++ b/litellm/passthrough/main.py @@ -21,6 +21,7 @@ import httpx from httpx._types import CookieTypes, QueryParamTypes, RequestFiles import litellm +from litellm._logging import verbose_logger from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler, HTTPHandler from litellm.llms.custom_httpx.llm_http_handler import BaseLLMHTTPHandler @@ -405,8 +406,13 @@ def _sync_streaming( raw_bytes=raw_bytes, provider_config=provider_config, ) - except Exception: - pass + except Exception as e: + verbose_logger.exception( + "Failed to schedule passthrough spend-tracking flush " + "in _sync_streaming; %d buffered chunks dropped: %s", + len(raw_bytes), + e, + ) async def _async_streaming( @@ -450,5 +456,10 @@ async def _async_streaming( provider_config=provider_config, ) ) - except Exception: - pass + except Exception as e: + verbose_logger.exception( + "Failed to schedule passthrough spend-tracking flush " + "in _async_streaming; %d buffered chunks dropped: %s", + len(raw_bytes), + e, + )