mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-28 00:00:38 +00:00
* fix(proxy): seed a cold end-user spend counter once from the end-user row A cold spend:end_user counter was seeded by adding the cached end-user spend, so requests that overlapped on the cold counter added it once each and a customer under budget was refused. The write path now seeds it with SET NX under the per-counter lock, from LiteLLM_EndUserTable and never below the cached spend, the way key, team, user, org and project counters seed. Reads of a cold counter are unchanged. Fixes #47062 * fix(proxy): write a cold counter's cached spend with SET NX, drop the row read The cold seed goes back to the cached spend main already used, written with SET NX in place of INCRBYFLOAT, so requests and proxies that overlap on a cold counter write it once. This drops the LiteLLM_EndUserTable read from the first commit: the row could already hold the request's own charge, and the post-call increment would then add it a second time. * fix(proxy): raise a cold counter to the cached spend, never past it The cold seed now uses the store's set_max, the write the stale-counter repair already uses. A charge that creates the counter just before the seed no longer makes the seed skip the cached spend, and two proxies with different cached spends leave the larger one. The new tests read the cached spend through a real UserApiKeyCache. * fix(proxy): seed a cold counter with an increment when Redis refuses the script * test: keep main's import block in the spend counter tests * fix(budgets): raise a cold counter to the cached spend in the rust post-call step The post-call step that main now runs in Rust added the auth cache's spend to a cold counter with INCRBYFLOAT, so requests that overlap on a cold counter with budget reservation off still multiplied it. Raise it with set_max as the Python seed does, and drop this process's copy when a seed fails. * fix(budgets): drop a cold counter everywhere when its seed may have applied A seed whose reply is lost may have written the cached spend to Redis. A failed increment already drops the counter from Redis and memory, and the set_max seed now does the same in the Python and Rust paths. * test(budgets): key the cold seed tests by AuthObject after the main merge * fix(budgets): end the cold seed with the charge's own increment On Redis Cluster a slot mid-migration answers the set_max script through an ASK redirect but refuses the pipelined INCRBYFLOAT that charges the counter. The seed then succeeded, the charge pipeline failed, and every counter in that step was dropped. The seed now ends with INCRBYFLOAT 0, so a counter the charge cannot reach fails in the seed and is dropped on its own, as it was when the seed was that increment. * test(budgets): mark the new charge tests with rstest --------- Co-authored-by: kenneth <kenneth@berri.ai> |
||
|---|---|---|
| .. | ||
| stores | ||
| __init__.py | ||
| store_settings.py | ||