Repository navigation
fix(proxy): stop serving stale team model allowlist after /team/update - #34266
mateo-berri merged 4 commits into
Conversation
get_team_object consults proxy_logging_obj.internal_usage_cache before user_api_key_cache, but _cache_team_object (the refresh every team mutation goes through) only wrote user_api_key_cache. With enable_redis_auth_cache both caches share one Redis, so any request backfills the internal cache's in-memory tier with the team object and that copy keeps shadowing the freshly written team until its TTL expires. The auth builder then wrote the team object it had just read back into the cache after check 6, clobbering the fresh Redis value with the stale one, which made the staleness self-sustaining under traffic: keys with models=["all-team-models"] kept getting 403 team_model_access_denied for models added via /team/update, and kept access to removed ones. _cache_team_object now deletes the internal usage cache entry before writing the refreshed team, and the auth-time write-back is removed so only authoritative writers (DB reads and team mutations) populate the team cache, mirroring how key objects already handle this (see test_auth_does_not_rewrite_cached_key_object_back_into_cache). The LIT-4000 test pinning the removed write-back is deleted; its concern (team object cached under the canonical key) is handled by _cache_team_object inside get_team_object's DB path and pinned by test_cache_team_object_writes_team_id_and_invalidates_team_alias Resolves LIT-4391
Greptile SummaryThis PR refreshes team authorization data after team updates. The main changes are:
Confidence Score: 5/5This looks safe to merge.
|
| Filename | Overview |
|---|---|
| litellm/proxy/auth/auth_checks.py | Adds ordered, non-blocking invalidation of internal team cache entries before canonical cache refreshes. |
| litellm/proxy/auth/user_api_key_auth.py | Removes request-time persistence of fetched or fallback team objects. |
| tests/test_litellm/proxy/auth/test_auth_checks.py | Adds tests for shared-cache invalidation order and cache failure handling. |
| tests/test_litellm/proxy/auth/test_user_api_key_auth.py | Adds coverage showing that fallback team data is not written into the team cache. |
| tests/test_litellm/proxy/management_endpoints/test_team_endpoints.py | Updates the endpoint test fixture for the new asynchronous invalidation call. |
Reviews (3): Last reviewed commit: "fix(proxy): suppress BLE001 for best-eff..." | Re-trigger Greptile
Greptile review: _cache_team_object runs after a successful DB fetch in get_team_object and after every team mutation's DB write, but DualCache.async_delete_cache propagates backend errors, so a Redis blip during invalidation would turn a healthy team lookup into a 404 and a committed /team/update into a 500. Both the internal usage cache delete and the alias-key invalidation now log a warning and continue on failure, matching how DualCache.async_set_cache already swallows write errors. Worst case on failure is worker-local staleness bounded by the internal cache's in-memory TTL, the same bound other workers already have
|
@greptileai pushed 769f434 making both cache invalidations in _cache_team_object best-effort, please re-review Generated by Claude Code |
The ruff strict gate flagged the two new blind excepts. They are deliberate: the guards exist so that any cache backend failure, not just an enumerable set of Redis errors, leaves the authoritative team write and the mutation response intact
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…itellm_team-model-allowlist-stale-qqg50q
|
Thanks for this fix — we ran into exactly this on the v1.92.x line and it took a while to track down, so sharing the mechanism in case it helps with backport triage. Symptom: a model added to a team through the UI never became callable — Root cause as far as we could tell: Removing that write-back plus invalidating the internal-usage-cache copy — exactly what this PR does — matches what #33565 did for the key object, so this looks like it closes the team half of the same pattern. Two questions, if you don't mind: is a backport to the v1.95.x line planned, or should we expect this in v1.96.0 only? ( Thanks again for the quick turnaround here. cc @yassin-berriai |
TLDR
Problem this solves:
How it solves it:
Relevant issues
Linear ticket
Resolves LIT-4391
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
@greptileaito re-request a review after pushing changes)Delays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Root cause:
get_team_objectreadsproxy_logging_obj.internal_usage_cachebeforeuser_api_key_cache. Withenable_redis_auth_cacheboth caches share one Redis, so ordinary reads backfill the internal cache's in-memory tier with the team object./team/updaterefreshed onlyuser_api_key_cache, so the backfilled copy kept shadowing the update; the auth builder then wrote the team object it had just read back into the cache after check 6, clobbering the fresh Redis value with the stale one. Under traffic this loop is self-sustaining and immune to/cache/flushall, which is exactly what the customer reportedProof below is fully e2e: a live proxy on localhost:4000 backed by Postgres and Redis (
enable_redis_auth_cache: true), withmodel-a/model-bboth mapped to realgemini/gemini-3.6-flashdeployments (real provider calls, real cost), following the reproduction steps from the Linear ticketBefore, captured at commit f1f0a0b (master without the fix):
After, captured at commit 221b185 (this PR):
The revoke direction matters for security: before this fix a model removed from the team stayed callable until the poisoned cache finally decayed
Type
🐛 Bug Fix
Changes
litellm/proxy/auth/auth_checks.py:_cache_team_objectnow deletes the internal usage cache entry forteam_id:{id}before writing the refreshed team touser_api_key_cache. The delete runs before the write because with a shared Redis a delete afterwards would wipe the value that was just written. This mirrors the alias key invalidation that already lived in the same function, and every team mutation endpoint benefits since they all refresh through_cache_team_object. Per Greptile review, both the internal cache delete and the alias-key invalidation are best-effort (769f434): on a cache backend error they log a warning and continue, so a Redis blip cannot turn a healthy team lookup into a 404 or a committed /team/update into a 500; this matches howDualCache.async_set_cachealready swallows write errors on the same pathlitellm/proxy/auth/user_api_key_auth.py: removed the post check 6 write-back that stored the fetched (or token-fallback) team object underteam_id:{id}on every authenticated request. Cache-read values must never be written back into the cache; only authoritative writers (DB reads insideget_team_objectand team mutations) populate it. This is the same rule the codebase already enforces for key objects (seetest_auth_does_not_rewrite_cached_key_object_back_into_cache)Tests: extended
test_cache_team_object_writes_team_id_and_invalidates_team_aliasto pin the new invalidation; addedtest_team_update_not_shadowed_by_internal_usage_cache_lit_4391, which rebuilds the shared-Redis topology with both caches over one fake Redis and fails on master; addedtest_auth_flow_never_persists_fallback_team_object_lit_4391, which drives the real auth builder and fails on master; addedtest_cache_team_object_tolerates_cache_invalidation_failures, which pins that cache backend errors do not fail the refresh and the authoritative write still runs; deletedtest_auth_path_caches_team_object_under_canonical_team_id_key, which pinned the removed write-back (its underlying concern, caching under the canonical key, is handled insideget_team_object's DB path and covered by the_cache_team_objecttests); gavetest_update_team_org_scoped_tpm_rpm_bypasses_user_limitan awaitable mock for the new delete call. The LIT-4391 regression tests were verified to fail before the fix and pass afterFinal Attestation