Skip to content

fix(proxy-extras): stop the migration sanity check from building the hand-built SpendLogs indexes and cut 1.103.3 - #44286

Merged
yuneng-berri merged 2 commits into
stable/1.103.xfrom
litellm_fix_cbfd1b
Oct 3, 2026
Merged

yuneng-berri merged 2 commits into
stable/1.103.xfrom
litellm_fix_cbfd1b

Conversation

@yuneng-berri

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

How it solves it:

  • The post-migration drift script now drops those two CREATE INDEX statements
  • Mirrors filter_request_log_index_diff on main, so 1.105 converges
  • Bumps litellm to 1.103.3; litellm-proxy-extras stays at the unpublished 0.4.100.post1

User Flow

Before: an operator upgrading from a pre-1.103 release still gets both SpendLogs indexes built at proxy boot, holding a write-blocking lock on a large table

  1. They start the proxy on the 1.103.x patch with DATABASE_URL pointing at a database last migrated by 1.102
  2. The boot log shows "Running post-migration sanity check..." then "Migration diff applied successfully"
  3. Postgres runs a plain CREATE INDEX for LiteLLM_SpendLogs_litellm_call_id_idx and LiteLLM_SpendLogs_api_key_startTime_idx, blocking spend log writes until both finish

After: the same upgrade boots without touching those indexes, so the operator builds them online on their own schedule

  1. They start the proxy on this build with the same DATABASE_URL
  2. The boot log shows "Running post-migration sanity check..." then "Drift script is empty after filtering; nothing to apply"
  3. Neither index is created; the operator runs CREATE INDEX CONCURRENTLY by hand when ready

Screenshots / Proof of Fix

Shared setup: a throwaway postgres:16 with log_statement=all, one database per run, seeded by prisma migrate deploy with every migration older than 20260823000000 (the state a 1.102 proxy leaves behind) plus 5 SpendLogs rows. Each run boots the proxy's DB setup with no server:

DATABASE_URL=postgresql://postgres:p@127.0.0.1:54019/<db> \
  python -c "import sys; from litellm.proxy.proxy_cli import run_server; sys.argv=['litellm','--skip_server_startup']; run_server()"
psql -d <db> -Atc "select indexname from pg_indexes where tablename='LiteLLM_SpendLogs' and indexname in ('LiteLLM_SpendLogs_api_key_startTime_idx','LiteLLM_SpendLogs_litellm_call_id_idx')"

Before (3e32c0c)

  1. Boot against up_before: exit 0, log shows
    INFO - Running post-migration sanity check...
    INFO - ✅ Migration diff applied successfully
    
  2. Index query returns both:
    LiteLLM_SpendLogs_api_key_startTime_idx
    LiteLLM_SpendLogs_litellm_call_id_idx
    
  3. Postgres statement log shows two plain CREATE INDEX "LiteLLM_SpendLogs_..._idx" statements

After (21995f8)

  1. Boot against up_after: exit 0, log shows
    INFO - Running post-migration sanity check...
    INFO - Drift script is empty after filtering; nothing to apply
    
  2. Index query returns nothing
  3. Postgres statement log shows no new CREATE INDEX for either index

tests/proxy_migration_tests/test_db_schema_migration.py also passes against an empty database on this branch; it failed on 3e32c0c with exactly these two CREATE INDEX statements as the drift

Type

🐛 Bug Fix

Caveats (if any)

Medium

  • Fresh installs and pre-1.103 upgrades now have neither index until an operator builds it
    • Key metadata recovery and request_id OR litellm_call_id spend log lookups get slower without them
  • --use_prisma_db_push likely still builds both from schema.prisma, blocking (untested; db push syncs to the schema)
  • Databases on 1.103.0 to 1.103.2 keep the indexes the old migrations already built

Low

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

… the hand-built SpendLogs indexes

schema.prisma still declares the LiteLLM_SpendLogs (api_key, startTime) and (litellm_call_id) indexes while their migrations are now SELECT 1, so the v1 resolver's drift script recreated both with a blocking CREATE INDEX at boot. The drift script now drops those two statements before it is applied, matching filter_request_log_index_diff on main. The key metadata recovery fixture builds its index directly and the schema sync test exempts the two indexes.
@yuneng-berri
yuneng-berri requested a review from a team October 2, 2026 23:59
@greptile-apps

greptile-apps Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium risk] Adjusts database migration sanity checks to skip hand-built indexes.

The migration fix appears sound, but the new test parameters must meet the repository's typing requirement before merging

Findings

  1. P2 New test inputs lack types ▶

Summary

Stops the migration sanity check from creating the two operator-managed SpendLogs indexes and updates litellm to 1.103.3

  • Keeps unrelated drift SQL and the existing partitioned-table filter
  • Updates the schema check and adds tests for omitted indexes
  • The new test parameters need types to meet the repository requirement
  • yuneng-berri acknowledges slower lookups without the indexes, continued index creation through --use_prisma_db_push, and retention of indexes already built by earlier releases

Reviews (1) · Last reviewed commit: "chore(release): bump litellm 1.103.2 -> ..."


class TestResolveAllMigrationsLedger:
def _run(self, monkeypatch, tmp_path, partitioned, execute_fails):
def _run(self, monkeypatch, tmp_path, partitioned, execute_fails, drift_sql=_PARTITIONED_DRIFT_SQL):

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 New test inputs lack types

The new drift_sql parameter and test parameters lack types. AGENTS.md requires strongly typed parameters. Add these types before merging

Context Used: AGENTS.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@yuneng-berri
yuneng-berri merged commit 7969128 into stable/1.103.x Oct 3, 2026
9 of 10 checks passed
@yuneng-berri
yuneng-berri deleted the litellm_fix_cbfd1b branch October 3, 2026 00:15
DeoLeung pushed a commit to aiyou178/litellm that referenced this pull request Oct 4, 2026
… the hand-built SpendLogs indexes

schema.prisma still declares the LiteLLM_SpendLogs (api_key, startTime) and (litellm_call_id) indexes while their migrations are now SELECT 1, so the v1 resolver's drift script recreated both with a blocking CREATE INDEX at boot. The drift script now drops those two statements before it is applied, matching filter_request_log_index_diff on main. The schema sync test exempts the two indexes

Ported to rc/1.104.0 from stable/1.103.x (BerriAI#44286), which is not on main: main carries filter_request_log_index_diff from BerriAI#43948 instead, and its backport here was reverted in BerriAI#44212. The key metadata recovery hunk is dropped because this line's test file has no Postgres-backed index fixture

(cherry picked from commit 4d245e1)
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.

2 participants