Fix health check reliability: exception handling, stale status, and concurrency#673
Merged
bhimrazy merged 8 commits intoLightning-AI:mainfrom Apr 9, 2026
Merged
Conversation
…oncurrency - Wrap custom health() calls in try/except to return 503 instead of 500 - Remove nonlocal workers_ready caching so status is re-evaluated every request - Add tests for exception handling, stale status detection, and cache invalidation Fixes Lightning-AI#660 Signed-off-by: Lidang-Jiang <lidangjiang@gmail.com>
andyland
approved these changes
Apr 6, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #673 +/- ##
===================================
- Coverage 85% 85% -0%
===================================
Files 39 39
Lines 3279 3282 +3
===================================
+ Hits 2775 2776 +1
- Misses 504 506 +2 🚀 New features to boost your workflow:
|
bhimrazy
approved these changes
Apr 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #660 — Three reliability issues in the
/healthendpoint:health()methods — If a user'shealth()raises an exception, the endpoint crashes with 500 instead of returning 503. In Kubernetes, this causes incorrect pod restarts.workers_readywas cached vianonlocaland never re-evaluated. If workers die after becoming ready, health check still returns 200.nonlocal workers_readyvariable was shared across concurrent health check requests.Changes
health()calls intry/exceptwithlogger.exception(), returning 503 on failurenonlocal workers_readycaching — computeworkers_readyinline on every requestBefore (unmodified code)
After (with fix)
Unit test results (all passing)
Full suite: 76 passed, 3 skipped
Test plan
test_health_check_returns_503_on_health_exception— customhealth()raising → 503 not 500test_health_check_detects_worker_status_change— workers READY→ERROR → 503test_health_check_no_stale_cache— status not cached across requests, recovers to 200ruff checkand pre-commit hooks pass