mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-07 02:59:05 +00:00
fix(proxy): stay within the ruff strict-rule BLE001 budget
The reset-race fix's new except Exception blocks pushed BLE001 4 over ruff-strict-budget.json's limit. Each catches a Redis or reconcile failure of unknown type by design, matching the noqa pattern this file already uses on the equivalent non-cancel release path, so suppress rather than narrow.
This commit is contained in:
parent
b25920d9c9
commit
9f546fdb89
2 changed files with 6 additions and 6 deletions
|
|
@ -565,7 +565,7 @@ class ResetBudgetJob:
|
|||
)
|
||||
try:
|
||||
await redis_cache.async_delete_cache(key=counter_key)
|
||||
except Exception as delete_err:
|
||||
except Exception as delete_err: # noqa: BLE001 # any Redis failure here leaves the pre-reset value stuck; log and move on
|
||||
verbose_proxy_logger.error(
|
||||
"Failed to delete spend counter %s in Redis after its reset also failed; the "
|
||||
"pre-reset value stays authoritative until its TTL expires: %s",
|
||||
|
|
@ -582,7 +582,7 @@ class ResetBudgetJob:
|
|||
try:
|
||||
current = await redis_cache.async_get_cache(key=counter_key)
|
||||
return float(current) if current is not None else 0.0
|
||||
except Exception as redis_err:
|
||||
except Exception as redis_err: # noqa: BLE001 # any Redis failure here means no safe baseline; fall back to delete
|
||||
verbose_proxy_logger.warning(
|
||||
"Failed to read spend counter %s in Redis before reset; skipping the delta-preserving "
|
||||
"reset and falling back to delete: %s",
|
||||
|
|
@ -606,7 +606,7 @@ class ResetBudgetJob:
|
|||
key=counter_key, new_base=new_spend, snapshot=snapshot, ttl=60
|
||||
)
|
||||
return True
|
||||
except Exception as redis_err:
|
||||
except Exception as redis_err: # noqa: BLE001 # any Redis failure here is worth a retry, not just specific ones
|
||||
is_last_attempt = attempt == RESET_BUDGET_SPEND_COUNTER_RESET_MAX_ATTEMPTS - 1
|
||||
verbose_proxy_logger.warning(
|
||||
"Attempt %d/%d to reset spend counter %s in Redis failed: %s",
|
||||
|
|
|
|||
|
|
@ -379,7 +379,7 @@ async def release_budget_reservation_on_cancel(
|
|||
)
|
||||
except asyncio.CancelledError:
|
||||
pass # a second cancellation while shielded; the reconcile keeps running detached regardless
|
||||
except Exception:
|
||||
except Exception: # noqa: BLE001 # a reconcile failure must not pin the counter; retry, then drop it directly
|
||||
verbose_proxy_logger.exception(
|
||||
"Failed to reconcile budget reservation on cancel; retrying before invalidating reserved counters"
|
||||
)
|
||||
|
|
@ -389,7 +389,7 @@ async def release_budget_reservation_on_cancel(
|
|||
return
|
||||
try:
|
||||
await invalidate_budget_reservation_counters(budget_reservation=budget_reservation)
|
||||
except Exception:
|
||||
except Exception: # noqa: BLE001 # nothing left to try; the finalized stamp below keeps it from being reprocessed
|
||||
verbose_proxy_logger.exception(
|
||||
"Failed to invalidate budget reservation counters after cancel-path reconcile failed"
|
||||
)
|
||||
|
|
@ -408,7 +408,7 @@ async def _retry_reconcile_reservation_on_cancel(
|
|||
try:
|
||||
await reconcile_budget_reservation(budget_reservation=budget_reservation, actual_cost=incurred_cost)
|
||||
return True
|
||||
except Exception:
|
||||
except Exception: # noqa: BLE001 # any reconcile failure is worth a retry here, not just specific ones
|
||||
is_last_attempt = attempt == _RELEASE_ON_CANCEL_RECONCILE_MAX_ATTEMPTS - 1
|
||||
verbose_proxy_logger.warning(
|
||||
"Retry %d/%d to reconcile budget reservation on cancel failed",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue