Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Fix RC3 backend release blockers

rcourtman53838d8f93bf
diff --git a/Makefile b/Makefile
index 09f49f36f8..cf6376d803 100644
--- a/Makefile
+++ b/Makefile
@@ -5,6 +5,7 @@
FRONTEND_DIR := frontend-modern
FRONTEND_DIST := $(FRONTEND_DIR)/dist
FRONTEND_EMBED_DIR := internal/api/frontend-modern
+GO_TEST_PACKAGES := ./cmd/... ./internal/... ./pkg/... ./scripts/... ./tests/...
# Build everything (including all agent binaries)
all: frontend backend build-agents
@@ -89,8 +90,8 @@ control-plane:
test:
@./scripts/ensure_test_assets.sh
- @echo "Running backend tests (excluding tmp tooling)..."
- go test -race -timeout 10m $$(go list ./... | grep -v '/tmp$$')
+ @echo "Running backend tests..."
+ go test -race -timeout 10m $$(go list $(GO_TEST_PACKAGES))
# Run integration tests (requires Ollama at OLLAMA_URL or 127.0.0.1:11434)
test-integration:
diff --git a/docker-compose.yml b/docker-compose.yml
index 2177065852..7a2df2a052 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -2,7 +2,7 @@ version: '3.8'
services:
pulse:
- image: ${PULSE_IMAGE:-rcourtman/pulse:6.0.0}
+ image: ${PULSE_IMAGE:-rcourtman/pulse:6.0.0-rc.3}
container_name: pulse
restart: unless-stopped
logging:
diff --git a/internal/ai/chat/agentic_test.go b/internal/ai/chat/agentic_test.go
index d4e0c22e4e..9e7ce6d13b 100644
--- a/internal/ai/chat/agentic_test.go
+++ b/internal/ai/chat/agentic_test.go
@@ -98,10 +98,13 @@ func TestAgenticLoop(t *testing.T) {
assert.NoError(t, err)
assert.Len(t, results, 1)
assert.Equal(t, "Hi there!", results[0].Content)
- assert.Len(t, events, 1) // Only "content" is forwarded by the loop closure switch
+ require.Len(t, events, 3)
+ assert.Equal(t, "workflow_state", events[0].Type)
+ assert.Equal(t, "content", events[1].Type)
+ assert.Equal(t, "workflow_state", events[2].Type)
var eventContent ContentData
- _ = json.Unmarshal(events[0].Data, &eventContent)
+ _ = json.Unmarshal(events[1].Data, &eventContent)
assert.Equal(t, "Hi there!", eventContent.Text)
})
diff --git a/internal/ai/cost/store.go b/internal/ai/cost/store.go
index 22d5de52ba..f75d813985 100644
--- a/internal/ai/cost/store.go
+++ b/internal/ai/cost/store.go
@@ -41,9 +41,10 @@ type Store struct {
persistence Persistence
// Debounced persistence to avoid frequent disk writes.
- saveTimer *time.Timer
- savePending bool
- saveDebounce time.Duration
+ saveTimer *time.Timer
+ saveTimerDone chan struct{}
+ savePending bool
+ saveDebounce time.Duration
// Error tracking for persistence
lastSaveError error
@@ -276,21 +277,34 @@ func (s *Store) GetSummary(days int) Summary {
// Flush immediately writes any pending changes to persistence.
func (s *Store) Flush() error {
s.mu.Lock()
- if s.saveTimer != nil {
- s.saveTimer.Stop()
- }
+ timerDone := s.stopSaveTimerLocked()
s.savePending = false
events := make([]UsageEvent, len(s.events))
copy(events, s.events)
p := s.persistence
s.mu.Unlock()
+ if timerDone != nil {
+ <-timerDone
+ }
if p != nil {
return p.SaveUsageHistory(events)
}
return nil
}
+func (s *Store) stopSaveTimerLocked() chan struct{} {
+ done := s.saveTimerDone
+ if s.saveTimer != nil {
+ if s.saveTimer.Stop() && done != nil {
+ close(done)
+ }
+ }
+ s.saveTimer = nil
+ s.saveTimerDone = nil
+ return done
+}
+
func (s *Store) trimLocked(now time.Time) {
if s.maxDays <= 0 {
return
@@ -310,12 +324,13 @@ func (s *Store) scheduleSaveLocked() {
return
}
- if s.saveTimer != nil {
- s.saveTimer.Stop()
- }
+ _ = s.stopSaveTimerLocked()
s.savePending = true
+ done := make(chan struct{})
+ s.saveTimerDone = done
s.saveTimer = time.AfterFunc(s.saveDebounce, func() {
+ defer close(done)
s.mu.Lock()
if !s.savePending {
s.mu.Unlock()
diff --git a/internal/ai/service.go b/internal/ai/service.go
index d126905a56..7d1eced559 100644
--- a/internal/ai/service.go
+++ b/internal/ai/service.go
@@ -1061,6 +1061,7 @@ func (s *Service) Stop() {
incidentStore := s.incidentStore
infraDiscovery := s.infraDiscoveryService
discoveryService := s.discoveryService
+ costStore := s.costStore
s.resourceExportStore = nil
s.resourceExportStoreOrgID = ""
defer s.mu.Unlock()
@@ -1076,6 +1077,12 @@ func (s *Service) Stop() {
discoveryService.Stop()
}
+ if costStore != nil {
+ if err := costStore.Flush(); err != nil {
+ log.Warn().Err(err).Msg("failed to flush AI usage cost store")
+ }
+ }
+
if store != nil {
if err := store.Close(); err != nil {
log.Warn().Err(err).Msg("failed to close unified resource export store")
diff --git a/internal/api/ai_handlers.go b/internal/api/ai_handlers.go
index c4f2d784ea..17f5b66f73 100644
--- a/internal/api/ai_handlers.go
+++ b/internal/api/ai_handlers.go
@@ -1531,6 +1531,28 @@ func (h *AISettingsHandler) StopPatrol() {
}
}
+// StopServices stops all AI services owned by the handler, including their
+// debounced persistence timers and background discovery/patrol workers.
+func (h *AISettingsHandler) StopServices() {
+ if h == nil {
+ return
+ }
+ if h.defaultAIService != nil {
+ h.defaultAIService.Stop()
+ }
+ h.aiServicesMu.RLock()
+ services := make([]*ai.Service, 0, len(h.aiServices))
+ for _, svc := range h.aiServices {
+ if svc != nil {
+ services = append(services, svc)
+ }
+ }
+ h.aiServicesMu.RUnlock()
+ for _, svc := range services {
+ svc.Stop()
+ }
+}
+
// StopPatrolForOrg stops patrol for a single org without affecting others.
func (h *AISettingsHandler) StopPatrolForOrg(orgID string) {
orgID = normalizeAIIntelligenceOrgID(orgID)
diff --git a/internal/api/recovery_tokens.go b/internal/api/recovery_tokens.go
index 8f06de668f..f10d3ea5a1 100644
--- a/internal/api/recovery_tokens.go
+++ b/internal/api/recovery_tokens.go
@@ -41,6 +41,7 @@ type RecoveryTokenStore struct {
mu sync.RWMutex
dataPath string
stopCleanup chan struct{}
+ cleanupDone chan struct{}
stopOnce sync.Once
}
@@ -106,6 +107,7 @@ func ensureRecoveryTokenStore(dataPath string) *RecoveryTokenStore {
tokens: make(map[string]*RecoveryToken),
dataPath: newDataPath,
stopCleanup: make(chan struct{}),
+ cleanupDone: make(chan struct{}),
}
recoveryStoreDataPath = newDataPath
recoveryStore.load()
@@ -220,6 +222,9 @@ func (r *RecoveryTokenStore) ValidateRecoveryTokenConstantTime(providedToken str
func (r *RecoveryTokenStore) cleanupRoutine() {
ticker := time.NewTicker(1 * time.Hour)
defer ticker.Stop()
+ if r.cleanupDone != nil {
+ defer close(r.cleanupDone)
+ }
for {
select {
@@ -237,8 +242,13 @@ func (r *RecoveryTokenStore) Shutdown() {
return
}
r.stopOnce.Do(func() {
- close(r.stopCleanup)
+ if r.stopCleanup != nil {
+ close(r.stopCleanup)
+ }
})
+ if r.cleanupDone != nil {
+ <-r.cleanupDone
+ }
}
func resetRecoveryStoreForTests() {
diff --git a/internal/api/router.go b/internal/api/router.go
index eecec43a9a..abff1a9dfc 100644
--- a/internal/api/router.go
+++ b/internal/api/router.go
@@ -2179,6 +2179,9 @@ func (r *Router) shutdownBackgroundWorkers() {
if r.recoveryTokenStore != nil {
r.recoveryTokenStore.Shutdown()
}
+ if r.aiSettingsHandler != nil {
+ r.aiSettingsHandler.StopServices()
+ }
if r.trueNASPoller != nil {
r.trueNASPoller.Stop()
}
diff --git a/internal/license/entitlements/evaluator_test.go b/internal/license/entitlements/evaluator_test.go
index 190bc7520e..20c2830650 100644
--- a/internal/license/entitlements/evaluator_test.go
+++ b/internal/license/entitlements/evaluator_test.go
@@ -277,7 +277,7 @@ func TestEvaluatorMeterEnabled(t *testing.T) {
}
func TestTokenSourceLegacyDerivation(t *testing.T) {
- t.Run("legacy claims", func(t *testing.T) {
+ t.Run("legacy self-hosted claims keep capabilities but scrub monitored-system caps", func(t *testing.T) {
claims := &license.Claims{
Tier: license.TierPro,
MaxMonitoredSystems: 25,
@@ -291,8 +291,8 @@ func TestTokenSourceLegacyDerivation(t *testing.T) {
}
limits := source.Limits()
- if got, ok := limits["max_monitored_systems"]; !ok || got != 25 {
- t.Fatalf("expected max_monitored_systems limit 25, got (%d, %t)", got, ok)
+ if got, ok := limits["max_monitored_systems"]; ok {
+ t.Fatalf("expected self-hosted Pro monitored-system limit to be scrubbed, got %d", got)
}
})
diff --git a/internal/relay/client.go b/internal/relay/client.go
index f83c0d6ab4..99a68b727a 100644
--- a/internal/relay/client.go
+++ b/internal/relay/client.go
@@ -462,19 +462,28 @@ func (c *Client) connectAndHandle(ctx context.Context) (bool, error) {
// goroutines spawned by handleData. Without this, stream goroutines
// would keep running against a stale sendCh until the whole client stops.
connCtx, connCancel := context.WithCancel(ctx)
- defer connCancel()
+ var connWG sync.WaitGroup
+ defer func() {
+ connCancel()
+ _ = conn.Close()
+ connWG.Wait()
+ }()
go func() {
<-connCtx.Done()
_ = conn.Close()
}()
- go c.writePump(connCtx, conn, sendCh)
+ connWG.Add(1)
+ go func() {
+ defer connWG.Done()
+ c.writePump(connCtx, conn, sendCh)
+ }()
// Read pump (blocking) — passes connCtx so handleData streams inherit it
// Rate-limit concurrent DATA stream handlers per connection.
dataLimiter := make(chan struct{}, maxConcurrentDataHandlers)
- return true, c.readPump(connCtx, conn, sendCh, dataLimiter)
+ return true, c.readPump(connCtx, conn, sendCh, dataLimiter, &connWG)
}
func relayTLSConfig() (*tls.Config, error) {
@@ -604,7 +613,7 @@ func (c *Client) register(conn *websocket.Conn) error {
}
}
-func (c *Client) readPump(ctx context.Context, conn *websocket.Conn, sendCh chan<- []byte, dataLimiter chan struct{}) error {
+func (c *Client) readPump(ctx context.Context, conn *websocket.Conn, sendCh chan<- []byte, dataLimiter chan struct{}, connWG *sync.WaitGroup) error {
for {
select {
case <-ctx.Done():
@@ -632,7 +641,7 @@ func (c *Client) readPump(ctx context.Context, conn *websocket.Conn, sendCh chan
c.handleKeyExchange(frame, sendCh)
case FrameData:
- c.handleData(ctx, frame, sendCh, dataLimiter)
+ c.handleData(ctx, frame, sendCh, dataLimiter, connWG)
case FrameChannelClose:
c.handleChannelClose(frame)
@@ -762,7 +771,7 @@ func (c *Client) handleChannelOpen(frame Frame, sendCh chan<- []byte) {
}
}
-func (c *Client) handleData(connCtx context.Context, frame Frame, sendCh chan<- []byte, dataLimiter chan struct{}) {
+func (c *Client) handleData(connCtx context.Context, frame Frame, sendCh chan<- []byte, dataLimiter chan struct{}, connWG *sync.WaitGroup) {
channelID := frame.Channel
// Snapshot channel state under lock so the goroutine below doesn't race
@@ -810,7 +819,13 @@ func (c *Client) handleData(connCtx context.Context, frame Frame, sendCh chan<-
}
// Handle in background goroutine so we don't block the read pump
+ if connWG != nil {
+ connWG.Add(1)
+ }
go func(payload []byte) {
+ if connWG != nil {
+ defer connWG.Done()
+ }
defer func() { <-dataLimiter }()
// Derive from the connection context so streams are cancelled on disconnect.
diff --git a/internal/relay/client_handshake_error_test.go b/internal/relay/client_handshake_error_test.go
index 2fb16a75fa..014ff9eb23 100644
--- a/internal/relay/client_handshake_error_test.go
+++ b/internal/relay/client_handshake_error_test.go
@@ -155,7 +155,7 @@ func TestClientReadPump_ReturnsLicenseError(t *testing.T) {
}
defer conn.Close()
- err = client.readPump(context.Background(), conn, make(chan []byte, 1), make(chan struct{}, 1))
+ err = client.readPump(context.Background(), conn, make(chan []byte, 1), make(chan struct{}, 1), nil)
if err == nil {
t.Fatal("expected readPump() to return license error")
}
diff --git a/internal/relay/client_license_lifecycle_test.go b/internal/relay/client_license_lifecycle_test.go
index 0311c3a345..cb4fdbc9b9 100644
--- a/internal/relay/client_license_lifecycle_test.go
+++ b/internal/relay/client_license_lifecycle_test.go
@@ -473,7 +473,7 @@ func TestRunLoop_LicenseErrorIsDetectedByIsLicenseError(t *testing.T) {
}
defer wsConn.Close()
- rpErr := client.readPump(context.Background(), wsConn, make(chan []byte, 1), make(chan struct{}, 1))
+ rpErr := client.readPump(context.Background(), wsConn, make(chan []byte, 1), make(chan struct{}, 1), nil)
if rpErr == nil {
t.Fatal("expected readPump() to return error")
}
@@ -512,7 +512,7 @@ func TestRunLoop_NonLicenseErrorIsNotLicenseError(t *testing.T) {
}
defer wsConn.Close()
- rpErr := client.readPump(context.Background(), wsConn, make(chan []byte, 1), make(chan struct{}, 1))
+ rpErr := client.readPump(context.Background(), wsConn, make(chan []byte, 1), make(chan struct{}, 1), nil)
// Non-license errors either return nil or a non-license error
if rpErr != nil && isLicenseError(rpErr) {
t.Errorf("isLicenseError() = true for non-license code %q", code)
diff --git a/internal/relay/client_test.go b/internal/relay/client_test.go
index 44ed094f4b..a84b037713 100644
--- a/internal/relay/client_test.go
+++ b/internal/relay/client_test.go
@@ -1004,7 +1004,7 @@ func TestClient_HandleDataDecryptsBeforeReturning(t *testing.T) {
done := make(chan struct{})
go func() {
- client.handleData(context.Background(), frame, sendCh, dataLimiter)
+ client.handleData(context.Background(), frame, sendCh, dataLimiter, nil)
close(done)
}()
diff --git a/internal/websocket/hub.go b/internal/websocket/hub.go
index 8962fd6704..bb628bddf6 100644
--- a/internal/websocket/hub.go
+++ b/internal/websocket/hub.go
@@ -405,6 +405,10 @@ type Hub struct {
unregister chan *Client
stopChan chan struct{} // Signals shutdown
stopOnce sync.Once
+ runStarted chan struct{}
+ runDone chan struct{}
+ runStartOnce sync.Once
+ runDoneOnce sync.Once
mu sync.RWMutex
getState func(orgID string) interface{} // Function to get state for specific tenant
allowedOrigins []string // Allowed origins for CORS
@@ -488,6 +492,8 @@ func NewHub(getState func(orgID string) interface{}) *Hub {
register: make(chan *Client),
unregister: make(chan *Client),
stopChan: make(chan struct{}),
+ runStarted: make(chan struct{}),
+ runDone: make(chan struct{}),
getState: getState,
allowedOrigins: []string{}, // Default to empty (will be set based on actual host)
coalesceWindow: 100 * time.Millisecond, // Coalesce rapid updates within 100ms
@@ -498,8 +504,22 @@ func NewHub(getState func(orgID string) interface{}) *Hub {
// Run starts the hub's main loop
func (h *Hub) Run() {
+ h.runStartOnce.Do(func() {
+ close(h.runStarted)
+ })
+
// Start broadcast sequencer goroutine
- go h.runBroadcastSequencer()
+ sequencerDone := make(chan struct{})
+ go func() {
+ defer close(sequencerDone)
+ h.runBroadcastSequencer()
+ }()
+ defer func() {
+ <-sequencerDone
+ h.runDoneOnce.Do(func() {
+ close(h.runDone)
+ })
+ }()
log.Info().Msg("WebSocket state payload configured for unified resources")
pingTicker := time.NewTicker(30 * time.Second)
@@ -660,6 +680,11 @@ func (h *Hub) Stop() {
h.stopOnce.Do(func() {
close(h.stopChan)
})
+ select {
+ case <-h.runStarted:
+ <-h.runDone
+ default:
+ }
}
func (h *Hub) isStopping() bool {
diff --git a/scripts/generate-self-hosted-feature-catalog.go b/scripts/generate-self-hosted-feature-catalog.go
index 2fee503bca..41107d4369 100644
--- a/scripts/generate-self-hosted-feature-catalog.go
+++ b/scripts/generate-self-hosted-feature-catalog.go
@@ -1,3 +1,5 @@
+//go:build ignore
+
package main
import (
diff --git a/scripts/generate-types.go b/scripts/generate-types.go
index 418ba4b950..dfe521576c 100644
--- a/scripts/generate-types.go
+++ b/scripts/generate-types.go
@@ -10,6 +10,8 @@
// Output:
//
// frontend-modern/src/api/generated/aiChatEvents.ts
+//go:build ignore
+
package main
import (
diff --git a/scripts/install-docker.sh b/scripts/install-docker.sh
index 10347414c8..64c833691a 100755
--- a/scripts/install-docker.sh
+++ b/scripts/install-docker.sh
@@ -6,7 +6,7 @@ set -euo pipefail
SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
DOCKER_IMAGE_REPO="${DOCKER_IMAGE_REPO:-rcourtman/pulse}"
-CANONICAL_DEFAULT_PULSE_VERSION="6.0.0"
+CANONICAL_DEFAULT_PULSE_VERSION="6.0.0-rc.3"
resolve_default_pulse_version() {
if [ -n "${PULSE_IMAGE_VERSION:-}" ]; then
diff --git a/scripts/release_update_key.go b/scripts/release_update_key.go
index 0219de33c1..a53b7af618 100644
--- a/scripts/release_update_key.go
+++ b/scripts/release_update_key.go
@@ -1,3 +1,5 @@
+//go:build ignore
+
package main
import (
diff --git a/scripts/render_installers.go b/scripts/render_installers.go
index 0d13456287..7c4f0169c8 100644
--- a/scripts/render_installers.go
+++ b/scripts/render_installers.go
@@ -1,3 +1,5 @@
+//go:build ignore
+
package main
import (
diff --git a/tests/migration/v5_full_upgrade_test.go b/tests/migration/v5_full_upgrade_test.go
index 7dc247add3..f4e19be7f3 100644
--- a/tests/migration/v5_full_upgrade_test.go
+++ b/tests/migration/v5_full_upgrade_test.go
@@ -201,7 +201,7 @@ func newMigrationTestServer(t *testing.T, dataDir string) *httptest.Server {
router := api.NewRouter(cfg, monitor, nil, hub, func() error {
monitor.SyncAlertState()
return nil
- }, "6.0.0-test", nil)
+ }, "6.0.0-test")
ln, err := net.Listen("tcp4", "127.0.0.1:0")
if err != nil {