litellm/litellm-rust/crates/redis-connect/AGENTS.md
Devin AI 604249b933
Some checks failed
Cost map pins recheck / rerun-cost-map-guard (push) Has been cancelled
LiteLLM Rust DB / db-queries (push) Has been cancelled
LiteLLM Rust / rust-lint (push) Has been cancelled
LiteLLM Rust / rust-test (push) Has been cancelled
LiteLLM Rust / rust-wheel (push) Has been cancelled
Terraform Modules / fmt, validate, test (aws) (push) Has been cancelled
Terraform Modules / fmt, validate, test (gcp) (push) Has been cancelled
feat(redis): rotating cloud credentials for Redis
The REDIS_CIRCUIT_BREAKER_* settings are read once in resolve into
Resolution::breaker, like get_env_int and get_env_float read them. A value
that does not parse is warned about and keeps its default. Before, a typo
failed connect with InvalidBreakerSetting and put every native store on
per-process memory while RedisCache kept its default breaker.
2026-11-05 13:21:52 +09:00

3.4 KiB

  • Turns a litellm_redis_types::Resolution into a RedisClient, the same way for every host. It depends on litellm-redis-types, never on litellm-config, so a host that resolves Redis some other way connects the same way. redis-client stays cloud-agnostic, so credential providers and cloud token sources are built here
  • The host passes only what it alone can build in HostServices: the event sink, the HTTP client and the environment lookup. The breaker config comes from Resolution::breaker, which config reads from REDIS_CIRCUIT_BREAKER_* with Python's fallback, so a bad value keeps the default instead of failing connect. Each cloud source asks its auth crate for one explicit identity, the way the Python SDK builds it: AwsAuthService::default_chain_credentials (botocore's default chain), CredentialSource::application_default (google.auth.default) and AzureIdentity (the class _build_azure_credential picks). LiteLLM's provider settings such as AWS_ROLE_NAME, AZURE_AD_TOKEN or VERTEXAI_CREDENTIALS belong to Bedrock, Azure OpenAI and Vertex and never reach those constructors. Auth::Provider (a handle for a Python credential_provider object) fails at connect with an error naming the key, since no host can supply one yet
  • Every expiring credential goes through the one refresh loop in refresh.rs. A cloud source only fetches. Never add a second loop or let a source sleep. The expiry deadline lives only in the published Latest::Ready, so expiring it leaves Ready and cannot fire again. Never keep a copy of the deadline in the loop
  • AWS SDK identity settings must be in the process environment. aws-config cannot take the host lookup, so config-only overrides for profiles, role/web-identity settings, credentials, files and metadata sources fail before connecting rather than silently using another identity. Equal process/config values are allowed. Bedrock-only settings remain unrelated to Redis
  • redis-rs subscribes once for the connection handshake and again for re-authentication, so a new connection sends a redundant initial AUTH. Unchanged refreshes do not trigger another AUTH. Do not skip a provider's first or alternating subscriptions, because concurrent connections and retries each need the current token. Removing the initial duplicate requires an upstream connection-level fix
  • The loop starts on the first subscribe(), which redis-rs calls inside its runtime, so connect is safe off a runtime
  • A token-only credential (Azure without REDIS_USERNAME, GCP) is sent as AUTH default <token>, because redis-rs always sends a username with a credentials provider. On Redis 6+ that is the same as Python's AUTH <token>
  • Tests for the refresh loop use a fake source and real Redis ACL users. Cloud sources are proven against the live service, unit tests only pin request shapes we own
  • Rotation tests must retain the same server-side connection IDs across re-AUTH, then force a reconnect after removing the old user and verify the new identity still works
  • Live cloud tests live in tests/live/. Set LITELLM_REDIS_AWS_LIVE_CONFIG, LITELLM_REDIS_AZURE_LIVE_CONFIG or LITELLM_REDIS_GCP_LIVE_CONFIG to a JSON file containing redis settings and hold_seconds. Set the waiting period from the deployment's token lifetime when checking expiry. Optional fixtures return early when unset, and configured tests run under plain cargo test. An unconfigured run never counts as live proof