From 96f683a72aad95122dc7500e3251d9cc4185dff4 Mon Sep 17 00:00:00 2001 From: AetherForge Date: Tue, 2 Jun 2026 22:02:34 -0700 Subject: [PATCH] Guard NewWSHub nil-db path to fix test suite flake --- server/internal/api/websocket.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/server/internal/api/websocket.go b/server/internal/api/websocket.go index 5d2c308..c7b072e 100644 --- a/server/internal/api/websocket.go +++ b/server/internal/api/websocket.go @@ -121,8 +121,10 @@ type WSHub struct { func NewWSHub(database *db.Database) *WSHub { // Reset any rows that were left "online" by a previous server crash/restart. // Agents will re-authenticate and flip themselves back to online within seconds. - if err := database.MarkAllAgentsOffline(); err != nil { - log.Printf("[hub] startup offline reset: %v", err) + if database != nil { + if err := database.MarkAllAgentsOffline(); err != nil { + log.Printf("[hub] startup offline reset: %v", err) + } } h := &WSHub{ @@ -148,6 +150,9 @@ func NewWSHub(database *db.Database) *WSHub { // last_seen timestamp is stale (> 3 minutes without a stats message). // It also notifies the dashboard so client state stays in sync. func (h *WSHub) runStaleAgentSweep() { + if h.db == nil { + return + } const staleness = 3 * time.Minute ticker := time.NewTicker(45 * time.Second) defer ticker.Stop()