Skip to content

test(ci): pin the xai reported-cost split and the coordinator-held Prisma lock wait - #46645

Merged
mateo-berri merged 1 commit into
mainfrom
litellm_circleci_heal_xai_split_prisma_lock_test
Oct 15, 2026
Merged

mateo-berri merged 1 commit into
mainfrom
litellm_circleci_heal_xai_split_prisma_lock_test

Conversation

@mateo-berri

@mateo-berri mateo-berri commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • integration-cost and migration-startup are red on every scheduled main run since 2026-10-15 00:09 UTC
  • Two merged fixes changed behavior on purpose, and one test each still pins the old behavior

How it solves it:

Relevant issues

Red on main in integration pipeline 91253 job integration-cost 2260303, and in migration pipeline 91252 job migration-startup 2260279. Both have failed in every scheduled run since the culprits landed (integration 91241 through 91253, migration 91243 and 91252), and passed in the runs before (integration 91235 did not fail this case, migration 91236 green)

tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[xai-grok-5-provider_reported_cost] fails with input_cost 0.029078078078078076 != expected 0.0. The culprit is 44e94eb (#46320), which on purpose splits xAI's reported total across input and output in the ratio our token math gives. That PR moved the cases in cases/xai.py but missed the grok-5 case in cases/misc.py. The new expected split is 1840 prompt tokens at 1.35e-6 and 412 completion tokens at 2.7e-6 applied to the reported 0.0421, so input 0.029078078 and output 0.013021922, with spend unchanged

tests/e2e/migrations/test_startup.py::TestMigrationStartup::test_lock_deadline_then_restart fails with Timed out waiting for Prisma lock contention. The culprit is 2310dae (#46368), which disables Prisma's session advisory lock and has the proxy hold the coordinator key, then poll Prisma's key 72707369 with pg_try_advisory_xact_lock. A polling waiter never shows up as an ungranted pg_locks row, so the old blocked(PRISMA_LOCK) probe can never fire. The test now waits for a replica to hold the coordinator lock while the test holds Prisma's key, and requires the replica to fail with the specific Timed out waiting for Prisma's lock message, so it still proves the replica reached Prisma's key and gave up at the deadline without touching history

Deferred to their own fixes. test_bad_database_url and test_v2_resolver_unreachable_database_exits_2_and_names_p1001 (integration-database, integration-database-replica) are covered by #46592. test_request_log_indexes::test_a_migration_job_that_could_not_build_the_indexes_reports_failure_and_succeeds_when_rerun[v2] times out because #46368 now takes the coordinator key around every prisma migrate deploy, the same key a running index build holds, so a v2 boot waits behind any index build. Picking which side gets its own key is a design call left to the #46368 author. The integration-providers reds (tool-search replay, thinking history, prompt cache pin TTL, bridged invalid prompt fallback) and the integration-extensions Prometheus shared-label reds have several unrelated causes and were not bisected in this run

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. 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 more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

Screenshots / Proof of Fix

This is a test-only change, so the proof is the previously red CircleCI jobs on this branch

Before (ea777eb)

  1. Scheduled integration pipeline 91253 shows integration-cost failed on the grok-5 case
  2. Scheduled migration pipeline 91252 shows migration-startup failed on test_lock_deadline_then_restart

After (16d30fd)

  1. Branch pipeline 91257 shows integration-cost 2260393 passed, grok-5 case included (91255 was auto-canceled when 91256 started on the same branch)
  2. Branch pipeline 91256 shows every migration job green, with test_lock_deadline_then_restart passing in migration-startup 2260381
  3. integration-browser hit a socket hang up on /team/delete cleanup and passed on rerun (job 2260413). integration-providers, integration-extensions, integration-database, integration-database-replica and test_bad_database_url stay red here exactly as on main, deferred as described above

Type

✅ Test

QA runbook

  • tests/e2e/migrations/test_startup.py::TestMigrationStartup::test_lock_deadline_then_restart - a replica that cannot get Prisma's lock stops at its deadline without changing migration history, and a later restart completes
    • Hold Prisma's key from psql with SELECT pg_advisory_lock(72707369) on the proxy's database
    • Boot the proxy with --use_v2_migration_resolver and LITELLM_MIGRATION_LOCK_TIMEOUT=12
    • While it waits, SELECT pid FROM pg_locks WHERE locktype='advisory' AND granted shows the proxy holding the llm_mig2 coordinator key
    • Expect the proxy to exit with Timed out waiting for Prisma's lock and _prisma_migrations unchanged
    • Release the lock, boot again, and expect startup to complete with every migration applied
    • Sanity check: this test makes sense to add and is not hand-wavey (e.g., assert actual expected spend instead of just spend > 0) or potentially flaky

Final 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
  • 16d30fd passes /live-pr-risk

Link to Devin session: https://app.devin.ai/sessions/5c13f40005934ef0a488261a6e88253a
Open in Devin Desktop: https://app.devin.ai/desktop/session/5c13f40005934ef0a488261a6e88253a?variant=devin
Requested by: @mateo-berri


Note

Low Risk
Changes are limited to test expectations and e2e lock observability; no production code paths are modified.

Overview
Test-only updates so CI matches intentional product changes that landed on main without updating every assertion.

The xai/grok-5 provider-reported cost integration case now expects input and output cost split (≈0.029078078 / ≈0.013021922) while total spend stays 0.0421, aligning misc.py with the xAI reported-cost allocation behavior introduced elsewhere.

For migration startup, e2e helpers gain Database.holders() (granted advisory locks). test_lock_deadline_then_restart waits for a replica to hold COORDINATOR_LOCK while the test holds Prisma’s lock, then asserts exit with Timed out waiting for Prisma's lock—replacing a blocked(PRISMA_LOCK) probe that no longer fires when Prisma waits via pg_try_advisory_xact_lock polling.

Reviewed by Cursor Bugbot for commit 16d30fd. Bugbot is set up for automated code reviews on this repo. Configure here.

…k timeout

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@greptile-apps

greptile-apps Bot commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Automatic reviews are disabled for this repository.

@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@litereview code-review

@litereview

litereview Bot commented Oct 15, 2026

Copy link
Copy Markdown

✅ code-review

5/5 · Ready for human review

Scope: full · Full PR review.

Completed · Some checks not run.

No correctness findings.

Checks and execution details
  • Passed · Real testing evidence (required): Not applicable: no LLM translation changes in the scoped paths. The diff touches only tests/e2e/migrations/database.py, tests/e2e/migrations/test_startup.py, and tests/integration/cost_calculation/cases/misc.py. Nothing under litellm/llms/** or litellm/litellm_core_utils/prompt_templates/** changed.
  • Passed · grok-5 expected split matches implementation (optional): litellm/llms/xai/cost_calculator.py::_split_reported_cost computes reported * priced_input / priced_total. With the test cost map (tests/integration/cost_calculation/cost_map.py: input 1.35e-6, output 2.7e-6) and 1840/412 tokens, python3 returns 0.029078078078078076 for input, so output is 0.013021922. approx_equal in conftest.py allows 1% tolerance, and spend stays at 0.0421.
  • Passed · Lock deadline test traced against migration_lock.py (optional): migration_lock() holds llm_mig2 through pg_try_advisory_xact_lock inside an open transaction, so pg_locks shows it as granted. acquire_prisma_lock() then polls key 72707369 and raises Timed out waiting for Prisma's lock to recover migration history..., which contains the new failed() marker. holders() uses the same classid/objid split as the existing blocked() query. The e2e containers default to USE_V2_MIGRATION_RESOLVER=true, so the v2 path is the one under test.
  • Not run · Execute the changed integration and e2e tests (optional): These tests need the docker-compose integration stack and the migration container harness, and neither is available in this sandbox. The PR cites CircleCI branch pipeline 91255 as the after-run. I did not verify that pipeline.

View review · Reviewed 16d30fd4306e

@mateo-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment

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.

✅ 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 16d30fd. Configure here.

@codecov

codecov Bot commented Oct 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@litellm-stampbot

@litellm-stampbot

Copy link
Copy Markdown

litellm-stampbot: risk low

Approved at 16d30fd.

Rules (stampbot/risk_rules.yml):

  • low: no rule flagged it

Judge (gpt-6-luna): low, probability of high 0.00 (high at or above 0.90)

  • risk: low (probability of high 0.00)

Pushes do not re-run this check. Comment @litellm-stampbot again to re-check the new head.

@litellm-stampbot litellm-stampbot Bot added the risk:low Small, isolated, low-risk change label Oct 15, 2026

@kerry-berri kerry-berri left a comment

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.

Low risk by rule and by judgement at 16d30fd

@mateo-berri
mateo-berri merged commit d553123 into main Oct 15, 2026
118 of 123 checks passed
@mateo-berri
mateo-berri deleted the litellm_circleci_heal_xai_split_prisma_lock_test branch October 15, 2026 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk:low Small, isolated, low-risk change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants