Repository navigation
fix(health): skip background health check DB writes when the latest-row read fails - #40993
Conversation
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
|
Greptile SummaryThis PR separates the latest-health-check database read into strict and fault-tolerant paths
Confidence Score: 5/5The PR appears safe to merge because a failed latest-row read now prevents duplicate background writes while non-persistence reads retain their existing fallback No actionable new issues remain. The previously reported stale mock was corrected to intercept the exact awaited database call, and its thread is resolved
|
| Filename | Overview |
|---|---|
| litellm/proxy/db/health_check_latest.py | Adds a strict typed query function while preserving fault-tolerant behavior for decorative read callers |
| litellm/proxy/health_endpoints/_health_endpoints.py | Uses the strict query in background persistence so read failures abort the write cycle |
| tests/test_litellm/proxy/db/test_health_check_latest.py | Verifies strict query failures propagate while the existing fetch wrapper still degrades gracefully |
| tests/test_litellm/proxy/test_health_check_functions.py | Covers write suppression after read failure and correctly targets the live db.query_raw call in legacy tests |
Reviews (2): Last reviewed commit: "fix(health): skip background health chec..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…ow read fails Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
75825c6 to
6d2c489
Compare
|
@greptileai please re-review 6d2c489: the legacy exception test now mocks db.query_raw, the read the save path actually makes |
|
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 6d2c489. Configure here.
af6dc1d
into
litellm_internal_staging
Rebuilds the branch on current main so the PR diff is only the Mantle overflow mapping and its test. Drops the stale litellm_internal_staging drift (BerriAI#37762, BerriAI#40993, BerriAI#34939) the branch had picked up.
TLDR
Problem this solves:
How it solves it:
/health/latest) keep degrading to no rowsUser Flow
Before: an admin with background health checks on sees the health check table fill up with duplicate rows
background_health_checks: trueandhealth_check_interval: 15Error getting all latest health checksand then writes one new row per model, even though nothing changedhealthy, while the table behind it keeps growing on every podAfter: the same failing read costs nothing but a warning
Failed to save background health checks to database: ...and writes nothinghealthy, and once the read works again the proxy goes back to writing a row only when a status changes or the hourly refresh is dueRelevant issues
Affected release
Linear ticket
Resolves LIT-2457
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. Local Postgres, schema pushed, two real OpenAI deployments, background health checks every 15 seconds. To make the latest-row read fail the way it does on an overloaded database, the proxy connects as a non-superuser role and a row level security policy raises whenever that specific
DISTINCT ONread runs. Plain inserts and plain selects from that role keep working, and the policy is evaluated per row, so the very first cycle against an empty table reads fine and writes one row per model on both sides. That first cycle is the control: the write path works. Every cycle after it hits the failing read.Before (c2c2a62)
After (6d2c489; captured on 75825c6, whose production code is byte for byte the same, the follow-up only repointed one legacy test mock)
postgresuser (read works, table already holds one row per model) and wait another 95 seconds. Nothing new is written because nothing changed, and/health/lateststill serves the rowsType
🐛 Bug Fix
Caveats (if any)
Medium
/health/latest, so this PR fixes the write storm behind the customer report instead. If the team wants persistence off entirely, that is a product call and a follow-upPOST /healthsave path writes one row per call and is unchanged; only the background loop is affectedVerify schema.d.ts matches the proxy OpenAPI speccheck is red on the base.litellm_internal_stagingcarries b9ba808, which dropped thesoft_budgetdocstring from the user endpoints without regeneratingui/litellm-dashboard/src/lib/http/schema.d.ts, so any PR touchinglitellm/proxy/regenerates the file and sees that two-line drift. This PR does not touch those endpoints and leaves the generated file alone rather than folding an unrelated regeneration into a health check fixproxy-behaviorcheck fails ontests/proxy_behavior/auth/test_auth_object_prefetch.py::test_join_binds_the_membership_to_the_requested_team(object MagicMock can't be used in 'await' expression). The same test fails the same way on unrelated open PRs against the same base (runs 34750112885, 34749974493, 34749801203), it passed on this PR's first run with identical production code, and the wholetests/proxy_behaviorsuite passes locally on this branch (848 passed). This PR does not touch auth or the prefetch pathLow
/health/latestreads keep the swallowingfetch_latest_health_checks; the manual/healthsave is a separate path and out of scope as stated above. C (silent behavior change): the only change is that a failing read skips the cycle and logs a warning. T1 (fails on unfixed code): the new save-path test reads(True, 1)with the old read and(False, 0)with the fix. H: no new source comments, noOptional, no baredictorAny, lines within 120Final Attestation
Link to Devin session: https://app.devin.ai/sessions/7b18ae4f7a1e4187b400e7fe04b32742
Open in Devin Desktop: https://app.devin.ai/desktop/session/7b18ae4f7a1e4187b400e7fe04b32742?variant=devin
Requested by: @yassin-berriai