Skip to content

Conversation

@KAVYANSHTYAGI
Copy link
Contributor

Description

This PR enhances the LitAPI.health() method to support both synchronous and asynchronous implementations by allowing the return type to be bool | Awaitable[bool].

Previously, coroutine objects returned by health() were not awaited, leading to incorrect health reporting. The server now detects if the result is awaitable and properly awaits it, ensuring accurate readiness checks.

Key Changes

  • API update: LitAPI.health() can now return a coroutine.
  • Server logic: Uses inspect.isawaitable() to detect and await async returns.
  • Short-circuit: Stops checking once a failing health status is detected.
  • Test added: Verifies integration using an async def health() method.

Why this matters

Many real-world deployments require async health checks — e.g., pinging background workers, databases, or message queues. This change makes LitServe production-ready for those scenarios.

Compatibility

  • Fully backward compatible with existing sync implementations.
  • PEP 604 (bool | Awaitable[bool]) syntax used — requires Python ≥ 3.10.

Example

class MyAPI(LitAPI):
    async def health(self) -> bool:
        return await self.worker.is_alive()

@codecov
Copy link

codecov bot commented Sep 9, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85%. Comparing base (0a89b36) to head (9352083).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@         Coverage Diff         @@
##           main   #604   +/-   ##
===================================
- Coverage    85%    85%   -0%     
===================================
  Files        39     39           
  Lines      3071   3079    +8     
===================================
  Hits       2605   2605           
- Misses      466    474    +8     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Co-authored-by: Aniket Maurya <[email protected]>
@andyland andyland merged commit 00c5390 into Lightning-AI:main Sep 9, 2025
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants