From 5c1e3ff2456e189aa02b2239c772b95b0c257d92 Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Wed, 13 May 2026 14:12:11 -0700 Subject: [PATCH] address greptile review feedback (greploop iteration 1) - Fix eager asyncio.Lock() allocation in _get_async_refresh_lock by using get() + conditional set instead of setdefault (avoids discarded Lock per call) - Add warning log when pages_processed is None in ocr_cost to surface potentially malformed OCR responses instead of silently returning 0 Co-Authored-By: Claude Opus 4.6 --- litellm/cost_calculator.py | 4 ++++ litellm/llms/vertex_ai/vertex_llm_base.py | 8 +++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/litellm/cost_calculator.py b/litellm/cost_calculator.py index d9710d0c1a4..b84f1b1356f 100644 --- a/litellm/cost_calculator.py +++ b/litellm/cost_calculator.py @@ -1817,6 +1817,10 @@ def ocr_cost( pages_processed = response.usage_info.pages_processed if pages_processed is None: + verbose_logger.warning( + "ocr_cost: pages_processed is None for model=%s; returning 0 cost", + model, + ) return 0.0, 0.0 ocr_cost_per_page: float = 0.0 diff --git a/litellm/llms/vertex_ai/vertex_llm_base.py b/litellm/llms/vertex_ai/vertex_llm_base.py index 787b45df15c..b029e9220f2 100644 --- a/litellm/llms/vertex_ai/vertex_llm_base.py +++ b/litellm/llms/vertex_ai/vertex_llm_base.py @@ -359,9 +359,11 @@ class VertexBase: def _get_async_refresh_lock(self, credential_cache_key: tuple) -> asyncio.Lock: """Get or create an asyncio.Lock for the given credential cache key.""" - return self._async_refresh_locks.setdefault( - credential_cache_key, asyncio.Lock() - ) + lock = self._async_refresh_locks.get(credential_cache_key) + if lock is None: + lock = asyncio.Lock() + self._async_refresh_locks[credential_cache_key] = lock + return lock def _try_get_cached_token( self,