litellm/tests/unit/redis
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
..
stores fix(rate-limit): open the rate-limit window when a token charge finds none (#54401) 2026-11-25 16:54:50 +00:00
__init__.py feat(redis): extend the native Redis foundation for the store families (#50169) 2026-11-06 12:30:07 +09:00