Repository navigation
fix(db): partition runbook moves the call-id index off the legacy spend logs table - #46131
Conversation
…nd logs table db_scripts/partition_spend_logs.sql renames the Prisma indexes aside before creating the partitioned table but not LiteLLM_SpendLogs_litellm_call_id_idx, which the request-log index job builds. A deployment that partitions after that job ran keeps the name on LiteLLM_SpendLogs_legacy, so every later index build reports the index as being on another table and the migration job fails Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
@litereview code-review |
✅ code-reviewScope: full · Full PR review. READY · Test evidence: VERIFIED · 5/5 No correctness findings. Checks and execution details
View review · Reviewed |
|
bugbot run |
There was a problem hiding this comment.
✅ 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 5937ad5. Configure here.
TLDR
Problem this solves:
How it solves it:
db_scripts/partition_spend_logs.sqlrenames the call-id index aside with the six othersUser Flow
Before: an operator who partitions spend logs after upgrading cannot get the next upgrade's migration job through
LiteLLM_SpendLogspsql -f db_scripts/partition_spend_logs.sql, and the proxy keeps servingAfter: the same upgrade goes through without touching the database by hand
LiteLLM_SpendLogspsql -f db_scripts/partition_spend_logs.sql, and the proxy keeps servingPre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or moreDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
The symptom was first seen in the Buildkite perf lane (https://github.com/BerriAI/project-releaser/pull/310), which restores a Postgres volume where the index job ran before the runbook, and boots the released
ghcr.io/berriai/litellm-migrations:v1.105.0job on it:Job e2e-bk-412-rbo-litellm-migrations failedwith the collision error below, and builds 413 to 415 passed once the rename was applied by handThe run below repeats that operator flow on each commit with a fresh Postgres 18 database per leg.
python3 migrations/run.pyis thelitellm-migrationsimage's entrypoint, the runbook is applied withpsql -v ON_ERROR_STOP=1, and the proxy then boots with 2 uvicorn workers andDISABLE_SCHEMA_UPDATE=true(schema changes left to the Job, as in a Kubernetes rollout) and serves a realgpt-5.4-minicallBefore (cca06b2)
After (5937ad5)
The regression test,
test_partitioning_a_table_the_index_job_already_covered_moves_its_call_id_index_aside, fails on main withassert None == 'LiteLLM_SpendLogs_legacy'and passes at 5937ad5 against Postgres 18. A rollback withdb_scripts/unpartition_spend_logs.sqlafter the index job ran was also checked, and needs no matching rename, since it drops the partitioned table and its index in the same transaction and the next Job rebuilds the index on the plain tableObserved during the run, none caused or made worse by this PR:
DROP TABLEon legacyType
🐛 Bug Fix
Final Attestation
Link to Devin session: https://app.devin.ai/sessions/a12e287eab9e442d858a8ee418ba2897
Open in Devin Desktop: https://app.devin.ai/desktop/session/a12e287eab9e442d858a8ee418ba2897?variant=devin
Requested by: @kerry-berri
Note
Medium Risk
Touches the manual spend-logs partitioning runbook and upgrade ordering; wrong behavior blocks migration jobs, but the change mirrors existing index renames and is covered by an integration test.
Overview
Fixes a partition runbook gap where
LiteLLM_SpendLogs_litellm_call_id_idxstayed onLiteLLM_SpendLogs_legacyafter partitioning if the migration index job had already created it on the plain table. Laterensure_request_log_indexes/ migration job runs then failed because the canonical index name was on the wrong table.partition_spend_logs.sqlnow renames that index toLiteLLM_SpendLogs_legacy_litellm_call_id_idx, matching the six Prisma indexes already moved aside before recreating indexes on the partitioned parent.A new integration test runs the index job, applies the partition script, asserts the legacy rename, and confirms a second index job succeeds with call-id coverage on every partition.
Reviewed by Cursor Bugbot for commit 5937ad5. Bugbot is set up for automated code reviews on this repo. Configure here.