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>
This commit is contained in:
yassin 2026-09-08 21:54:57 +00:00
parent e654a7962a
commit 2c302d252c

View file

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