Repository navigation
chore(release): backport #43948, #44109, #44124 to rc/1.104.0 - #44156
Conversation
…nstead of in migrations (#43948) The two SpendLogs index migrations shipped in v1.103.0 each break one table shape: the plain CREATE INDEX holds a SHARE lock on a large unpartitioned table and the CONCURRENTLY one fails with 0A000 on a partitioned parent. Both files are now inert and the indexes are built by a table-driven, shape-aware step after migrate deploy: CONCURRENTLY on a plain table, ON ONLY the parent plus per-partition CONCURRENTLY and ATTACH PARTITION on a partitioned one. The migration job builds them synchronously and exits non-zero on failure; a serving proxy that ran migrate deploy itself builds them in the background off the readiness path. A valid index of the same definition under another name is renamed and reused, an invalid one is rebuilt, and extra copies are reported with their DROP INDEX statement instead of being dropped. The migration checker rejects any CREATE INDEX on LiteLLM_SpendLogs or LiteLLM_ErrorLogs in future migrations Co-authored-by: yassin <yassin@berri.ai> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> (cherry picked from commit c66c828)
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> (cherry picked from commit 4d95818)
The backported SpendLogs index build changes code inside litellm-proxy-extras, and litellm calls the new ProxyExtrasDBManager methods at boot. 0.4.102 is already published without them, so the pin moves to a post release built from this line
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
@greptileai please review the current head b82994a |
|
|
|
||
| current: Final = _index_state(connection, schema, name) | ||
| if current is None or not current.valid or current.table != table: | ||
| if not _under_migration_lock(connection, build): |
There was a problem hiding this comment.
Index build blocks migration startup
When an opted-in proxy builds an index on a large SpendLogs table, this call holds the migration coordinator lock for the entire CREATE INDEX CONCURRENTLY operation. Another replica starting migrations can exhaust its 600-second lock wait and fail to boot, even though the index build is running in the background.
Knowledge Base Used: Restore the v1 proxy migration resolver by default
| text=True, | ||
| timeout=MIGRATION_JOB_SECONDS, | ||
| cwd=REPO_ROOT, | ||
| env={**os.environ, "DATABASE_URL": database_url, **resolver.job_environment}, |
There was a problem hiding this comment.
Integration tests omit build opt-in
These subprocesses inherit the environment but the tests never set LITELLM_BUILD_SPEND_LOGS_INDEXES. With the default environment, the migration job exits successfully without building either index, so the tests fail while waiting for the “all in place” log message or checking the indexes. Set the opt-in explicitly for the tested flow.
| if existing is not None and existing.valid: | ||
| return True |
There was a problem hiding this comment.
Named indexes lack definition checks
If an existing valid index has the expected name but different columns, this branch accepts it without checking its definition. The partitioned-parent path also trusts an existing index by name. The build can therefore report success without the intended lookup index, leaving spend-log queries without the expected optimization.
|
|
TLDR
Backport to rc/1.104.0 of #43948 and #44109 (merged on main) and #44124 (picked from its PR head 4d95818, not merged yet), each with
git cherry-pick -x. No litellm version bump, since 1.104.0 has not been releasedProblem this solves:
CREATE INDEXblocks writes on a large unpartitioned SpendLogs during migrate deployCONCURRENTLYone fails with 0A000 on a partitioned SpendLogs and leaves the migration stuckHow it solves it:
LITELLM_BUILD_SPEND_LOGS_INDEXES, on the migration job or the proxyIntentional product change: new deployments no longer get
LiteLLM_SpendLogs_api_key_startTime_idxandLiteLLM_SpendLogs_litellm_call_id_idxfrom migrations. Operators who want them setLITELLM_BUILD_SPEND_LOGS_INDEXES=true. Databases that already have them keep themUser Flow
Before: an operator upgrading a proxy with a large SpendLogs table gets index DDL during migrate deploy, which either blocks writes or fails on a partitioned table
Applying migration `20260823000000_add_spend_logs_api_key_starttime_index`andApplying migration `20260831120001_spend_logs_litellm_call_id_index`cannot create index on partitioned table ... concurrentlyAfter: migrate deploy never builds those indexes, and the operator decides when to build them
LITELLM_BUILD_SPEND_LOGS_INDEXES is not enabled, skipping the request-log index buildLITELLM_BUILD_SPEND_LOGS_INDEXES=true, the migration job builds both indexes concurrently and logsRequest-log indexes are all in place; a serving proxy does the same in the background afterApplication startup completeWhat is included
Each dependency commit only changes that package's version, sdist and wheel lines in uv.lock, and
uv lock --checkwith the line's uv 0.11.7 passes. main already resolves every one of them at or above these versionsAdaptation notes
#43948 is the only adapted pick, and every non-test file is identical to upstream. Its unit tests were moved by rename detection from
tests/unit/proxy/totests/test_litellm/proxy/, where this line keeps them, with identical hunks. Intests/integration/_support/process.pythe pick's own change (thedatabase_setupparameter and its constants) is applied onto this line's older launcher, so only the indentation of one line differs.tests/integration/spend/test_key_metadata_recovery_probe_bounds.pydoes not exist on this line, so its hunk was dropped. #44109 and #44124 are patch-identical to their sourcesScreenshots / Proof of Fix
Shared setup: a Postgres 16 container, a fresh database per case, and this config, with the process environment cleared so no
.envleaks inBefore (61876f2)
Proxy boot with default settings
python litellm/proxy/proxy_cli.py --config proxy_config.yaml --port 4000withDATABASE_URLpointing at an empty databaseApplying migration `20260823000000_add_spend_logs_api_key_starttime_index`andApplying migration `20260831120001_spend_logs_litellm_call_id_index`, so the indexes are built inside migrate deploypsql -Atc "select indexname from pg_indexes where tablename='LiteLLM_SpendLogs'"listsLiteLLM_SpendLogs_api_key_startTime_idxandLiteLLM_SpendLogs_litellm_call_id_idxAfter (b82994a)
Proxy boot with default settings
curl http://localhost:4000/health/readinessreturns{"status":"healthy","db":"connected"}LITELLM_BUILD_SPEND_LOGS_INDEXES is not enabled, skipping the request-log index buildpsqlquery listsend_user_idx,pkey,session_id_idx,startTime_idxandstartTime_request_id_idx, and neither of the two indexescurl http://localhost:4000/chat/completions -H 'Authorization: Bearer sk-...' -d '{"model":"claude-haiku","messages":[{"role":"user","content":"Reply with exactly: backport ok"}],"max_tokens":20}'returnsbackport okwith 14 prompt and 6 completion tokens, and the SpendLogs row readsanthropic/claude-haiku-4-5|4.4e-05|20Proxy boot with the build turned on
LITELLM_BUILD_SPEND_LOGS_INDEXES=trueagainst a new empty database/health/readinessreturns healthy, and the log hasApplication startup complete.beforeRequest-log indexes are all in placepg_index.indisvalidistfor bothLiteLLM_SpendLogs_api_key_startTime_idxandLiteLLM_SpendLogs_litellm_call_id_idxMigration job with the build turned on
LITELLM_BUILD_SPEND_LOGS_INDEXES=true python migrations/run.pyagainst a new empty databaseBuilding index LiteLLM_SpendLogs_api_key_startTime_idx on LiteLLM_SpendLogs concurrently, the same forlitellm_call_id_idx, andRequest-log indexes are all in placeTests on this line: the targeted set (
tests/unit/litellm_proxy_extras,tests/unit/test_check_migrations_no_data_rewrites.py,tests/test_litellm/proxy/test_proxy_cli.py,tests/test_litellm/proxy/db/test_prisma_client.py,tests/test_litellm/proxy/auth/test_handle_jwt.py) goes from 505 passed on the rc tip to 780 passed, with no new failure. The Postgres-backedtests/proxy_migration_tests/test_request_log_indexes.py,test_invalid_index_repair.pyandtest_db_schema_migration.pypass 53 of 53. A five-lens adversarial review found nothing introduced by the backport; it also drove the migration job on partitioned, nested-partition and non-public-schema tables, a role without CREATE privilege (exit 1 when opted in, 0 when not), concurrent jobs, and an existing invalid index.tests/integration/database/test_request_log_indexes_at_boot.pycollects here but needs the CircleCI integration stack, so CI is its proofType
🐛 Bug Fix
Caveats (if any)
Severe
LITELLM_BUILD_SPEND_LOGS_INDEXES=trueMedium
DISABLE_SCHEMA_UPDATE=trueand no indexes, the boot drift check logs "schema out of sync" and suggests a plainCREATE INDEX; it only logs, and main does the sameLow
LITELLM_BUILD_SPEND_LOGS_INDEXESaccepts true, 1, yes and y;onor a trailing space silently skipslitellm_call_idindex stays on the legacy table; main has the same behaviorLink to Devin session: https://app.devin.ai/sessions/6ba0cdb773754acc873fb533f6c5bf9c
Open in Devin Desktop: https://app.devin.ai/desktop/session/6ba0cdb773754acc873fb533f6c5bf9c?variant=devin