Skip to content

chore(release): backport #43948, #44109, #44124 to rc/1.104.0 - #44156

Merged
yuneng-berri merged 8 commits into
rc/1.104.0from
litellm_backport_rc1040_bp1001
Oct 2, 2026
Merged

yuneng-berri merged 8 commits into
rc/1.104.0from
litellm_backport_rc1040_bp1001

Conversation

@devin-ai-integration

Copy link
Copy Markdown
Contributor

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 released

Problem this solves:

  • The two SpendLogs index migrations shipped in v1.103.0 each break one table shape
  • The plain CREATE INDEX blocks writes on a large unpartitioned SpendLogs during migrate deploy
  • The CONCURRENTLY one fails with 0A000 on a partitioned SpendLogs and leaves the migration stuck

How it solves it:

  • Both migration files become inert, and a shape-aware step builds the indexes after migrate deploy
  • The build is opt-in through LITELLM_BUILD_SPEND_LOGS_INDEXES, on the migration job or the proxy
  • litellm-proxy-extras moves to 0.4.102.post1, since litellm now calls new methods in it and 0.4.102 is already on PyPI without them
  • Lock-only dependency bumps: pyjwt 2.15.0, tornado 6.5.9, urllib3 2.8.0, gitpython 3.1.62

Intentional product change: new deployments no longer get LiteLLM_SpendLogs_api_key_startTime_idx and LiteLLM_SpendLogs_litellm_call_id_idx from migrations. Operators who want them set LITELLM_BUILD_SPEND_LOGS_INDEXES=true. Databases that already have them keep them

User 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

  1. The operator starts the proxy or the migration job against Postgres with default settings
  2. The log shows Applying migration `20260823000000_add_spend_logs_api_key_starttime_index` and Applying migration `20260831120001_spend_logs_litellm_call_id_index`
  3. On a partitioned SpendLogs the second one fails with cannot create index on partitioned table ... concurrently

After: migrate deploy never builds those indexes, and the operator decides when to build them

  1. The operator starts the same proxy or migration job with default settings
  2. The log shows LITELLM_BUILD_SPEND_LOGS_INDEXES is not enabled, skipping the request-log index build
  3. With LITELLM_BUILD_SPEND_LOGS_INDEXES=true, the migration job builds both indexes concurrently and logs Request-log indexes are all in place; a serving proxy does the same in the background after Application startup complete

What is included

Each dependency commit only changes that package's version, sdist and wheel lines in uv.lock, and uv lock --check with the line's uv 0.11.7 passes. main already resolves every one of them at or above these versions

Adaptation 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/ to tests/test_litellm/proxy/, where this line keeps them, with identical hunks. In tests/integration/_support/process.py the pick's own change (the database_setup parameter 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.py does not exist on this line, so its hunk was dropped. #44109 and #44124 are patch-identical to their sources

Screenshots / Proof of Fix

Shared setup: a Postgres 16 container, a fresh database per case, and this config, with the process environment cleared so no .env leaks in

model_list:
  - model_name: claude-haiku
    litellm_params:
      model: anthropic/claude-haiku-4-5
      api_key: os.environ/ANTHROPIC_API_KEY
general_settings:
  master_key: os.environ/LITELLM_MASTER_KEY

Before (61876f2)

Proxy boot with default settings

  1. python litellm/proxy/proxy_cli.py --config proxy_config.yaml --port 4000 with DATABASE_URL pointing at an empty database
  2. The log shows Applying migration `20260823000000_add_spend_logs_api_key_starttime_index` and Applying migration `20260831120001_spend_logs_litellm_call_id_index` , so the indexes are built inside migrate deploy
  3. psql -Atc "select indexname from pg_indexes where tablename='LiteLLM_SpendLogs'" lists LiteLLM_SpendLogs_api_key_startTime_idx and LiteLLM_SpendLogs_litellm_call_id_idx

After (b82994a)

Proxy boot with default settings

  1. Same command against a new empty database
  2. curl http://localhost:4000/health/readiness returns {"status":"healthy","db":"connected"}
  3. The log shows LITELLM_BUILD_SPEND_LOGS_INDEXES is not enabled, skipping the request-log index build
  4. The same psql query lists end_user_idx, pkey, session_id_idx, startTime_idx and startTime_request_id_idx, and neither of the two indexes
  5. curl 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}' returns backport ok with 14 prompt and 6 completion tokens, and the SpendLogs row reads anthropic/claude-haiku-4-5|4.4e-05|20

Proxy boot with the build turned on

  1. Same command with LITELLM_BUILD_SPEND_LOGS_INDEXES=true against a new empty database
  2. /health/readiness returns healthy, and the log has Application startup complete. before Request-log indexes are all in place
  3. pg_index.indisvalid is t for both LiteLLM_SpendLogs_api_key_startTime_idx and LiteLLM_SpendLogs_litellm_call_id_idx

Migration job with the build turned on

  1. LITELLM_BUILD_SPEND_LOGS_INDEXES=true python migrations/run.py against a new empty database
  2. It exits 0 after Building index LiteLLM_SpendLogs_api_key_startTime_idx on LiteLLM_SpendLogs concurrently, the same for litellm_call_id_idx, and Request-log indexes are all in place
  3. Both indexes exist afterwards

Tests 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-backed tests/proxy_migration_tests/test_request_log_indexes.py, test_invalid_index_repair.py and test_db_schema_migration.py pass 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.py collects here but needs the CircleCI integration stack, so CI is its proof

Type

🐛 Bug Fix

Caveats (if any)

Severe

  • New installs on this rc no longer get the two SpendLogs indexes unless LITELLM_BUILD_SPEND_LOGS_INDEXES=true
    • Spend lookups by request id on large tables are slower without them
  • Publish litellm-proxy-extras 0.4.102.post1 before the litellm release
    • pip installs and the non_root image install the extras from PyPI and fail to resolve until then

Medium

  • pyjwt 2.14.0 and later reject JWTs with non-canonical (padded) base64url segments that 2.13.0 accepted
    • Only affects identity providers issuing non-RFC tokens; 2.14.0 is the smallest version that clears the advisories
  • feat(proxy-extras): make the SpendLogs index build opt-in #44124 is picked from its open PR; if it changes before merging, this line needs a follow-up
  • With DISABLE_SCHEMA_UPDATE=true and no indexes, the boot drift check logs "schema out of sync" and suggests a plain CREATE INDEX; it only logs, and main does the same

Low

  • LITELLM_BUILD_SPEND_LOGS_INDEXES accepts true, 1, yes and y; on or a trailing space silently skips
  • Opted in, a SpendLogs that was converted to partitioned after migrating plain keeps failing the build, since its litellm_call_id index stays on the legacy table; main has the same behavior

Link to Devin session: https://app.devin.ai/sessions/6ba0cdb773754acc873fb533f6c5bf9c
Open in Devin Desktop: https://app.devin.ai/desktop/session/6ba0cdb773754acc873fb533f6c5bf9c?variant=devin

devin-ai-integration Bot and others added 8 commits October 2, 2026 06:48
…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)
…index build (#44109)

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 123237c)
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
@devin-ai-integration

devin-ai-integration Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

@greptileai please review the current head b82994a

@greptile-apps

greptile-apps Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 3/5

[High risk] Database migration and index-building logic for spend logs.

The PR should not merge until long index builds cannot fail competing proxy startups and the new integration tests enable the behavior they assert.

Findings

  1. P1 Index build blocks migration startup ▶
  2. P1 Integration tests omit build opt-in ▶
  3. P2 Named indexes lack definition checks ▶

Summary

The PR makes two SpendLogs index migrations inert and adds an opt-in, partition-aware index builder after migration deployment. It also updates the proxy-extras pin and four locked dependencies.

  • The concurrent builder can hold migration coordination long enough to fail another replica’s startup.
  • The new at-boot integration tests omit the opt-in needed for their assertions.
  • Named indexes are not checked against their expected definitions.

Reviews (1) · Last reviewed commit: "chore(deps): bump gitpython to 3.1.62"


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):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 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},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 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.

Comment on lines +352 to +353
if existing is not None and existing.valid:
return True

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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.

@yuneng-berri
yuneng-berri merged commit dea6fb9 into rc/1.104.0 Oct 2, 2026
9 of 10 checks passed
@yuneng-berri
yuneng-berri deleted the litellm_backport_rc1040_bp1001 branch October 2, 2026 07:21
@CLAassistant

CLAassistant commented Oct 2, 2026 •

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 3 committers have signed the CLA.

✅ yuneng-berri
❌ yassin-berriai
❌ devin-ai-integration[bot]
You have signed the CLA already but the status is still pending? Let us recheck it.

This branch had an error being deployed

1 failed deployment
e2e-changed — b82994ac Deployed Oct 2, 2026 by devin-ai-integration[bot] via oauth #2562
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants