Repository navigation
fix: avoid expensive no-progress health scan - #1638
Conversation
📝 WalkthroughWalkthroughThe PR refactors consensus "no progress" detection in ChangesConsensus Health No-Progress Detection Optimization
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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: 1
🧹 Nitpick comments (1)
tests/db-sqlalchemy/test_health_orphan_detection.py (1)
667-674: ⚡ Quick winAdd type hints to the new event callback (and test return) for guideline compliance.
Suggested fix
+from typing import Any @@ -async def test_no_progress_detector_skips_history_scan_without_backlog(engine: Engine): +async def test_no_progress_detector_skips_history_scan_without_backlog( + engine: Engine, +) -> None: @@ - def fail_on_progress_scan( - conn, cursor, statement, parameters, context, executemany - ): + def fail_on_progress_scan( + conn: Any, + cursor: Any, + statement: str, + parameters: Any, + context: Any, + executemany: bool, + ) -> None:As per coding guidelines, "
**/*.py: Include type hints in all Python code".🤖 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/db-sqlalchemy/test_health_orphan_detection.py` around lines 667 - 674, The new test callback lacks type annotations; add type hints to the event callback function fail_on_progress_scan and to the test return type for guideline compliance: annotate fail_on_progress_scan's parameters (e.g., conn, cursor, statement, parameters, context, executemany) with appropriate types from sqlalchemy and typing (such as Connection/Cursor or DBAPI cursor, str, Any, Any, bool) and declare the test function test_no_progress_detector_skips_history_scan_without_backlog -> None; ensure imports (typing.Any or sqlalchemy types) are added if needed.
🤖 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/health.py`:
- Around line 915-916: The computed no_progress_check_error returned from
_check_consensus_health() is not being propagated into the cached /health
payload; update _run_health_checks() so when it builds/updates
services["consensus"] it copies the no_progress_check_error (and keep
NO_PROGRESS_WINDOW_MINUTES if needed) into that dict—i.e., locate where
_run_health_checks() consumes _check_consensus_health() results and add
"no_progress_check_error": no_progress_check_error to the services["consensus"]
response so clients of /health can see the scan timeout/error state.
---
Nitpick comments:
In `@tests/db-sqlalchemy/test_health_orphan_detection.py`:
- Around line 667-674: The new test callback lacks type annotations; add type
hints to the event callback function fail_on_progress_scan and to the test
return type for guideline compliance: annotate fail_on_progress_scan's
parameters (e.g., conn, cursor, statement, parameters, context, executemany)
with appropriate types from sqlalchemy and typing (such as Connection/Cursor or
DBAPI cursor, str, Any, Any, bool) and declare the test function
test_no_progress_detector_skips_history_scan_without_backlog -> None; ensure
imports (typing.Any or sqlalchemy types) are added if needed.
🪄 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: 29eae775-680c-4e60-8a84-c89b49409187
📒 Files selected for processing (2)
backend/protocol_rpc/health.pytests/db-sqlalchemy/test_health_orphan_detection.py
| "no_progress_check_error": no_progress_check_error, | ||
| "no_progress_window_minutes": NO_PROGRESS_WINDOW_MINUTES, |
There was a problem hiding this comment.
no_progress_check_error is computed but not exposed through cached /health consensus payload.
Line 915 adds the field to _check_consensus_health() output, but _run_health_checks() does not copy it into services["consensus"], so clients of /health cannot see scan timeout/error state.
Suggested fix
diff --git a/backend/protocol_rpc/health.py b/backend/protocol_rpc/health.py
@@
services["consensus"] = {
"processing_transactions": consensus_health.get(
"total_processing_transactions", 0
),
@@
"seconds_since_consensus_progress": consensus_health.get(
"seconds_since_consensus_progress"
),
+ "no_progress_check_error": consensus_health.get(
+ "no_progress_check_error", False
+ ),
"active_workers": consensus_health.get("active_workers", 0),
"status": consensus_status,
}🤖 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/health.py` around lines 915 - 916, The computed
no_progress_check_error returned from _check_consensus_health() is not being
propagated into the cached /health payload; update _run_health_checks() so when
it builds/updates services["consensus"] it copies the no_progress_check_error
(and keep NO_PROGRESS_WINDOW_MINUTES if needed) into that dict—i.e., locate
where _run_health_checks() consumes _check_consensus_health() results and add
"no_progress_check_error": no_progress_check_error to the services["consensus"]
response so clients of /health can see the scan timeout/error state.
|
🎉 This PR is included in version 0.120.12 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Summary
Verification
Note: tests/db-sqlalchemy/test_health_orphan_detection.py requires POSTGRES_URL locally; CI should run it in the DB-backed environment.
Summary by CodeRabbit
Improvements
Tests