hub (unreleased): four silent failures tell the operator (R-1383, D78)
gates / gates (push) Successful in 2m9s

A hub daily check skipped while the hub was down; an operator mail that was never sent; a signed job a box did not
take; a signed job a box refused, and the guest-power watchdog's give-up (both from the agent). Operator-only.
No new table. Not deployed.

Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
This commit is contained in:
admin committed 2026-11-14 17:29:53 +01:00
1 parent 88e636445a
commit 1886030782
22 files changed
+1269 -2

No files matched your search

+39 -1
View File
@@ -362,6 +362,18 @@ func main() {
)
apiHandler.SetDispatcher(dispatcher)
// R-1383 (D78, decision 299): three of the four silent failures are the hub's own. hubEvent leaves a row AND
// mails (the dispatcher keeps all of them operator-only). Pinned by r1383_wiring_test.go.
hubEvent := func(cust, typ, sev, msg, details, src string) {
if _, err := dataStore.SaveEvent(cust, typ, sev, msg, details, src); err != nil {
logger.Printf("[WARN] %s event save FAILED: %v", typ, err)
}
dispatcher.ProcessEvent(cust, typ, sev, msg, details, src)
}
// (1) a daily check whose slot passed while the hub was down — told at this start.
dailyLedger = monitor.NewDailyLedger(dataStore.OSAlarmRaised, dataStore.SetOSAlarmRaised, hubEvent, logger,
"deadline-check", "offsite-key-audit")
// MAIL-HOLD (internal/mailhold): while <data_dir>/MAIL-HOLD exists the hub sends NO e-mail on any path —
// dispatcher, /notify, app-mail relay. A hub started on a restored database mailed households within a minute
// (2026-10-09 restore drill); the marker makes a restored copy start quiet. Lifted by the operator with
@@ -915,6 +927,25 @@ func main() {
// durable (events table), so a hub restart neither floods nor silently re-heals.
// R-523: the agent's in-guest controller supervisor → controller_restarted_by_agent / controller_crashloop.
controllerSupervisorChecker := monitor.NewControllerSupervisorChecker(dataStore, dispatcher.ProcessEvent, logger)
// R-1383 (2) an operator mail that was never sent — told at this start, in one mail (after the mail hold is wired).
go dispatcher.ReportLostOperatorMails(time.Now())
// R-1383 (3) a signed job a box never took — on the 60 s sweep.
signedJobWaitChecker := monitor.NewSignedJobWaitChecker(
func() ([]monitor.PendingSignedJob, error) {
rows, err := dataStore.PendingSignedJobs()
out := make([]monitor.PendingSignedJob, 0, len(rows))
for _, r := range rows {
out = append(out, monitor.PendingSignedJob{HostID: r.HostID, JobID: r.JobID, CreatedAt: r.CreatedAt})
}
return out, err
},
func(hostID string) string {
if h, err := dataStore.GetHost(hostID); err == nil && h != nil {
return h.CustomerID
}
return ""
},
dataStore.OSAlarmRaised, dataStore.SetOSAlarmRaised, hubEvent, logger)
// D53 (`08` §10): a held app reaches the OPERATOR — one reminder after the grace per reason, then weekly.
var heldGrace time.Duration
if v := cfg.Alerting.HeldAppGraceOverride; v != "" {
@@ -957,7 +988,8 @@ func main() {
restoreTestChecker.Check() // R-85: restore-test failure + per-tier staleness
offsiteDeliveryChecker.Check()
controllerSupervisorChecker.Check()
heldAppsChecker.Check() // D53: throttled to one pass per 15 min
signedJobWaitChecker.Check() // R-1383: a signed job a box did not take in two hours
heldAppsChecker.Check() // D53: throttled to one pass per 15 min
if goldenVouchChecker != nil {
goldenVouchChecker.Check() // R-242: throttled to one Gitea listing per 15 min
}
@@ -1079,6 +1111,10 @@ func loadConfig(path string, logger *log.Logger) *Config {
return cfg
}
// dailyLedger remembers across a restart when a watched daily check last ran (R-1383). nil until main wires it; a nil
// ledger is safe to call.
var dailyLedger *monitor.DailyLedger
// scheduleDaily runs fn once daily at the given "HH:MM" time in Europe/Budapest.
// It blocks until ctx is cancelled.
func scheduleDaily(ctx context.Context, name, timeStr string, fn func(), logger *log.Logger) {
@@ -1088,6 +1124,7 @@ func scheduleDaily(ctx context.Context, name, timeStr string, fn func(), logger
}
hour, min := parseHM(timeStr)
dailyLedger.Started(name, time.Now(), hour, min, budapest) // R-1383: was the newest slot missed while the hub was down?
var last time.Time
for {
@@ -1101,6 +1138,7 @@ func scheduleDaily(ctx context.Context, name, timeStr string, fn func(), logger
case <-time.After(delay):
last = next
fn()
dailyLedger.Ran(name, next) // after fn: a hub that dies inside the check reads as "did not run"
}
}
}
+93
View File
@@ -0,0 +1,93 @@
package main
import (
"go/ast"
"go/parser"
"go/token"
"testing"
)
// R-1383 (D78): the three hub-side checks are components with seams; unit-green and never called is the inert-seam
// defect (four instances in this project). The wiring is asserted from main.go's AST: the ledger is built and
// assigned, the scheduler asks it at its start and tells it after each run, the lost-mail scan runs at a start, and
// the signed-job check is on the sweep. COMPANION RED-PROOFS: audits/night-build-2026-11-14/B/redproof-hub-wiring.txt.
func TestR1383_MainWiresTheSilentFailureChecks(t *testing.T) {
fset := token.NewFileSet()
f, err := parser.ParseFile(fset, "main.go", nil, 0)
if err != nil {
t.Fatalf("parse main.go: %v", err)
}
seen := map[string]int{}
inScheduler := map[string]int{}
callName := func(c *ast.CallExpr) (recv, name string) {
sel, ok := c.Fun.(*ast.SelectorExpr)
if !ok {
return "", ""
}
if id, ok := sel.X.(*ast.Ident); ok {
recv = id.Name
}
return recv, sel.Sel.Name
}
for _, d := range f.Decls {
fn, ok := d.(*ast.FuncDecl)
if !ok {
continue
}
ast.Inspect(fn, func(n ast.Node) bool {
switch node := n.(type) {
case *ast.AssignStmt:
if len(node.Lhs) == 1 && len(node.Rhs) == 1 {
if id, ok := node.Lhs[0].(*ast.Ident); ok && id.Name == "dailyLedger" {
if c, ok := node.Rhs[0].(*ast.CallExpr); ok {
if _, name := callName(c); name == "NewDailyLedger" {
seen["ledger built"]++
for _, a := range c.Args {
if lit, ok := a.(*ast.BasicLit); ok && (lit.Value == `"deadline-check"` || lit.Value == `"offsite-key-audit"`) {
seen["watched "+lit.Value]++
}
}
}
}
}
}
case *ast.CallExpr:
recv, name := callName(node)
switch {
case recv == "dailyLedger" && fn.Name.Name == "scheduleDaily":
inScheduler[name]++
case recv == "dispatcher" && name == "ReportLostOperatorMails":
seen["lost-mail scan"]++
case recv == "signedJobWaitChecker" && name == "Check":
seen["signed-job sweep"]++
}
}
return true
})
}
for _, k := range []string{"ledger built", `watched "deadline-check"`, `watched "offsite-key-audit"`, "lost-mail scan", "signed-job sweep"} {
if seen[k] != 1 {
t.Errorf("main.go: %s — found %d time(s), want 1", k, seen[k])
}
}
if inScheduler["Started"] != 1 || inScheduler["Ran"] != 1 {
t.Errorf("scheduleDaily calls the ledger: Started %d, Ran %d — want 1 and 1", inScheduler["Started"], inScheduler["Ran"])
}
// the names the ledger watches are the names the scheduler is started with
names := map[string]bool{}
ast.Inspect(f, func(n ast.Node) bool {
if c, ok := n.(*ast.CallExpr); ok {
if id, ok := c.Fun.(*ast.Ident); ok && id.Name == "scheduleDaily" && len(c.Args) > 1 {
if lit, ok := c.Args[1].(*ast.BasicLit); ok {
names[lit.Value] = true
}
}
}
return true
})
for _, n := range []string{`"deadline-check"`, `"offsite-key-audit"`} {
if !names[n] {
t.Errorf("no scheduleDaily job is named %s — the ledger watches a name nobody runs", n)
}
}
}