litellm/tests/unit/redis/stores
izzybn 9513084d92
fix(rate-limit): open the rate-limit window when a token charge finds none (#54401)
* fix(rate-limit): open the rate-limit window when a token charge finds none

* fix(rate-limit): settle failed calls and refunds through the window-opening charge

A failed call settled after its window ended wrote its tokens with no window, and so did the plain parts of reservation settlements and batch refunds, so the next call reset them. They now go through the same charge as successes, which opens a missing window

Without Redis, a window opened by a charge now starts both counters at 0 for the charge's TTL, as the Redis script does, instead of keeping a leftover counter's earlier deadline

* test(rate-limit): re-record golden values for failed calls settling through the token charge

With Redis up, a failed call's charge now goes through the token increment
script, which writes Redis only, as successes already do. The in-memory copy
of the token counter no longer takes that charge, and the recorded Redis call
label changes to token_increment_script. Redis values and admission
decisions are unchanged.

* fix(rate-limit): fall back only for the slot group whose token script failed

When one slot group's token script failed, the fallback re-sent every
operation as plain increments and stopped, so groups that had already
been charged were charged again and later groups never got the script.
Failed calls, refunds and settlements now go through this path, so the
fallback now covers only the failed group's keys and keeps going.

Also replaces the seeding loops in the token charge tests with helpers

* fix(rate-limit): keep 10,000 limiter memory entries so window-opening charges do not evict live limits

A charge that opens a window writes three memory entries per scope instead
of one. With the default 200-entry memory, a proxy without Redis could evict
a live limit window once about 66 other keys were charged in the same
minute, so a key over its tpm_limit got through again

* test(rate-limit): mark the memory eviction test with rstest

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-11-25 16:54:50 +00:00
..
__init__.py
auth_cache_double.py perf(proxy): read only the needed team fields from the auth cache (#53909) 2026-11-23 12:53:14 -08:00
cache_invalidation_double.py refactor(auth_cache_invalidation): move the invalidation channel to the native client (#51135) 2026-11-21 18:58:27 +09:00
fake_rate_limits.py fix(rate-limit): open the rate-limit window when a token charge finds none (#54401) 2026-11-25 16:54:50 +00:00
router_session_pins_memory.py feat(redis): serve the router's session pins from a native store (#50870) 2026-11-13 03:22:28 +00:00
router_usage_double.py refactor(redis): delete the Python RedisBatch now that every request op is native (#51383) 2026-11-13 03:22:28 +00:00
spend_counters_double.py fix(proxy): write a cold spend counter's cached spend once (#52806) 2026-11-24 13:00:34 -08:00
test_active_teams.py feat(redis): serve the dynamic rate limiter's active teams from a native store (#52995) 2026-11-20 10:58:19 +09:00
test_auth_cache.py refactor(auth_cache): type auth cache keys and keep the cache always native (#51130) 2026-11-21 17:20:30 +09:00
test_auth_cache_key.py refactor(auth-store): shape the cached virtual key in Rust and load it through one Python path (#53325) 2026-11-21 22:06:13 +09:00
test_cache_invalidation.py fix(rust_bridge): send warnings from unscoped native threads to the proxy log (#53539) 2026-11-23 17:53:52 +09:00
test_connection.py fix(redis): share one native circuit breaker between RedisCache and the Rust stores (#50473) 2026-11-07 17:50:06 +09:00
test_deployment_health.py feat(redis): serve the health checks' deployment states from a native store (#50357) 2026-11-13 03:22:28 +00:00
test_rate_limits.py refactor(redis): delete the Python RedisBatch now that every request op is native (#51383) 2026-11-13 03:22:28 +00:00
test_router_cooldowns.py refactor(redis): delete the Python RedisBatch now that every request op is native (#51383) 2026-11-13 03:22:28 +00:00
test_router_session_pins.py feat(redis): serve the router's session pins from a native store (#50870) 2026-11-13 03:22:28 +00:00
test_router_usage.py refactor(redis): move per-request miss, settlement and shutdown-drain tracking from Python into Rust (#51384) 2026-11-20 17:57:37 +09:00
test_spend_counters.py feat(proxy): add app groups with shared budgets and usage (#53232) 2026-11-21 12:50:58 -08:00