Repository navigation
fix(proxy-extras): exit the 1.103 migration job by the migrations and fix three index build failures - #51009
Conversation
…ontract manifest The database group stopped at collection on these nodes, so the lane never ran them. Each one boots a migration job and a proxy, so the file also gets a 240 s timeout
An index the job could not build, for example while another replica held the migration lock, failed a helm upgrade whose migrations had passed. The job still waits for the build and logs what is left, and the next run or a serving proxy builds it
…cket hosts, and past a URL lock_timeout Without psycopg the build warns and reports the indexes missing instead of crashing the job. Prisma's ?host= socket param now reaches libpq, so socket URLs connect, and the unreachable-host message names that socket. The build session sets lock_timeout to 0 next to statement_timeout, so a lock_timeout in the URL no longer cancels an online build that waits on an old snapshot
[Medium impact] The changes since the previous review appear safe to merge SummaryThis PR lets the migration job succeed when migrations pass but request-log indexes remain missing. It also preserves socket hosts, skips index builds safely without psycopg, lifts index-build timeouts, and bumps proxy-extras to The latest change replaces
Reviews (5) · Last reviewed commit: "fix(proxy-extras): reset only the index ..." · Reviewed by Greptile |
|
bugbot run |
…quest-log index build On Postgres 17 and later a transaction_timeout in the database URL's options ends the build session in the middle of CREATE INDEX CONCURRENTLY. The build session now sets it to 0 next to statement_timeout and lock_timeout
…hem when each session ends
|
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 c15ffdb. Configure here.
|
Closed to free an open-PR slot. Branch kept, and it reopens for final CI and bot reviews once ready |
Handwritten 1-3 sentence description
Follow-up to #50856 on the 1.103 line. The helm migration job passes again whenever the migrations pass, even if the new SpendLogs indexes are not built yet. The index build also works on socket URLs, without psycopg, and with a timeout in the database URL
Details
TLDR
Problem this solves:
?host=socket URL builds against the wrong hostHow it solves it:
?host=socket paramstatement_timeout,lock_timeout, andtransaction_timeoutfor its session, whatever set them,general_settings.database_lock_timeoutincluded. The invalid index check zeroes all butlock_timeout. Both reset only those limits at the endIntentional product change:
migrations/run.pyexits 0 when the migrations passed but an index is still missing, and the next job run builds it. On a?host=URL with a partitionedLiteLLM_SpendLogs,prisma db pushnow stops with the partition error, as on TCPUser Flow
Before: a helm upgrade of a 1.103 deployment fails though every migration applied
helm upgradewhile another replica holds the migration lockMigration job failed after retries., and exits 1?host=URL or a URL timeout fails it the same wayAfter: the same upgrade goes through
helm upgradeMigration job completed successfully., and exits 0?host=URL or a URL timeout, the job builds both indexes on the first runRelevant issues
Follow-up to #50856, the backport of #43948. main and stable/1.104.x have the same gaps
Pre-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
Each case runs the helm Job's entrypoint,
python migrations/run.pywithUSE_V2_MIGRATION_RESOLVER=true, on both trees against a fresh Postgres 18.6 databaserun_legs.py and how to run it
The helm image always has psycopg, so no_psycopg and the CLI and proxy runs below cover pip installs. no_psycopg runs on a fresh venv with
litellm[proxy]==1.103.10andprisma==0.11.0and no psycopg. The other cases run on the branch'smake bootstrapvenv. socket_host tests libpq host resolution, which works the same inside a containerEach block below is the script's printed output for that leg, with only the local checkout path replaced. It prints each log line that matches
SHOWN, then the index stateThe url_transaction_timeout and url_transaction_timeout_repair cases ran again on their own,
run_legs.py <case>, with a 2000 ms timeout and a 5 s hold. In the full run their 200 ms timeout also cancelledprisma migrate deployon a loaded box before the index work began. The after cases ran again at c15ffdb withSIDES=afterBefore (8f44f66), output per case
lock_held
python run_legs.py, another session holds the migration lockSome request-log indexes are not in place yetthenMigration job failed after retries.no_psycopg
python run_legs.pyon the psycopg-free venvModuleNotFoundError: No module named 'psycopg'socket_host
python run_legs.py,postgresql://mateo@cloudsql.invalid:5432/<db>?host=/tmpfailed to resolve host 'cloudsql.invalid'for the invalid index check and the buildurl_lock_timeout
python run_legs.py,?options=-c%20lock_timeout%3D200, with an old snapshot held 3 s into the buildcanceling statement due to lock timeout, andLiteLLM_SpendLogs_api_key_startTime_idxis left INVALIDurl_transaction_timeout
python run_legs.py,?options=-c%20transaction_timeout%3D2000, with an old snapshot held 5 s into the buildthe connection is closed, andLiteLLM_SpendLogs_api_key_startTime_idxis left INVALIDurl_transaction_timeout_repair
python run_legs.py, a migrated database whoseLiteLLM_HealthCheckTable_model_id_model_name_checked_at_idxan interrupted build left INVALID,?options=-c%20transaction_timeout%3D2000, with an old snapshot held 5 s into the repairCould not repair invalid indexthenthe connection is closed, and the index stays INVALIDmigrations_fail
python run_legs.py,localhost:1P1001: Can't reach database serverAfter (c15ffdb), output per case
lock_held
python run_legs.py, another session holds the migration lockleaving the request-log indexes to the next index buildthenMigration job completed successfully.no_psycopg
python run_legs.pyon the psycopg-free venvpsycopg is not installed; skipping the request-log index buildsocket_host
python run_legs.py,postgresql://mateo@cloudsql.invalid:5432/<db>?host=/tmpurl_lock_timeout
python run_legs.py,?options=-c%20lock_timeout%3D200, with an old snapshot held 3 s into the buildurl_transaction_timeout
python run_legs.py,?options=-c%20transaction_timeout%3D2000, with an old snapshot held 5 s into the buildurl_transaction_timeout_repair
python run_legs.py, a migrated database whoseLiteLLM_HealthCheckTable_model_id_model_name_checked_at_idxan interrupted build left INVALID,?options=-c%20transaction_timeout%3D2000, with an old snapshot held 5 s into the repairmigrations_fail
python run_legs.py,localhost:1Run summary
Migration-only CLI and serving proxy without psycopg
--skip_server_startup/health/readiness,/v1/modelsCommands, config, and output
c15ffdb changes only which settings the index build and the invalid index check reset when their sessions end, and 5725752 changes only version strings. These legs never reach that reset with a different outcome, so they carry from df1d862
litellm --config nopg_proxy.yaml --use_v2_migration_resolver, with and without--skip_server_startup, on the psycopg-free venv against a fresh database. The litellm package is the same on both sides, and onlylitellm-proxy-extrascomes from each treeOther
?host=socket callersprisma db pushsetupsocket_callers.py and output
c15ffdb changes only which settings the index build and the invalid index check reset when their sessions end, and 5725752 changes only version strings. These legs never reach that reset with a different outcome, so they carry from df1d862
A fresh database is migrated over TCP and partitioned with
db_scripts/partition_spend_logs.sql. Each tree then calls the socket-reachable checks withDATABASE_URL=postgresql://mateo@cloudsql.invalid:5432/<db>?host=/tmpHelm upgrade on kind
Commands, values, and pod logs
Each tree's chart and its
migrations/Dockerfileimage ran on kind at 6eb671b, with Postgres 16. c09cd03, df1d862, and c15ffdb change only the index sessions' timeouts, their reset, and socket URL handling, which the job cases above run at c15ffdbBefore, a Job retry absorbed the 4.5 s lock wait in url_lock_timeout, so helm fails only when the old transaction outlasts every retry
The after runs use tag
6eb671b. url_lock_timeout also setsmigrationJob.extraEnvDATABASE_URL=postgresql://postgres:<password>@pg.qa.svc.cluster.local:5432/<db>?options=-c%20lock_timeout%3D200lock_held holds
pg_advisory_lock(7812739710205912882)from a psql session in the Postgres pod for the whole helm run. url_lock_timeout first applies the migrations and drops both indexes, then opens a REPEATABLE READ snapshot onLiteLLM_SpendLogsand commits it about 4.5 s afterCREATE INDEX CONCURRENTLYshows inpg_stat_activityBefore lock_held, helm and each of the 5 pods
After lock_held, the one pod
Before url_lock_timeout, pod 1 and then pod 2
After url_lock_timeout, the one pod, whose build waited on
Lock/virtualxidwhile the snapshot was openIndex state after each run: lock_held has neither index on both sides, and url_lock_timeout has both valid on both sides
pip install of proxy-extras
Each leg installs one wheel in a clean venv, with no
PYTHONPATHor psycopgModuleNotFoundErrorCommands, pip_leg.py, and output
The unpacked post3 wheel's
litellm_proxy_extrasmatches the tip tree (diff -rq -x __pycache__prints nothing), anduv lock --checkexits 0 at c15ffdbRegression tests, each failing before its fix and passing here
test_a_prisma_socket_host_param_reaches_libpq:'localhost' == '/cloudsql/...'on 8f44f66test_without_psycopg_the_build_warns_and_reports_the_indexes_missing:ModuleNotFoundErroron 8f44f66?host=case oftest_coordination_failure_labels_unreachable_hosts_named_like_tls_markers: the message namedlocalhost:5432on 8f44f66test_a_timeout_the_database_url_sets_does_not_cancel_the_online_build: itslock_timeoutcase fails on 8f44f66 withcanceling statement due to lock timeout, and itstransaction_timeoutcase fails on 6eb671b withthe connection is closedtest_repair_outlives_a_timeout_passed_through_database_url_options: itstransaction_timeoutcase fails on c09cd03, where the invalid index check loses its session and the index stays INVALIDtest_a_pooled_server_session_gets_its_timeout_back_after_the_build: all three cases fail without the reset withassert ('0',) == ('4s',), so the pooled session kept the build's zero timeouttest_a_pooled_server_session_keeps_the_search_path_another_client_set:assert ('"$user", public',) == ('public, pg_catalog',)on df1d862, whoseRESET ALLdropped ittest_the_job_succeeds_by_the_migrations_when_an_index_could_not_be_builtandtest_a_migration_job_that_could_not_build_the_indexes_succeeds_and_a_rerun_builds_themreplace the exit 1 expectationsLocal checks and the database integration lane
tests/litellm-proxy-extraspasses 155 of 155 at c15ffdbGauntlet-mini: SURVIVED, 5/5 lenses, 6 confirmed (all fixed), run 03347e01009b, reviewed the staged tree that became 6eb671b
make check BASE_REF=origin/stable/1.103.xat c15ffdb fails only on 13 ruff F811 and F821 errors that stable/1.103.x already has, intest_llm_cost_calc_utils.py,test_response_metadata.py, andtest_gpt5_transformation.py. This branch does not touch those filesOn the laptop, every boot test passed at 6eb671b in at least one of two runs. On the GCE box, 8f44f66 and 6eb671b passed the same 8 of 12, and the same 4 failed on both at the 70 s owned-proxy readiness deadline while the legacy
prisma migrate deploywas still running at load average 25At c15ffdb,
test_invalid_index_repair.pyandtest_request_log_indexes.pypass 63 of 64 on local Postgres 18.6 at load average 20.test_a_role_that_may_not_create_indexes_is_logged_and_left_for_the_next_job_runfails locally because it builds its reader URL by replacingpostgres:postgres@, which the local URL does not have/live-pr-risk at df1d862 and c15ffdb
PASS at c15ffdb. No breaking or backward incompatible change beyond what this PR names
At df1d862 /live-pr-risk failed. On Postgres 17 behind PgBouncer 1.26.1 in transaction mode, with
?schema=lpr3sand no DIRECT_URL, theRESET ALLthat ended the build and repair sessions also reset thesearch_pathPrisma had set on the shared server connection./key/infowith keys not yet cached then returned 401 (relation "LiteLLM_VerificationToken" does not exist) on 7 of 8 after the migration job and 6 of 8 after the migration-only CLI, while base returned 200 on all of them. Postgres 18 reportssearch_pathto PgBouncer, which sets it again, so it was not affectedc15ffdb resets only
statement_timeout,lock_timeout, andtransaction_timeout, andtest_a_pooled_server_session_keeps_the_search_path_another_client_setfails without that change. Every df1d862 leg ran again on all three trees, with the same rig, config, and order on each sideThe miss legs count
/key/infocalls with keys not yet cached that return 200 right after the job (the df1d862 run of miss_cli_pg18 got 0/8 on base too, so it has no baseline), and the reader legs show the first/key/infoafter it. In miss_job_pg17 the pooled server connection held0/30s/0/lpr4s(statement, lock, and transaction timeout, thensearch_path) on base,0/0/0/"$user", publicon df1d862, and0/0/0/lpr4son c15ffdbBreaking
None. Every boot, job, and CLI leg exits the same way on base and c15ffdb except the cases this PR fixes (no_psycopg 1 to 0, p3005_socket 2 to 0, and the index build markers)
Backward incompatible
None beyond the named reset. Base left the build's
statement_timeout 0andlock_timeout 30son a shared transaction-mode server connection. c15ffdb returns them to that connection's defaults. With database-level values of 41 s, 7 s, and 3 s, the pooled connection read0/30s/3safter the job on base and41s/7s/3son c15ffdb on PG18 and PG17 (pgb_tx_all_job, pgb_tx17_db), and0/30sagainst41s/7son PG16 (pgb_tx16_db). The one-setting legs (pgb_tx_dbst, pgb_tx_dblt, pgb_tx_dbtt) and exc_cancel, a cancelled build, show the same. exc_terminate and session mode match on all treesA client that ran
SET search_path,SET work_mem, a custom setting, andSET statement_timeout = 45son the same pooled backend (clientsetrb, PG16 and PG17) kept itssearch_path,work_mem, and custom setting after the job on base and c15ffdb, and lost all of them on df1d862. Itsstatement_timeoutread 0 afterwards on base and c15ffdb alikeRegression risk
Through a transaction pooler without DIRECT_URL, the three SETs and RESETs can land on different server connections. That is the Low caveat above, and DIRECT_URL is the documented setup for transaction poolers. A grep of
litellm_proxy_extrasforSET,RESET, andset_configfinds no other session setting on the build or repair connection.replica_identity.pyusesSET LOCAL, which ends with its transaction and does not run under the helper. The advisory locks held after the job match on all three treesDependency graph
tests/litellm-proxy-extrasThe one migration suite failure is
test_a_role_that_may_not_create_indexes_is_logged_and_left_for_the_next_job_run, which builds its reader URL frompostgres:postgres@and fails on base too with the local URLNot verified
The PG16 migration suite timed out under load, and the PG16 live legs above ran instead. Helm on kind did not run again at c15ffdb, and its earlier run at 6eb671b stands for the chart and image. Poolers other than PgBouncer 1.26.1, such as RDS Proxy or Supavisor, were not available
Decisions
lock_timeoutandtransaction_timeout0 for the build session, never the value from the URL, the role, or the databasestatement_timeoutfrom every source the same wayCREATE INDEX CONCURRENTLYtakes SHARE UPDATE EXCLUSIVE, which never blocks app reads or writestransaction_timeoutthe same way, since a cancelledREINDEX CONCURRENTLYleaves the index INVALID for the next boottransaction_timeoutis set only on Postgres 17 and later, since older servers reject the nameoptionsinstead would also drop the operator's other session settingsstatement_timeout,lock_timeout, andtransaction_timeoutwhen each session ends, neverRESET ALLRESET ALLalso dropped thesearch_pathPrisma set on a shared PgBouncer server connection, so key auth on Postgres 17 failed until Prisma reconnected (/live-pr-risk at df1d862)lock_timeout--timeoutplusmigrationJob.activeDeadlineSeconds, still applies?host=URLs now reach every psycopg caller, not only the buildType
🐛 Bug Fix
✅ Test
Caveats (if any)
Medium
LiteLLM_SpendLogsor a slow build can still outlast Helm's five-minute hooklock_timeoutortransaction_timeoutfrom the URL, role, or database cuts that wait shortDISABLE_SCHEMA_UPDATE=true, and the job exits 0, so nothing retries the buildLow
transaction_timeoutcases?host=socket URLs, as beforetransaction_timeoutcan still cancel the v2 migration lock transaction in a baseline or P3009 recovery, as beforeFinal Attestation
Bugbot summary