fix(awooop): surface legacy HITL backlog
All checks were successful
CD Pipeline / tests (push) Successful in 1m31s
Code Review / ai-code-review (push) Successful in 12s
CD Pipeline / build-and-deploy (push) Successful in 3m40s
CD Pipeline / post-deploy-checks (push) Successful in 1m38s

This commit is contained in:
Your Name
2026-05-25 23:46:50 +08:00
parent a21cb05af3
commit 88b19259c5
5 changed files with 284 additions and 9 deletions

View File

@@ -20,6 +20,7 @@ from pydantic import BaseModel
from src.core.config import settings
from src.core.logging import get_logger
from src.core.sse import EventPublisher, EventType, SSEEvent, get_publisher
from src.services.dashboard_metrics_service import fetch_pending_approval_count
from src.services.host_aggregator import AggregatedStatus, HostAggregator
router = APIRouter()
@@ -141,12 +142,14 @@ async def dashboard_update_loop(publisher: EventPublisher) -> None:
try:
# Fetch aggregated status
status = await HostAggregator.fetch_all()
pending_approvals = await fetch_pending_approval_count()
# Publish to all connected clients
event = SSEEvent(
type=EventType.HOST_UPDATE,
data={
"overall_status": status.overall_status,
"pending_approvals": pending_approvals,
"hosts": [
{
"ip": h.ip,
@@ -206,7 +209,9 @@ async def get_dashboard() -> DashboardResponse:
logger.info("dashboard_fetch")
status = await HostAggregator.fetch_all()
return aggregated_to_response(status)
response = aggregated_to_response(status)
response.pending_approvals = await fetch_pending_approval_count()
return response
@router.get("/dashboard/stream")

View File

@@ -0,0 +1,31 @@
"""
Dashboard Metrics Service
=========================
Small DB-backed counters used by the war-room dashboard.
"""
from sqlalchemy import text
from src.core.logging import get_logger
from src.db.base import get_db_context
logger = get_logger("awoooi.dashboard_metrics")
async def fetch_pending_approval_count() -> int:
"""Read the live HITL backlog from approval_records."""
try:
async with get_db_context() as db:
result = await db.execute(
text(
"""
SELECT count(*)
FROM approval_records
WHERE upper(status::text) = 'PENDING'
"""
)
)
return int(result.scalar_one() or 0)
except Exception as exc:
logger.warning("dashboard_pending_approval_count_failed", error=str(exc))
return 0