hub: F2 — alert on host already degraded/stale at (re)start (seed only healthy) v0.21.0

Constructors seed only healthy hosts; an already-degraded/stale host is left unseeded so the first
Check() emits once (cooldown dedups on hub restart). Born-degraded red-proof + staleness test updated.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pg8ANF97SEeKYSN5Jxw3qJ
This commit is contained in:
2026-06-29 21:46:25 +02:00
parent a297639c58
commit 12f038618e
5 changed files with 79 additions and 16 deletions
+15 -5
View File
@@ -53,14 +53,17 @@ func NewHostCapabilityChecker(s *store.Store, onEvent EventNotifyFunc, logger *l
}
cc.customerOf[row.HostID] = row.CustomerID
st, _, _ := capabilityState(row.Capabilities)
cc.states[row.HostID] = st
// F2: seed only HEALTHY hosts. A host already degraded at (re)start is left UNSEEDED so the
// first Check() observes oldState=="" and emits once — otherwise a box already broken when the
// hub restarts would stay silent forever. The dispatcher's 1h cooldown dedups the re-emit.
if st == "degraded" {
degCount++
} else {
okCount++
continue
}
cc.states[row.HostID] = st
okCount++
}
logger.Printf("[INFO] Host capability checker initialized: %d ok, %d degraded", okCount, degCount)
logger.Printf("[INFO] Host capability checker initialized: %d ok, %d degraded (degraded left unseeded → first Check emits)", okCount, degCount)
return cc
}
@@ -87,7 +90,14 @@ func (cc *HostCapabilityChecker) Check() {
newState, names, features := capabilityState(row.Capabilities)
oldState := cc.states[row.HostID]
if oldState == "" {
cc.states[row.HostID] = newState // first observation — no event
// F2: first observation (incl. a hub restart). A healthy first-obs seeds silently; a host
// already DEGRADED at first sight emits once (else a host that was already broken when the
// hub (re)started would never alert). The dispatcher's 1h operator cooldown dedups a re-emit
// across a hub restart.
cc.states[row.HostID] = newState
if newState == "degraded" {
cc.emitTransition(row.HostID, row.CustomerID, "unknown", newState, names, features)
}
continue
}
if oldState == newState {