Repository navigation
fix(proxy): kill the whole prisma process group when a boot migration command times out - #39509
Conversation
… command times out
Greptile SummaryThis PR routes boot-time Prisma schema checks and direct pushes through a timeout-aware runner so blocked database operations cannot stall startup indefinitely on supported process-group platforms
Confidence Score: 5/5The PR appears safe to merge because no blocking failure remains No blocking failure remains
|
| Filename | Overview |
|---|---|
| litellm/proxy/db/check_migration.py | Replaces the unbounded migration-diff subprocess with the shared timeout-aware Prisma runner and handles timeout, command, and import failures |
| litellm/proxy/db/prisma_client.py | Routes direct database pushes through the shared Prisma runner while preserving retry and post-push behavior |
| tests/test_litellm/proxy/db/conftest.py | Adds a fake Prisma CLI fixture that records calls and creates a descendant process for cleanup verification |
| tests/test_litellm/proxy/db/test_check_migration.py | Covers bounded migration-diff execution, descendant cleanup, and missing-runner degradation |
| tests/test_litellm/proxy/db/test_prisma_client.py | Updates database-push tests to exercise the CLI boundary and adds timeout cleanup and missing-runner coverage |
Reviews (3): Last reviewed commit: "fix(proxy): keep boot alive when the ins..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
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 cc4a066. Configure here.
|
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 f8e34d9. Configure here.
9982453
into
litellm_internal_staging
TLDR
Problem this solves:
prisma db pushtimeout killed only the wrapper processprisma migrate diffhad no timeout at allHow it solves it:
run_prismamigrate diffgets the same budget, overridable per deploymentBased on
litellm_prisma_timeout_killpg(#39466), which addsrun_prisma, rather than duplicatingthe helper. Retarget to
litellm_internal_stagingonce that merges.That base predates #39478, so
ci/circleci: build_docker_database_imagefails here on the dashboardtype check for
tests/mocks/autoRouterPresets.ts. Nothing in this PR touches the UI, and stagingalready carries the fix.
User Flow
Before: an operator restarting the proxy while their database is busy gets a proxy that never
becomes ready and leaves prisma processes running on the host after they stop it.
--use_prisma_db_pushagainst a Postgres where a long-runningmigration or analytics transaction holds a lock the schema update needs
Attempt 1 timed outthroughAttempt 4 timed out, thenLiteLLM Proxy: Database migration failed but continuing startup.ps -eo pid,ppid,command | grep schema-enginestill lists aschema-engine-*process owned bypid 1, still connected to their database and still writing the schema
DISABLE_SCHEMA_UPDATE=true, and the proxy prints nothingat all: the log file stays 0 bytes and
curl http://127.0.0.1:<port>/health/livelinessfails with exit 7 for as long as they waitpsshows the wholeprisma migrate diffchain surviving withppid 1
After: the same restart gives up on schedule, comes up healthy on the second path, and leaves
nothing running behind it.
--use_prisma_db_pushagainst the same busy PostgresAttempt 1 timed out after 60sthroughAttempt 4 timed out after 60s,then
LiteLLM Proxy: Database migration failed but continuing startup.ps -eo pid,ppid,command | grep schema-enginelists nothingDISABLE_SCHEMA_UPDATE=true, and after 60 seconds the proxy printsTimed out after 60.0s generating the migration diff. Raise LITELLM_PRISMA_COMMAND_TIMEOUT if this database needs longer.and finishes booting, socurl http://127.0.0.1:<port>/health/livelinessreturns 200psshows no surviving prisma processesRelevant issues
Linear ticket
Resolves LIT-6801
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/test_litellm/<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 more@greptileaito re-request a review after pushing changes)Delays 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
Shared setup, identical on both sides: a real Postgres, a real Anthropic key, and a table lock that
keeps the schema update from finishing inside its budget, which is what a live migration or a long
analytics transaction does on a real deployment. Both sides boot with
--num_workers 2.Before (9f4fe31)
prisma db push
The engine is still running under pid 1, still connected to the database and still writing the
schema.
prisma migrate diff
9f4fe3144awith only the test files copied over,fail there for the reasons this PR fixes.
After (f8e34d9)
prisma db push
Both come back empty.
prisma migrate diff
Both come back empty.
An older proxy-extras install alongside this code
The two packages ship together, so this pairing only happens on a raw
pip install '.[proxy]'ofthe git tree between releases. Same clean database, same
--use_prisma_db_pushboot, with thepublished
litellm-proxy-extras==0.4.92ahead of the worktree onPYTHONPATH.At the merge base the push runs and the schema lands:
At this tip the import fails, boot says so and carries on, exactly as the default
migratepathalready does when it cannot import the extras:
--enforce_prisma_migration_check(orENFORCE_PRISMA_MIGRATION_CHECK=true) still turns that intoan exit, which is the operator's existing lever for a migration that did not run.
Type
🐛 Bug Fix
Caveats (if any)
Low
LITELLM_PRISMA_COMMAND_TIMEOUTfor a longer budgetprisma generateand the CLI runnability probe stay unboundedrun_prismaskips the command, not bootmigrate diffloses the drift diagnostic;db pushlogs the failure and leaves the schema aloneenforce_prisma_migration_checkstill decides whether that skipped push stops startuppip installof the git tree can pair them; releases publish both togethersubprocess.runnever reached them either, so nothing regressesFinal 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
f8e34d9 passes /live-pr-risk