fix(proxy): load REDIS_* env vars when cache_params has non-connection keys#26244
Conversation
️✅ There are no secrets present in this pull request anymore.If these secrets were true positive and are still valid, we highly recommend you to revoke them. 🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request. |
9f02a75 to
fdcd0d7
Compare
Greptile SummaryThis PR fixes a silent fallback to Confidence Score: 5/5Safe to merge — minimal, well-tested fix that restores expected Redis env-var fallback behaviour. The one-line logic change is correct and tightly scoped. Both new tests are mock-only, cover the exact regression and its guard condition, and no existing tests were modified. No security, backwards-compatibility, or data-integrity concerns are introduced. No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/proxy/proxy_server.py | Replaced empty-dict guard with connection-key check; env-var fallback now correctly fires when only non-connection keys (e.g. mode) are present in cache_params. |
| tests/test_litellm/proxy/test_proxy_server.py | Two new async regression tests added: one verifying env-var fallback with non-connection keys present, one verifying explicit host is not overwritten. Both use mocks only — no real network calls. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[load_config: cache=true] --> B{cache_params has\n'host' or 'url'?}
B -- Yes --> C[Use explicit connection\ndetails from cache_params]
B -- No --> D[Fall back to\nREDIS_HOST / REDIS_PORT /\nREDIS_PASSWORD env vars]
D --> E[cache_params.update with\nenv-var values]
C --> F[_init_cache cache_params]
E --> F
F --> G[Redis / redis-semantic cache\ninitialized correctly]
style D fill:#c8f7c5
style B fill:#fff3cd
Reviews (3): Last reviewed commit: "fix(proxy): load REDIS_* env vars when c..." | Re-trigger Greptile
00f47fa to
1372e07
Compare
Congrats! CodSpeed is installed 🎉
You will start to see performance impacts in the reports once the benchmarks are run from your default branch.
|
…n keys (BerriAI#26233) The cache_params env-var fallback in ProxyConfig.load_config was gated on `len(cache_params.keys()) == 0`, so any non-empty cache_params (e.g. just `mode: default_off`) silently dropped the Redis env var config and fell back to in-memory cache. This broke multi-pod deployments because spend_counter_cache.redis_cache never got wired up and each pod tracked counters independently. Replace the length check with a "user did not supply connection details" check: only populate REDIS_HOST / REDIS_PORT / REDIS_PASSWORD from the environment when neither `host` nor `url` is present in cache_params. Other cache_params keys (mode, ttl, etc.) no longer suppress the fallback. Adds two regression tests exercising ProxyConfig.load_config: - cache_params with only non-connection keys → env vars load, RedisCache path - cache_params with explicit host → env vars do not overwrite user config Fixes BerriAI#26233
1372e07 to
22a3c50
Compare
Relevant issues
Fixes #26233
Type
Bug Fix
Changes
Problem
In
ProxyConfig.load_config, the Redis env-var fallback is gated onlen(cache_params.keys()) == 0:This means a config like:
combined with
REDIS_HOST+REDIS_PORTenv vars silently falls back toInMemoryCache— because the presence ofmodemakescache_paramsnon-empty, skipping the env-var branch entirely.Downstream,
spend_counter_cache.redis_cachestaysNoneand per-pod counters diverge. In multi-pod deployments this breaks spend tracking and budget enforcement without any error.Fix
Replace the length check with "no connection details supplied":
The env-var fallback now triggers whenever the user has not specified
hostorurl. Othercache_paramskeys (mode,ttl,default_in_memory_ttl, etc.) no longer suppress it.Tests
Two new tests in
tests/test_litellm/proxy/test_proxy_server.py:test_redis_env_vars_loaded_when_cache_params_has_non_connection_keys— regression test for the reported bug.test_explicit_cache_params_host_not_overwritten_by_env_vars— ensures env-var fallback does not clobber user-suppliedhost.Both patch
ProxyConfig._init_cacheand assert the computedcache_paramsdict contains the expected Redis connection values.Pre-Submission checklist
tests/test_litellm/make test-uniton the touched file (110/110 intest_proxy_server.py)