litellm/tests/integration/database
Mateo Wang cf1ebf8577
fix(accounting): split a lock-timed-out spend batch by team so a held lock delays only the teams behind it (#55601)
* fix(accounting): let one pod at a time deliver spend

Every pod ran the delivery loop on each flush. When most spend belongs to a
few teams, the pods queue on the same team advisory lock, the waiters hit
lock_timeout and roll back, and their rows move to the one-row-per-transaction
retry path.

Take a short-lived delivery lock around the fresh and retry loops so only one
pod claims deliveries at a time. The maintenance lock is untouched, so an
orphaned maintenance lock still cannot stall delivery. A crashed holder delays
delivery by at most the lock TTL, and without Redis delivery behaves as before.

Relates to #55172

Co-Authored-By: AaronHowell <111272993+AaronHowell@users.noreply.github.com>

* fix(accounting): keep the delivery lock as long as one batch may run

A single delivery batch runs in a transaction with a 60 second timeout, so a
30 second lock could expire while its holder was still delivering and let a
second pod start. Use 60 seconds so the lock outlives any one batch.

Co-Authored-By: AaronHowell <111272993+AaronHowell@users.noreply.github.com>

* fix(accounting): leave lock-timed-out spend deliveries for the next flush instead of the retry queue

Since every pod delivers spend at once, a delivery that times out waiting for a
hot team or key row bumped attempts on its whole batch, which moved up to 500
rows into the one-row-at-a-time retry queue. A lock timeout means the batch never
applied and rolled back, so leave the claimed rows as they were and let the next
flush deliver them in a batch.

This replaces the one-pod-at-a-time delivery lock from #55173, which stopped the
retries but delivered a third to a half fewer rows per minute than concurrent
pods. Thanks to @Bytechoreographer for tracking the stuck rows down to concurrent
delivery.

* fix(accounting): keep backoff for retried deliveries that hit a lock timeout

Only a new batch is left as it was after a lock timeout. A delivery already in the retry queue backs off again as before, so one busy row no longer holds up the other retries behind it. The worker now logs how many requests it left for the next flush.

* fix(accounting): never park a delivery for a lock timeout

A lock timeout that Postgres reports in another language came back as a plain DataError, which counted as a permanent failure, so a retried delivery on its last attempt was parked. Lock timeouts now always back off and retry.

* fix(accounting): count lock-timed-out deliveries on /metrics

* fix(accounting): split a lock-timed-out batch by team so one held lock defers only that team

A fresh batch that times out on a team lock, or whose transaction expires,
is split by the teams it charges. Each team's deliveries are claimed again
and applied in their own transaction, so a long-held lock on one team only
defers that team's rows, and those rows step back 5-15 s so newer
deliveries go first. After two contended teams the rest of the batch waits
for the next flush untried.

* fix(accounting): back off an expired single-team batch, cap the split at 5 s, and keep committed teams when the database drops

* fix(accounting): name the split limit in the deferred delivery log

---------

Co-authored-by: Rick <26716961+Bytechoreographer@users.noreply.github.com>
Co-authored-by: AaronHowell <111272993+AaronHowell@users.noreply.github.com>
2026-12-02 15:58:55 -08:00
..
image build(docker): build OpenSSL 3.5 LTS from source for Prisma instead of Wolfi libssl3 3.6 (#54426) 2026-11-25 18:12:01 -08:00
migrations fix(proxy-extras): stop the invalid index repair from leaving session timeouts on pooled connections (#55233) 2026-12-01 13:11:48 -08:00
test_alerts.py feat(alerts): add email labels, bulk actions and threshold editing (#52139) 2026-11-16 15:32:19 -08:00
test_auth_profile_encryption_migration.py feat(mcp): cover stored profile credentials in key rotation and AES migration (#53671) 2026-11-28 15:07:22 -08:00
test_chunked_in_lists.py ci: fail on new unbounded SQL IN lists and add a Prisma chunking helper (#42629) 2026-09-26 13:40:44 -07:00
test_cleanup_transactions.py feat(proxy): run spend log cleanup from a DB-backed scheduled job table (#50131) 2026-11-11 18:22:02 -08:00
test_control_plane_runtime_config.py feat(control_plane): fleet-wide team budgets via desired state and reconciliation (#54056) 2026-11-24 10:15:44 -08:00
test_global_spend_refresh_writer.py fix(spend): run the MonthlyGlobalSpend refresh on the writer when a read replica is configured (#45699) 2026-10-10 00:49:13 -07:00
test_harness_lifecycle.py test(integration): probe ports with SO_REUSEADDR so forked children cannot block binds (#55431) 2026-12-01 06:13:10 +00:00
test_managed_file_flat_ids_index.py test(integration): point database tests at the moved litellm/proxy-extras package (#51453) 2026-11-12 20:27:00 +00:00
test_mcp_server_events_column.py feat(mcp): persist per-server event settings (#53602) 2026-11-24 06:31:10 +00:00
test_migration_entrypoint.py perf(mcp): skip unchanged scheduled catalog rebuilds (#54514) 2026-11-27 09:45:36 -05:00
test_partition_transactions.py fix(proxy): avoid blocking writes when attaching spend log partitions (#53858) 2026-11-23 11:19:33 -08:00
test_performance_alerts.py fix(proxy): yield on performance alert claim lock timeouts (#55370) 2026-11-30 17:15:27 -08:00
test_prisma_engine_port.py refactor(auth_cache): type auth cache keys and keep the cache always native (#51130) 2026-11-21 17:20:30 +09:00
test_prisma_engine_real_io.py fix(proxy): start and serve the proxy with a database on Python 3.10 and prisma 0.13+ (#54416) 2026-11-26 00:09:17 +00:00
test_prisma_migration_lock.py test(integration): fix four flaky integration tests (#49554) 2026-11-02 09:23:17 -08:00
test_proxy_boot_without_general_settings.py fix(proxy-extras): keep the host query param in the v2 migration lock URL (#52797) 2026-11-19 09:37:00 -08:00
test_proxy_database_lifespan.py fix(gateway): honor the configured Postgres connection cap (#52729) 2026-11-19 04:10:10 +00:00
test_reader_writer_regeneration.py test(integration): give each owned proxy a private database and Redis by default (#47213) 2026-10-18 03:37:41 +00:00
test_request_log_indexes_at_boot.py fix(proxy): create current and upcoming spend log partitions in the partitioning runbook (#53894) 2026-11-23 20:01:44 +00:00
test_roi_observed.py feat(roi): measure shipping velocity, quality, and recorded spend (#44426) 2026-10-03 23:07:34 +00:00
test_roi_sync_store.py feat(proxy): add native ROI calculator for gateway spend vs merged PRs (#43669) 2026-09-30 14:16:41 -07:00
test_scheduled_job_runs.py test(integration): point database tests at the moved litellm/proxy-extras package (#51453) 2026-11-12 20:27:00 +00:00
test_skill_publication.py feat(skills)!: version published Skills Hub updates (#50152) 2026-11-05 00:19:38 -08:00
test_skill_submissions.py feat(skills): let authors edit and withdraw pending submissions (#51312) 2026-11-12 08:30:10 -08:00
test_spend_lock_order.py chore: move scripts and runtime sources under litellm (#51006) 2026-11-12 04:19:57 +00:00
test_spendlogs_delivery.py fix(accounting): split a lock-timed-out spend batch by team so a held lock delays only the teams behind it (#55601) 2026-12-02 15:58:55 -08:00
test_spendlogs_ledger_parity.py refactor(rust): rename the compiled module _native to _rust (#55198) 2026-12-01 07:08:38 -08:00
test_transaction_atomicity.py test(integration): add read-replica routing harness to the CircleCI integration suite (#42692) 2026-09-24 00:25:03 -07:00
test_v1_migration_error_logging.py test(integration): point database tests at the moved litellm/proxy-extras package (#51453) 2026-11-12 20:27:00 +00:00