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 <noreply@anthropic.com>
This commit is contained in:
Krrish Dholakia 2026-05-13 14:12:11 -07:00
parent 494f426a5f
commit 5c1e3ff245
2 changed files with 9 additions and 3 deletions

View file

@ -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

View file

@ -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,