From 2c302d252ce70eb2770ab1eb5e1c33ca5f06f2f3 Mon Sep 17 00:00:00 2001 From: yassin Date: Tue, 8 Sep 2026 21:54:57 +0000 Subject: [PATCH] test(proxy): reseeded reservation counter also carries the settled request cost The reseed test asserted counter == DB floor. The floor is read before the async spend flush writes this request, so the counter now lands at floor plus settled cost, matching the after leg in the PR proof Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- tests/test_litellm/proxy/test_proxy_server.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/test_litellm/proxy/test_proxy_server.py b/tests/test_litellm/proxy/test_proxy_server.py index 6a901c5e7de..54579e6cb7c 100644 --- a/tests/test_litellm/proxy/test_proxy_server.py +++ b/tests/test_litellm/proxy/test_proxy_server.py @@ -8356,8 +8356,8 @@ async def test_increment_spend_counters_reseeds_from_db_on_bad_reserved_counter( """When the reservation reconcile finds the counter in an inconsistent state (here: missing), it must NOT delete the counter and fail open (the old behavior, which left the counter unenforced after a Redis reload). It reseeds - from the authoritative DB so the counter reflects the recorded total and - budget gating continues.""" + from the authoritative DB and adds this request's settled cost, which the + async spend flush has not written yet, so budget gating continues.""" from litellm.caching.dual_cache import DualCache from litellm.proxy.proxy_server import increment_spend_counters from litellm.proxy.db.spend_counter_reseed import SpendCounterReseed @@ -8394,9 +8394,7 @@ async def test_increment_spend_counters_reseeds_from_db_on_bad_reserved_counter( ) assert budget_reservation["finalized"] is True - # counter reseeded to the authoritative DB value, not deleted/left None - # and not double-counted via a direct increment - assert counter_cache.in_memory_cache.get_cache(key="spend:key:key-bad-reserved-counter") == pytest.approx(0.6) + assert counter_cache.in_memory_cache.get_cache(key="spend:key:key-bad-reserved-counter") == pytest.approx(0.85) finally: ps.spend_counter_cache = orig_counter ps.prisma_client = orig_prisma