fix: ws health_update — add coverage pillar + gate broadcast on valid computed score

Coverage pillar was added to mesh_routes.py in 15f2b6c but missed in
the WebSocket serializer, sending undefined for coverage on every WS
push. Also gates the initial health_update broadcast on composite > 0
and infra_total > 0 to prevent partially-initialized HealthScore from
overwriting good REST-fetched data on the frontend.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Matt Johnson (via Claude) 2026-06-10 05:57:58 +00:00
commit a119de7d86

View file

@ -69,6 +69,7 @@ def _serialize_health(mesh_health) -> dict:
"pillars": {
"infrastructure": round(score.infrastructure, 1),
"utilization": round(score.utilization, 1),
"coverage": round(score.coverage, 1),
"behavior": round(score.behavior, 1),
"power": round(score.power, 1),
},
@ -100,10 +101,12 @@ async def ws_endpoint(websocket: WebSocket):
# Send initial state snapshot on connect
health_engine = getattr(app_state, "health_engine", None)
if health_engine and health_engine.mesh_health:
await websocket.send_json({
"type": "health_update",
"data": _serialize_health(health_engine.mesh_health)
})
score = health_engine.mesh_health.score
if score.composite > 0 and score.infra_total > 0:
await websocket.send_json({
"type": "health_update",
"data": _serialize_health(health_engine.mesh_health)
})
# Keep connection alive, receive client keepalive pings
while True: