Repository navigation
fix: initialize genvm health before alert checks - #1637
Conversation
📝 WalkthroughWalkthroughExtracted GenVM cache updates and permit parsing into ChangesGenVM Health Check Refactoring
Sequence DiagramsequenceDiagram
participant HealthLoop as _run_health_checks()
participant GenVM as genvm_manager
participant Cache as _update_genvm_health_cache
participant DB as database_check
participant Consensus as consensus_check
HealthLoop->>GenVM: probe genvm_manager.health()
GenVM-->>HealthLoop: health response /status JSON
HealthLoop->>Cache: _update_genvm_health_cache(response)
Cache-->>HealthLoop: updated _health_cache (genvm fields)
HealthLoop->>DB: database_check() (observes genvm cache)
HealthLoop->>Consensus: consensus_check() (observes genvm cache)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@backend/protocol_rpc/endpoints.py`:
- Around line 319-321: The code assigns timeout_s by directly casting an env var
to float, which will raise on malformed values or accept non-positive numbers;
change this to robust parsing: fetch the string with
os.environ.get("LLM_PROVIDER_AVAILABILITY_TIMEOUT_SECONDS", "20"), try
converting to float inside a try/except, on exception or if the resulting value
is <= 0 set timeout_s to a safe default (e.g., 20.0), and optionally clamp to a
sensible max; update the logic around the timeout_s variable in endpoints.py so
all availability checks use this validated, positive timeout value.
In `@tests/unit/test_llm_provider_availability.py`:
- Around line 45-51: Add explicit type hints to the test helper signatures:
annotate SlowGenVMManager.__init__(self) -> None and give self.logger the type
MagicMock (from unittest.mock) if you want an attribute annotation; annotate
SlowGenVMManager.try_llms(self, providers: list, prompt: str) -> Coroutine[Any,
Any, List[Dict[str, Any]]] (import Any, Dict, List, Coroutine from typing) or
simpler async def try_llms(...) -> List[Dict[str, Any]] if you prefer using the
runtime return type; apply the same style to the other test helper/function near
lines 66-67 (add parameter and return types and necessary typing imports).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: b9c4d558-f1f0-4f80-8d3f-3a0a7a17241f
📒 Files selected for processing (2)
backend/protocol_rpc/endpoints.pytests/unit/test_llm_provider_availability.py
| timeout_s = float( | ||
| os.environ.get("LLM_PROVIDER_AVAILABILITY_TIMEOUT_SECONDS", "20") | ||
| ) |
There was a problem hiding this comment.
Harden timeout env parsing and bounds.
Line 319 directly casts the env var to float; malformed or non-positive values can make availability checks fail immediately and mark providers unavailable. Add guarded parsing with a positive fallback.
Proposed fix
- timeout_s = float(
- os.environ.get("LLM_PROVIDER_AVAILABILITY_TIMEOUT_SECONDS", "20")
- )
+ raw_timeout = os.environ.get("LLM_PROVIDER_AVAILABILITY_TIMEOUT_SECONDS", "20")
+ try:
+ timeout_s = float(raw_timeout)
+ if timeout_s <= 0:
+ raise ValueError("timeout must be > 0")
+ except (TypeError, ValueError):
+ genvm_manager.logger.warning(
+ "Invalid LLM provider availability timeout; using default",
+ raw_timeout=raw_timeout,
+ )
+ timeout_s = 20.0🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@backend/protocol_rpc/endpoints.py` around lines 319 - 321, The code assigns
timeout_s by directly casting an env var to float, which will raise on malformed
values or accept non-positive numbers; change this to robust parsing: fetch the
string with os.environ.get("LLM_PROVIDER_AVAILABILITY_TIMEOUT_SECONDS", "20"),
try converting to float inside a try/except, on exception or if the resulting
value is <= 0 set timeout_s to a safe default (e.g., 20.0), and optionally clamp
to a sensible max; update the logic around the timeout_s variable in
endpoints.py so all availability checks use this validated, positive timeout
value.
| class SlowGenVMManager: | ||
| def __init__(self): | ||
| self.logger = MagicMock() | ||
|
|
||
| async def try_llms(self, providers, prompt): | ||
| await asyncio.sleep(1) | ||
| return [{"response": "ok"}] |
There was a problem hiding this comment.
🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win
Add type hints to newly introduced test helper/test function signatures.
Lines 45-51 and Line 66 introduce new Python functions without annotations; please add parameter and return types for compliance.
Proposed fix
import asyncio
+from typing import Any
from unittest.mock import MagicMock
@@
class SlowGenVMManager:
- def __init__(self):
+ def __init__(self) -> None:
self.logger = MagicMock()
- async def try_llms(self, providers, prompt):
+ async def try_llms(
+ self, providers: list[dict[str, Any]], prompt: dict[str, Any]
+ ) -> list[dict[str, str]]:
await asyncio.sleep(1)
return [{"response": "ok"}]
@@
-async def test_provider_availability_timeout_returns_unavailable(monkeypatch):
+async def test_provider_availability_timeout_returns_unavailable(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:As per coding guidelines, "Include type hints in all Python code".
Also applies to: 66-67
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@tests/unit/test_llm_provider_availability.py` around lines 45 - 51, Add
explicit type hints to the test helper signatures: annotate
SlowGenVMManager.__init__(self) -> None and give self.logger the type MagicMock
(from unittest.mock) if you want an attribute annotation; annotate
SlowGenVMManager.try_llms(self, providers: list, prompt: str) -> Coroutine[Any,
Any, List[Dict[str, Any]]] (import Any, Dict, List, Coroutine from typing) or
simpler async def try_llms(...) -> List[Dict[str, Any]] if you prefer using the
runtime return type; apply the same style to the other test helper/function near
lines 66-67 (add parameter and return types and necessary typing imports).
|
🎉 This PR is included in version 0.120.11 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Summary
Verification
Summary by CodeRabbit
Refactor
New Features
Tests