Skip to content

fix(proxy-extras): backport the automatic SpendLogs index build (#43948, #44109, #44203) to stable/1.104.x - #50823

Merged
yuneng-berri merged 10 commits into
stable/1.104.xfrom
litellm_backport_43948_stable_1_104_x_devin
Nov 10, 2026
Merged

yuneng-berri merged 10 commits into
stable/1.104.xfrom
litellm_backport_43948_stable_1_104_x_devin

Conversation

@mateo-berri

@mateo-berri mateo-berri commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Handwritten 1-3 sentence description

Proxies on 1.104 with a large spend logs table never get the call ID index, so opening a request in the Logs page scans the whole table and times out. This backports the automatic, non-blocking index build that ships in 1.105 so those proxies build the index themselves after migrations

TLDR

Problem this solves:

How it solves it:

User Flow

Before: an admin on 1.104 with a large spend logs table and no call ID index cannot open any request's details

  1. They open https://litellm-domain/ui/logs and click a request row
  2. GET /spend/logs/ui/{request_id} hangs until the load balancer times out
  3. The drawer says prompt logging is not enabled, which it is

After: the proxy builds the index in the background after migrations, so the drawer opens

  1. They upgrade to the patch and the proxy boots and serves traffic right away
  2. The call ID index is built concurrently, spend log writes keep flowing
  3. They click a request row and the drawer shows its input and output

Affected release

Regression in v1.103.0, still present on every 1.104.x

Pre-Submission checklist

  • I have added meaningful tests
  • The handful of test files covering my change pass locally
  • My PR passes all required CI/CD checks
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review

Screenshots / Proof of Fix

Tests at the tip 7085864085, against local Postgres for the migration tests

  1. Mapped unit tests for request log indexes, proxy-extras utils, prisma client and proxy CLI, 587 passed
  2. tests/proxy_migration_tests/test_request_log_indexes.py and test_invalid_index_repair.py on Postgres 14, 39 passed
  3. The equivalent-index lookup on a live Postgres 10 server, 2 passed, 1 skipped (INCLUDE indexes need Postgres 11). The old SQL fails both cases there
  4. Schema drift integration test, 1 passed at d30a921dfe

Live before/after against a large spend logs table has not been run yet, see Caveats

Type

🐛 Bug Fix

Caveats (if any)

Severe

  • Boot now starts a concurrent index build on SpendLogs, which needs free disk and can run for hours on a very large table

Medium

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

Link to Devin session: https://app.devin.ai/sessions/b0bf3c680bdd430b98bc809296bc8168
Open in Devin Desktop: https://app.devin.ai/desktop/session/b0bf3c680bdd430b98bc809296bc8168?variant=devin
Requested by: @mateo-berri


Note

High Risk
Changes core database migration and online DDL paths for high-volume SpendLogs tables, including partitioned installs, advisory locking, and concurrent index builds that can run for a long time and need disk headroom.

Overview
LiteLLM_SpendLogs indexes declared in Prisma are no longer created in shipped migrations. The two affected migration files become inert (SELECT 1), and a new request_log_indexes module builds api_key/startTime and litellm_call_id indexes after prisma migrate deploy—concurrently on plain tables and per-partition on partitioned spend logs, under the migration coordinator lock with bounded lock waits.

The migration Job and proxy startup paths are wired so the job runs setup_database then waits for index builds (run_migration_job); a serving proxy that migrates on boot starts the same work on a daemon thread after readiness. Recovery can roll back a failed ledger row when this build ships an inert migration file, and drift filtering now treats these as migration-job-owned indexes. DATABASE_URL is translated for libpq/psycopg (Prisma TLS semantics), and invalid-index repair yields to the same advisory lock.

Migration lint now flags CREATE INDEX on request-log tables, with docs pointing new indexes at REQUEST_LOG_INDEXES.

Reviewed by Cursor Bugbot for commit 7085864. Bugbot is set up for automated code reviews on this repo. Configure here.

devin-ai-integration Bot and others added 9 commits November 10, 2026 02:31
…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)
… the migration job builds indexes (#44203)

The migration job runs DatabaseURLSettings.apply_to_env(), which rewrites
DATABASE_SSLMODE=verify-full plus DATABASE_SSLROOTCERT into Prisma's TLS
dialect: sslmode=require&sslcert=<CA>&sslaccept=strict. The request-log
index build then hands that same URL to psycopg, and libpq reads sslcert
as a client certificate, failing with "certificate present, but not
private key file" on every verify-full deployment since #43948.

_strip_prisma_query_params now undoes the Prisma dialect before psycopg
sees the URL. sslaccept=strict (or any value Prisma treats as strict)
becomes sslrootcert=<CA> plus sslmode=verify-full whatever sslmode said,
since strict verifies chain and hostname and libpq only does that in
verify-full; sslmode=disable stays off. Without strict, Prisma verifies
nothing, so the CA is dropped and sslmode is kept as is. A URL that also
carries sslkey is libpq's own client-certificate form and is left alone.

Resolves LIT-9169

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 4758fce)
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

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

@CLAassistant

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 2 committers have signed the CLA.

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

@veria-ai

veria-ai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

PR overview

No security issues were found in this pull request.

Reviews

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@greptile-apps

greptile-apps Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[High impact] The latest changes appear safe to merge, with no new blocking issue found

Summary

Backports automatic builds for the two missing LiteLLM_SpendLogs indexes. Migration jobs wait for completion, while serving proxies start the build in the background

  • SpendLogs indexes are built after migrations finish.
  • Migration jobs wait for indexes while serving proxies build them in the background.
  • Database setup recognizes indexes that the migration job now owns.
  • Migration checks flag index creation on request-log tables.

Reviews (2) · Last reviewed commit: "fix(proxy): support PostgreSQL 10 reques..." · Reviewed by Greptile

Comment thread litellm/proxy/proxy_cli.py Resolved
@mateo-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment •

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.

Stale Bugbot comment from a previous run.

Use the operator-class vector to count index keys across PostgreSQL versions and cover missing, equivalent and INCLUDE indexes with live catalog tests

Type the backported tests, construct environments without mutation and inject startup dependencies while preserving automatic index builds

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment

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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 7085864. Configure here.

@yuneng-berri
yuneng-berri merged commit 5e52c44 into stable/1.104.x Nov 10, 2026
10 of 12 checks passed
@yuneng-berri
yuneng-berri deleted the litellm_backport_43948_stable_1_104_x_devin branch November 10, 2026 17:56

This branch was successfully deployed

No deployments
e2e-changed — 70858640 Deployed Nov 10, 2026 by devin-ai-integration[bot] via oauth #6103
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