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.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
chore(alerts): delete the legacy transition-state maps
rcourtman6eee5a16413c
diff --git a/internal/alerts/active_cleanup.go b/internal/alerts/active_cleanup.goindex b86e7b4b58..94c6c6a6d4 100644--- a/internal/alerts/active_cleanup.go+++ b/internal/alerts/active_cleanup.go@@ -143,16 +143,9 @@ func (m *Manager) Cleanup(maxAge time.Duration) {m.pruneRecentlyResolvedUnlocked(now)m.resolvedMutex.Unlock()- maxPendingAge := 10 * time.Minute- for id, pendingTime := range m.pendingAlerts {- if now.Sub(pendingTime) > maxPendingAge {- delete(m.pendingAlerts, id)- log.Debug().- Str("resourceID", id).- Dur("age", now.Sub(pendingTime)).- Msg("Cleaned up stale pending alert entry")- }- }+ // Pending confirmation/delay runs whose resource stopped being observed+ // mid-run would otherwise linger in the core forever.+ m.core.PruneStalePending(now.Add(-10 * time.Minute))flappingCleanupAge := 1 * time.Hourfor alertID := range m.flappingHistory {@@ -321,23 +314,18 @@ func (m *Manager) CleanupAlertsForNodes(existingNodes map[string]bool) {// ClearActiveAlerts removes all active and pending alerts, resetting the manager state.func (m *Manager) ClearActiveAlerts() {m.mu.Lock()- if len(m.activeAlerts) == 0 && len(m.pendingAlerts) == 0 && len(m.intentPending) == 0 {+ if len(m.activeAlerts) == 0 && len(m.intentPending) == 0 {m.mu.Unlock()return}m.activeAlerts = make(map[string]*Alert)m.activeAlertAlias = make(map[string]string)- m.pendingAlerts = make(map[string]time.Time)+ m.core.Reset()m.intentPending = make(map[string]IntentPendingState)m.intentRuntimeTicks = make(map[string]time.Duration)m.recentAlerts = make(map[string]*Alert)m.suppressedUntil = make(map[string]time.Time)m.alertRateLimit = make(map[string][]time.Time)- m.nodeOfflineCount = make(map[string]int)- m.offlineConfirmations = make(map[string]int)- m.offlineRecoveryConfirmations = make(map[string]int)- m.dockerOfflineCount = make(map[string]int)- m.dockerStateConfirm = make(map[string]int)m.dockerRestartTracking = make(map[string]*dockerRestartRecord)m.dockerUpdateFirstSeen = make(map[string]time.Time)m.dockerUpdateFirstSeenByIdentity = make(map[string]time.Time)diff --git a/internal/alerts/active_lifecycle.go b/internal/alerts/active_lifecycle.goindex d2a2936c32..d65571cb8c 100644--- a/internal/alerts/active_lifecycle.go+++ b/internal/alerts/active_lifecycle.go@@ -567,10 +567,8 @@ func (m *Manager) removeActiveAlertNoLock(alertID string) {m.unregisterActiveAlertAliasNoLock(key, alert)}if exists {- delete(m.offlineRecoveryConfirmations, key)delete(m.activeAlerts, key)}- delete(m.offlineRecoveryConfirmations, alertID)// Preserve acknowledgement state so quick alert rebuilds keep user intent.if exists {@@ -578,27 +576,6 @@ func (m *Manager) removeActiveAlertNoLock(alertID string) {}}-func (m *Manager) confirmOfflineRecoveryNoLock(alertID string, required int) (int, bool) {- alertID = strings.TrimSpace(alertID)- if alertID == "" {- return 0, false- }-- if required <= 1 {- delete(m.offlineRecoveryConfirmations, alertID)- return required, true- }-- m.offlineRecoveryConfirmations[alertID]++- confirmations := m.offlineRecoveryConfirmations[alertID]- if confirmations < required {- return confirmations, false- }-- delete(m.offlineRecoveryConfirmations, alertID)- return confirmations, true-}-// clearResourceOfflineAlert removes an offline alert when a poll-driven resource// stays healthy for enough consecutive polls to confirm recovery. The// reducer core owns the recovery gate.@@ -636,16 +613,6 @@ func (m *Manager) resolveDiscreteRecoveryNoLock(resourceID, specKey, alertID strObservedAt: time.Now(),}, reducer.DiscreteRule{RecoveryConfirmations: requiredRecoveryCount})- // Legacy-map mirrors (read-only during Phase 2; deleted in Phase 3):- // a healthy poll clears any confirmation-run mirror and reflects the- // core's recovery count.- delete(m.offlineConfirmations, resourceID)- if incident, tracked := m.core.Incident(resourceID, specKey); tracked && incident.RecoveryCount > 0 {- m.offlineRecoveryConfirmations[alertID] = incident.RecoveryCount- } else {- delete(m.offlineRecoveryConfirmations, alertID)- }-alert, exists := m.getActiveAlertNoLock(alertID)if !exists {return@@ -696,12 +663,10 @@ func (m *Manager) ClearAlert(alertID string) bool {m.clearAlertNoLock(alertID)delete(m.recentAlerts, alertID)- delete(m.pendingAlerts, alertID)delete(m.suppressedUntil, alertID)delete(m.alertRateLimit, alertID)if trackingKey != "" && trackingKey != alertID {delete(m.recentAlerts, trackingKey)- delete(m.pendingAlerts, trackingKey)delete(m.suppressedUntil, trackingKey)delete(m.alertRateLimit, trackingKey)}diff --git a/internal/alerts/alerts_test.go b/internal/alerts/alerts_test.goindex ce5690b258..0fb3e2b1cb 100644--- a/internal/alerts/alerts_test.go+++ b/internal/alerts/alerts_test.go@@ -13,6 +13,7 @@ import ("time""github.com/rcourtman/pulse-go-rewrite/internal/alerts/eventlog"+ "github.com/rcourtman/pulse-go-rewrite/internal/alerts/reducer"alertspecs "github.com/rcourtman/pulse-go-rewrite/internal/alerts/specs""github.com/rcourtman/pulse-go-rewrite/internal/models""github.com/rcourtman/pulse-go-rewrite/internal/proxmoxidentity"@@ -582,7 +583,7 @@ func TestCheckGuestSkipsAlertsWhenMetricDisabled(t *testing.T) {}m.mu.RLock()- _, isPending := m.pendingAlerts[canonicalMetricStateID(vmID, "cpu")]+ isPending := testCoreIsPending(m, vmID, canonicalMetricSpecID(vmID, "cpu"))m.mu.RUnlock()if isPending {t.Fatalf("expected pending alert entry to be cleared after disabling metric")@@ -752,7 +753,7 @@ func TestClearAlertByCanonicalAliasRemovesActiveState(t *testing.T) {canonicalState := buildCanonicalStateID(resourceID, "metric-threshold:cpu")now := time.Now()alert := &Alert{- ID: "legacy-guest-200-cpu",+ ID: "guest-200-cpu",Type: "cpu",Level: AlertLevelWarning,ResourceID: resourceID,@@ -766,7 +767,7 @@ func TestClearAlertByCanonicalAliasRemovesActiveState(t *testing.T) {m.mu.Lock()m.setActiveAlertNoLock(alert.ID, alert)- m.pendingAlerts[canonicalState] = now+ m.core.ApplyDiscrete(reducer.DiscreteSignal{ResourceID: resourceID, Key: "metric-threshold:cpu", Matched: true, Severity: reducer.SeverityWarning, ObservedAt: now}, reducer.DiscreteRule{Confirmations: 3})m.suppressedUntil[canonicalState] = now.Add(time.Minute)m.alertRateLimit[canonicalState] = []time.Time{now}m.mu.Unlock()@@ -777,7 +778,7 @@ func TestClearAlertByCanonicalAliasRemovesActiveState(t *testing.T) {m.mu.RLock()_, active := m.getActiveAlertNoLock(canonicalState)- _, pending := m.pendingAlerts[canonicalState]+ pending := testCoreIsPending(m, resourceID, "metric-threshold:cpu")_, suppressed := m.suppressedUntil[canonicalState]_, rateLimited := m.alertRateLimit[canonicalState]m.mu.RUnlock()@@ -842,8 +843,6 @@ func TestHandleDockerHostRemovedClearsAlertsAndTracking(t *testing.T) {m.setActiveAlertNoLock(hostStorageKey, hostAlert)containerStorageKey, containerAlert := testNewCanonicalAlert(containerResourceID, canonicalDiscreteStateSpecID(containerResourceID, "runtime-state"), "discrete-state", "docker-container-state")m.setActiveAlertNoLock(containerStorageKey, containerAlert)- m.dockerOfflineCount[host.ID] = 2- m.dockerStateConfirm[containerResourceID] = 1m.dockerRestartTracking[containerResourceID] = &dockerRestartRecord{}m.mu.Unlock()@@ -858,10 +857,10 @@ func TestHandleDockerHostRemovedClearsAlertsAndTracking(t *testing.T) {if testHasActiveAlert(t, m, hostAlertID) {t.Fatalf("expected host offline alert to be cleared")}- if _, exists := m.dockerOfflineCount[host.ID]; exists {+ if testCoreHasIncident(m, "docker:"+host.ID, canonicalConnectivitySpecID("docker:"+host.ID)) {t.Fatalf("expected offline tracking to be cleared")}- if _, exists := m.dockerStateConfirm[containerResourceID]; exists {+ if testCoreHasIncident(m, containerResourceID, canonicalDiscreteStateSpecID(containerResourceID, "runtime-state")) {t.Fatalf("expected state confirmation to be cleared")}if _, exists := m.dockerRestartTracking[containerResourceID]; exists {@@ -1007,7 +1006,7 @@ func TestHandleHostOfflineRequiresConfirmations(t *testing.T) {if testHasActiveAlert(t, m, alertID) {t.Fatalf("expected no alert after first offline detection")}- if count := m.offlineConfirmations[resourceKey]; count != 1 {+ if count := testCoreConfirmations(m, resourceKey, canonicalConnectivitySpecID(resourceKey)); count != 1 {t.Fatalf("expected confirmation count to be 1, got %d", count)}m.mu.RUnlock()@@ -1017,7 +1016,7 @@ func TestHandleHostOfflineRequiresConfirmations(t *testing.T) {if testHasActiveAlert(t, m, alertID) {t.Fatalf("expected no alert after second offline detection")}- if count := m.offlineConfirmations[resourceKey]; count != 2 {+ if count := testCoreConfirmations(m, resourceKey, canonicalConnectivitySpecID(resourceKey)); count != 2 {t.Fatalf("expected confirmation count to be 2, got %d", count)}m.mu.RUnlock()@@ -1034,7 +1033,7 @@ func TestHandleHostOfflineRequiresConfirmations(t *testing.T) {if testHasActiveAlert(t, m, alertID) {t.Fatalf("expected offline alert %q to be cleared after host online", alertID)}- if _, exists := m.offlineConfirmations[resourceKey]; exists {+ if testCoreHasIncident(m, resourceKey, canonicalConnectivitySpecID(resourceKey)) {t.Fatalf("expected offline confirmations to be cleared when host online")}m.mu.RUnlock()@@ -2579,7 +2578,7 @@ func TestCheckDockerHostIgnoresContainersByPrefix(t *testing.T) {if testHasActiveAlert(t, m, alertID) {t.Fatalf("expected no state alert for ignored container")}- if _, exists := m.dockerStateConfirm[resourceID]; exists {+ if testCoreHasIncident(m, resourceID, canonicalDiscreteStateSpecID(resourceID, "runtime-state")) {t.Fatalf("expected no state confirmation tracking for ignored container")}}@@ -3642,7 +3641,6 @@ func TestCheckDockerHostIgnoredPrefixClearsExistingAlerts(t *testing.T) {m.activeAlerts[stateAlertID] = &Alert{ID: stateAlertID, ResourceID: resourceID}m.activeAlerts[healthAlertID] = &Alert{ID: healthAlertID, ResourceID: resourceID}m.activeAlerts[restartAlertID] = &Alert{ID: restartAlertID, ResourceID: resourceID}- m.dockerStateConfirm[resourceID] = 2m.dockerRestartTracking[resourceID] = &dockerRestartRecord{}m.mu.Unlock()@@ -3660,7 +3658,7 @@ func TestCheckDockerHostIgnoredPrefixClearsExistingAlerts(t *testing.T) {if testHasActiveAlert(t, m, restartAlertID) {t.Fatalf("expected restart alert cleared for ignored container")}- if _, exists := m.dockerStateConfirm[resourceID]; exists {+ if testCoreHasIncident(m, resourceID, canonicalDiscreteStateSpecID(resourceID, "runtime-state")) {t.Fatalf("expected state confirmation tracking cleared")}if _, exists := m.dockerRestartTracking[resourceID]; exists {@@ -4594,7 +4592,7 @@ func TestDisableAllStorageClearsExistingAlerts(t *testing.T) {// Pending alert should be clearedm.mu.RLock()- _, isPending := m.pendingAlerts[canonicalMetricStateID(storageID, "usage")]+ isPending := testCoreIsPending(m, storageID, canonicalMetricSpecID(storageID, "usage"))m.mu.RUnlock()if isPending {t.Fatalf("expected pending alert entry to be cleared after disabling all storage")@@ -6017,7 +6015,6 @@ func TestClearStorageOfflineAlert(t *testing.T) {Level: "critical",StartTime: time.Now().Add(-10 * time.Minute),}- m.offlineConfirmations[storage.ID] = 3m.mu.Unlock()resolvedCh := make(chan string, 1)@@ -6028,7 +6025,7 @@ func TestClearStorageOfflineAlert(t *testing.T) {m.clearStorageOfflineAlert(storage)m.mu.RLock()_, existsAfterFirst := testLookupActiveAlert(t, m, alertID)- recoveryCountAfterFirst := m.offlineRecoveryConfirmations[canonicalConnectivityStateID(storage.ID)]+ recoveryCountAfterFirst := testCoreRecoveryCount(m, storage.ID, canonicalConnectivitySpecID(storage.ID))m.mu.RUnlock()if !existsAfterFirst {t.Fatal("expected storage alert to remain active until recovery confirmations are satisfied")@@ -6041,7 +6038,7 @@ func TestClearStorageOfflineAlert(t *testing.T) {m.mu.RLock()_, alertExists := testLookupActiveAlert(t, m, alertID)- _, confirmExists := m.offlineConfirmations[storage.ID]+ confirmExists := testCoreHasIncident(m, storage.ID, canonicalConnectivitySpecID(storage.ID))m.mu.RUnlock()if alertExists {@@ -6095,13 +6092,13 @@ func TestClearStorageOfflineAlert(t *testing.T) {// Set confirmation without alertm.mu.Lock()- m.offlineConfirmations[storage.ID] = 2+ m.core.ApplyDiscrete(reducer.DiscreteSignal{ResourceID: storage.ID, Key: canonicalConnectivitySpecID(storage.ID), Matched: true, Severity: reducer.SeverityCritical, ObservedAt: time.Now()}, reducer.DiscreteRule{Confirmations: 3})m.mu.Unlock()m.clearStorageOfflineAlert(storage)m.mu.RLock()- _, confirmExists := m.offlineConfirmations[storage.ID]+ confirmExists := testCoreHasIncident(m, storage.ID, canonicalConnectivitySpecID(storage.ID))m.mu.RUnlock()if confirmExists {@@ -6466,7 +6463,7 @@ func TestHandleDockerHostRemovedEmptyID(t *testing.T) {// Create some alerts that should not be touchedm.mu.Lock()m.activeAlerts["docker-host-offline-host1"] = &Alert{ID: "docker-host-offline-host1"}- m.dockerOfflineCount["host1"] = 3+ m.core.ApplyDiscrete(reducer.DiscreteSignal{ResourceID: "docker:host1", Key: canonicalConnectivitySpecID("docker:host1"), Matched: true, Severity: reducer.SeverityCritical, ObservedAt: time.Now()}, reducer.DiscreteRule{Confirmations: 3})m.mu.Unlock()// Call with empty ID - should be noop@@ -6475,7 +6472,7 @@ func TestHandleDockerHostRemovedEmptyID(t *testing.T) {m.mu.RLock()_, alertExists := testLookupActiveAlert(t, m, "docker-host-offline-host1")- _, countExists := m.dockerOfflineCount["host1"]+ countExists := testCoreHasIncident(m, "docker:host1", canonicalConnectivitySpecID("docker:host1"))m.mu.RUnlock()if !alertExists {@@ -6499,14 +6496,13 @@ func TestHandleDockerHostOnline(t *testing.T) {// Set up offline alert and trackingm.mu.Lock()m.activeAlerts[alertID] = &Alert{ID: alertID, ResourceID: fmt.Sprintf("docker:%s", host.ID)}- m.dockerOfflineCount[host.ID] = 5m.mu.Unlock()m.HandleDockerHostOnline(host)m.mu.RLock()_, alertExists := testLookupActiveAlert(t, m, alertID)- _, countExists := m.dockerOfflineCount[host.ID]+ countExists := testCoreHasIncident(m, "docker:"+host.ID, canonicalConnectivitySpecID("docker:"+host.ID))m.mu.RUnlock()if alertExists {@@ -6525,13 +6521,13 @@ func TestHandleDockerHostOnline(t *testing.T) {// Set up only tracking, no alertm.mu.Lock()- m.dockerOfflineCount[host.ID] = 2+ m.core.ApplyDiscrete(reducer.DiscreteSignal{ResourceID: "docker:" + host.ID, Key: canonicalConnectivitySpecID("docker:" + host.ID), Matched: true, Severity: reducer.SeverityCritical, ObservedAt: time.Now()}, reducer.DiscreteRule{Confirmations: 3})m.mu.Unlock()m.HandleDockerHostOnline(host)m.mu.RLock()- _, countExists := m.dockerOfflineCount[host.ID]+ countExists := testCoreHasIncident(m, "docker:"+host.ID, canonicalConnectivitySpecID("docker:"+host.ID))m.mu.RUnlock()if countExists {@@ -6546,7 +6542,7 @@ func TestHandleDockerHostOnline(t *testing.T) {// Create some data that should not be touchedm.mu.Lock()m.activeAlerts["docker-host-offline-other"] = &Alert{ID: "docker-host-offline-other"}- m.dockerOfflineCount["other"] = 3+ m.core.ApplyDiscrete(reducer.DiscreteSignal{ResourceID: "docker:other", Key: canonicalConnectivitySpecID("docker:other"), Matched: true, Severity: reducer.SeverityCritical, ObservedAt: time.Now()}, reducer.DiscreteRule{Confirmations: 3})m.mu.Unlock()host := models.DockerHost{ID: ""}@@ -6554,7 +6550,7 @@ func TestHandleDockerHostOnline(t *testing.T) {m.mu.RLock()_, alertExists := testLookupActiveAlert(t, m, "docker-host-offline-other")- _, countExists := m.dockerOfflineCount["other"]+ countExists := testCoreHasIncident(m, "docker:other", canonicalConnectivitySpecID("docker:other"))m.mu.RUnlock()if !alertExists {@@ -6590,9 +6586,9 @@ func TestCleanupDockerContainerAlerts(t *testing.T) {ID: "container3-alert",ResourceID: prefix + "container3",}- m.dockerStateConfirm[prefix+"container1"] = 2- m.dockerStateConfirm[prefix+"container2"] = 1- m.dockerStateConfirm[prefix+"container3"] = 3+ m.core.ApplyDiscrete(reducer.DiscreteSignal{ResourceID: prefix + "container1", Key: canonicalDiscreteStateSpecID(prefix+"container1", "runtime-state"), Matched: true, Severity: reducer.SeverityWarning, ObservedAt: time.Now()}, reducer.DiscreteRule{Confirmations: 3})+ m.core.ApplyDiscrete(reducer.DiscreteSignal{ResourceID: prefix + "container2", Key: canonicalDiscreteStateSpecID(prefix+"container2", "runtime-state"), Matched: true, Severity: reducer.SeverityWarning, ObservedAt: time.Now()}, reducer.DiscreteRule{Confirmations: 3})+ m.core.ApplyDiscrete(reducer.DiscreteSignal{ResourceID: prefix + "container3", Key: canonicalDiscreteStateSpecID(prefix+"container3", "runtime-state"), Matched: true, Severity: reducer.SeverityWarning, ObservedAt: time.Now()}, reducer.DiscreteRule{Confirmations: 3})m.mu.Unlock()// Only container1 and container2 are in seen set@@ -6607,9 +6603,9 @@ func TestCleanupDockerContainerAlerts(t *testing.T) {_, c1Exists := testLookupActiveAlert(t, m, "container1-alert")_, c2Exists := testLookupActiveAlert(t, m, "container2-alert")_, c3Exists := testLookupActiveAlert(t, m, "container3-alert")- _, s1Exists := m.dockerStateConfirm[prefix+"container1"]- _, s2Exists := m.dockerStateConfirm[prefix+"container2"]- _, s3Exists := m.dockerStateConfirm[prefix+"container3"]+ s1Exists := testCoreHasIncident(m, prefix+"container1", canonicalDiscreteStateSpecID(prefix+"container1", "runtime-state"))+ s2Exists := testCoreHasIncident(m, prefix+"container2", canonicalDiscreteStateSpecID(prefix+"container2", "runtime-state"))+ s3Exists := testCoreHasIncident(m, prefix+"container3", canonicalDiscreteStateSpecID(prefix+"container3", "runtime-state"))m.mu.RUnlock()if !c1Exists {@@ -6671,14 +6667,14 @@ func TestCleanupDockerContainerAlerts(t *testing.T) {ID: "to-clear",ResourceID: prefix + "container1",}- m.dockerStateConfirm[prefix+"container1"] = 1+ m.core.ApplyDiscrete(reducer.DiscreteSignal{ResourceID: prefix + "container1", Key: canonicalDiscreteStateSpecID(prefix+"container1", "runtime-state"), Matched: true, Severity: reducer.SeverityWarning, ObservedAt: time.Now()}, reducer.DiscreteRule{Confirmations: 3})m.mu.Unlock()m.cleanupDockerContainerAlerts(host, map[string]struct{}{})m.mu.RLock()_, alertExists := testLookupActiveAlert(t, m, "to-clear")- _, stateExists := m.dockerStateConfirm[prefix+"container1"]+ stateExists := testCoreHasIncident(m, prefix+"container1", canonicalDiscreteStateSpecID(prefix+"container1", "runtime-state"))m.mu.RUnlock()if alertExists {@@ -6921,14 +6917,13 @@ func TestHandleHostOnline(t *testing.T) {// Set up offline alert and trackingm.mu.Lock()m.activeAlerts[alertID] = &Alert{ID: alertID, ResourceID: resourceKey}- m.offlineConfirmations[resourceKey] = 5m.mu.Unlock()m.HandleHostOnline(host)m.mu.RLock()_, alertExists := testLookupActiveAlert(t, m, alertID)- _, confirmExists := m.offlineConfirmations[resourceKey]+ confirmExists := testCoreHasIncident(m, resourceKey, canonicalConnectivitySpecID(resourceKey))m.mu.RUnlock()if alertExists {@@ -6948,13 +6943,13 @@ func TestHandleHostOnline(t *testing.T) {// Only tracking, no alertm.mu.Lock()- m.offlineConfirmations[resourceKey] = 2+ m.core.ApplyDiscrete(reducer.DiscreteSignal{ResourceID: resourceKey, Key: canonicalConnectivitySpecID(resourceKey), Matched: true, Severity: reducer.SeverityCritical, ObservedAt: time.Now()}, reducer.DiscreteRule{Confirmations: 3})m.mu.Unlock()m.HandleHostOnline(host)m.mu.RLock()- _, exists := m.offlineConfirmations[resourceKey]+ exists := testCoreHasIncident(m, resourceKey, canonicalConnectivitySpecID(resourceKey))m.mu.RUnlock()if exists {@@ -6969,7 +6964,7 @@ func TestHandleHostOnline(t *testing.T) {// Create data that should not be touchedm.mu.Lock()m.activeAlerts["host-offline-other"] = &Alert{ID: "host-offline-other"}- m.offlineConfirmations[hostResourceID("other")] = 3+ m.core.ApplyDiscrete(reducer.DiscreteSignal{ResourceID: hostResourceID("other"), Key: canonicalConnectivitySpecID(hostResourceID("other")), Matched: true, Severity: reducer.SeverityCritical, ObservedAt: time.Now()}, reducer.DiscreteRule{Confirmations: 3})m.mu.Unlock()host := models.Host{ID: ""}@@ -6977,7 +6972,7 @@ func TestHandleHostOnline(t *testing.T) {m.mu.RLock()_, alertExists := testLookupActiveAlert(t, m, "host-offline-other")- _, confirmExists := m.offlineConfirmations[hostResourceID("other")]+ confirmExists := testCoreHasIncident(m, hostResourceID("other"), canonicalConnectivitySpecID(hostResourceID("other")))m.mu.RUnlock()if !alertExists {@@ -7105,8 +7100,8 @@ func TestClearActiveAlertsEmptyMaps(t *testing.T) {if len(m.activeAlerts) != 0 {t.Fatalf("expected activeAlerts to be empty, got %d", len(m.activeAlerts))}- if len(m.pendingAlerts) != 0 {- t.Fatalf("expected pendingAlerts to be empty, got %d", len(m.pendingAlerts))+ if m.core.PendingCount() != 0 {+ t.Fatalf("expected no pending core incidents, got %d", m.core.PendingCount())}// Call ClearActiveAlerts on empty manager - should return early without panic@@ -7127,15 +7122,10 @@ func TestClearActiveAlertsWithExistingAlerts(t *testing.T) {m.activeAlerts["test-alert-1"] = &Alert{ID: "test-alert-1", Type: "cpu-usage"}m.activeAlerts["test-alert-2"] = &Alert{ID: "test-alert-2", Type: "memory-usage"}m.activeAlertAlias["canonical-test-alert-1"] = "test-alert-1"- m.pendingAlerts["pending-1"] = time.Now()+ m.core.ApplyDiscrete(reducer.DiscreteSignal{ResourceID: "pending-1", Key: "pending-1-spec", Matched: true, Severity: reducer.SeverityWarning, ObservedAt: time.Now()}, reducer.DiscreteRule{Confirmations: 3})m.recentAlerts["recent-1"] = &Alert{ID: "recent-1", Type: "disk-usage"}m.suppressedUntil["suppressed-1"] = time.Now().Add(time.Hour)m.alertRateLimit["rate-1"] = []time.Time{time.Now()}- m.nodeOfflineCount["node-1"] = 3- m.offlineConfirmations["node-1"] = 2- m.offlineRecoveryConfirmations["test-alert-1"] = 2- m.dockerOfflineCount["docker-1"] = 1- m.dockerStateConfirm["docker-1"] = 1m.dockerRestartTracking["docker-1"] = &dockerRestartRecord{}m.dockerUpdateFirstSeen["docker-1"] = time.Now()m.dockerUpdateFirstSeenByIdentity["docker-1"] = time.Now()@@ -7161,8 +7151,8 @@ func TestClearActiveAlertsWithExistingAlerts(t *testing.T) {if len(m.activeAlertAlias) != 0 {t.Errorf("expected activeAlertAlias to be empty, got %d", len(m.activeAlertAlias))}- if len(m.pendingAlerts) != 0 {- t.Errorf("expected pendingAlerts to be empty, got %d", len(m.pendingAlerts))+ if m.core.PendingCount() != 0 {+ t.Errorf("expected no pending core incidents, got %d", m.core.PendingCount())}if len(m.recentAlerts) != 0 {t.Errorf("expected recentAlerts to be empty, got %d", len(m.recentAlerts))@@ -7173,20 +7163,8 @@ func TestClearActiveAlertsWithExistingAlerts(t *testing.T) {if len(m.alertRateLimit) != 0 {t.Errorf("expected alertRateLimit to be empty, got %d", len(m.alertRateLimit))}- if len(m.nodeOfflineCount) != 0 {- t.Errorf("expected nodeOfflineCount to be empty, got %d", len(m.nodeOfflineCount))- }- if len(m.offlineConfirmations) != 0 {- t.Errorf("expected offlineConfirmations to be empty, got %d", len(m.offlineConfirmations))- }- if len(m.offlineRecoveryConfirmations) != 0 {- t.Errorf("expected offlineRecoveryConfirmations to be empty, got %d", len(m.offlineRecoveryConfirmations))- }- if len(m.dockerOfflineCount) != 0 {- t.Errorf("expected dockerOfflineCount to be empty, got %d", len(m.dockerOfflineCount))- }- if len(m.dockerStateConfirm) != 0 {- t.Errorf("expected dockerStateConfirm to be empty, got %d", len(m.dockerStateConfirm))+ if n := m.core.FiringCount(); n != 0 {+ t.Errorf("expected no firing core incidents, got %d", n)}if len(m.dockerRestartTracking) != 0 {t.Errorf("expected dockerRestartTracking to be empty, got %d", len(m.dockerRestartTracking))@@ -7457,9 +7435,6 @@ func TestApplyGlobalOfflineSettingsLocked(t *testing.T) {m.setActiveAlertNoLock(node2State, node2Alert)// Add non-node alertm.activeAlerts["cpu-alert"] = &Alert{ID: "cpu-alert", Type: "cpu"}- // Add to nodeOfflineCount- m.nodeOfflineCount["node1"] = 3- m.nodeOfflineCount["node2"] = 2m.config.DisableAllNodesOffline = true@@ -7478,10 +7453,6 @@ func TestApplyGlobalOfflineSettingsLocked(t *testing.T) {if !testHasActiveAlert(t, m, "cpu-alert") {t.Error("expected cpu-alert to remain")}- // nodeOfflineCount should be reset- if len(m.nodeOfflineCount) != 0 {- t.Errorf("expected nodeOfflineCount to be empty, got %d entries", len(m.nodeOfflineCount))- }})t.Run("DisableAllPBSOffline clears PBS offline alerts", func(t *testing.T) {@@ -7494,8 +7465,6 @@ func TestApplyGlobalOfflineSettingsLocked(t *testing.T) {m.setActiveAlertNoLock(pbsState, pbsAlert)// Add non-PBS alertm.activeAlerts["cpu-alert"] = &Alert{ID: "cpu-alert", Type: "cpu"}- // Add to offlineConfirmations- m.offlineConfirmations["pbs1"] = 3m.config.DisableAllPBSOffline = true@@ -7511,10 +7480,6 @@ func TestApplyGlobalOfflineSettingsLocked(t *testing.T) {if !testHasActiveAlert(t, m, "cpu-alert") {t.Error("expected cpu-alert to remain")}- // offlineConfirmations for PBS should be removed- if _, exists := m.offlineConfirmations["pbs1"]; exists {- t.Error("expected offlineConfirmations for pbs1 to be removed")- }})t.Run("DisableAllGuestsOffline clears guest powered off alerts", func(t *testing.T) {@@ -7526,8 +7491,6 @@ func TestApplyGlobalOfflineSettingsLocked(t *testing.T) {m.setActiveAlertNoLock(guestState, guestAlert)// Add non-guest alertm.activeAlerts["cpu-alert"] = &Alert{ID: "cpu-alert", Type: "cpu"}- // Add to offlineConfirmations- m.offlineConfirmations["vm1"] = 2m.config.DisableAllGuestsOffline = true@@ -7543,10 +7506,6 @@ func TestApplyGlobalOfflineSettingsLocked(t *testing.T) {if !testHasActiveAlert(t, m, "cpu-alert") {t.Error("expected cpu-alert to remain")}- // offlineConfirmations for guest should be removed- if _, exists := m.offlineConfirmations["vm1"]; exists {- t.Error("expected offlineConfirmations for vm1 to be removed")- }})t.Run("DisableAllDockerHostsOffline clears docker host alerts", func(t *testing.T) {@@ -7559,8 +7518,6 @@ func TestApplyGlobalOfflineSettingsLocked(t *testing.T) {m.setActiveAlertNoLock(dockerState, dockerAlert)// Add non-docker host alertm.activeAlerts["cpu-alert"] = &Alert{ID: "cpu-alert", Type: "cpu"}- // Add to dockerOfflineCount- m.dockerOfflineCount["host1"] = 3m.config.DisableAllDockerHostsOffline = true@@ -7576,10 +7533,6 @@ func TestApplyGlobalOfflineSettingsLocked(t *testing.T) {if !testHasActiveAlert(t, m, "cpu-alert") {t.Error("expected cpu-alert to remain")}- // dockerOfflineCount should be reset- if len(m.dockerOfflineCount) != 0 {- t.Errorf("expected dockerOfflineCount to be empty, got %d entries", len(m.dockerOfflineCount))- }})t.Run("DisableAllDockerContainers clears docker container alerts", func(t *testing.T) {@@ -7592,7 +7545,6 @@ func TestApplyGlobalOfflineSettingsLocked(t *testing.T) {// Add non-container alertm.activeAlerts["cpu-alert"] = &Alert{ID: "cpu-alert", Type: "cpu"}// Add tracking state- m.dockerStateConfirm["c1"] = 2m.dockerRestartTracking["c1"] = &dockerRestartRecord{count: 5}m.config.DisableAllDockerContainers = true@@ -7613,9 +7565,6 @@ func TestApplyGlobalOfflineSettingsLocked(t *testing.T) {t.Error("expected cpu-alert to remain")}// Tracking state should be reset- if len(m.dockerStateConfirm) != 0 {- t.Errorf("expected dockerStateConfirm to be empty, got %d entries", len(m.dockerStateConfirm))- }if len(m.dockerRestartTracking) != 0 {t.Errorf("expected dockerRestartTracking to be empty, got %d entries", len(m.dockerRestartTracking))}@@ -7708,7 +7657,6 @@ func TestHandleHostOffline(t *testing.T) {// Pre-create an alert and confirmationalertID := "host-offline-host1"m.activeAlerts[alertID] = &Alert{ID: alertID, Type: "host-offline"}- m.offlineConfirmations[hostResourceID("host1")] = 5host := models.Host{ID: "host1", Hostname: "test-host"}m.HandleHostOffline(host)@@ -7717,7 +7665,7 @@ func TestHandleHostOffline(t *testing.T) {if testHasActiveAlert(t, m, alertID) {t.Error("expected alert to be cleared")}- if _, exists := m.offlineConfirmations[hostResourceID("host1")]; exists {+ if testCoreHasIncident(m, hostResourceID("host1"), canonicalConnectivitySpecID(hostResourceID("host1"))) {t.Error("expected offlineConfirmations to be cleared")}})@@ -7733,7 +7681,6 @@ func TestHandleHostOffline(t *testing.T) {// Pre-create an alert and confirmationalertID := "host-offline-host1"m.activeAlerts[alertID] = &Alert{ID: alertID, Type: "host-offline"}- m.offlineConfirmations[hostResourceID("host1")] = 5host := models.Host{ID: "host1", Hostname: "test-host"}m.HandleHostOffline(host)@@ -7742,7 +7689,7 @@ func TestHandleHostOffline(t *testing.T) {if testHasActiveAlert(t, m, alertID) {t.Error("expected alert to be cleared")}- if _, exists := m.offlineConfirmations[hostResourceID("host1")]; exists {+ if testCoreHasIncident(m, hostResourceID("host1"), canonicalConnectivitySpecID(hostResourceID("host1"))) {t.Error("expected offlineConfirmations to be cleared")}})@@ -7756,7 +7703,6 @@ func TestHandleHostOffline(t *testing.T) {alertID := canonicalConnectivityStateID(hostResourceID("host1"))m.activeAlerts[alertID] = &Alert{ID: alertID, Type: "host-offline"}- m.offlineConfirmations[hostResourceID("host1")] = 5host := models.Host{ID: "host1", Hostname: "test-host", LinkedNodeID: "cluster-node1"}m.HandleHostOffline(host)@@ -7764,7 +7710,7 @@ func TestHandleHostOffline(t *testing.T) {if testHasActiveAlert(t, m, alertID) {t.Error("expected alert to be cleared")}- if _, exists := m.offlineConfirmations[hostResourceID("host1")]; exists {+ if testCoreHasIncident(m, hostResourceID("host1"), canonicalConnectivitySpecID(hostResourceID("host1"))) {t.Error("expected offlineConfirmations to be cleared")}})@@ -7820,16 +7766,16 @@ func TestHandleHostOffline(t *testing.T) {if len(m.activeAlerts) != 0 {t.Errorf("expected 0 alerts after 1st call, got %d", len(m.activeAlerts))}- if m.offlineConfirmations[resourceKey] != 1 {- t.Errorf("expected 1 confirmation, got %d", m.offlineConfirmations[resourceKey])+ if testCoreConfirmations(m, resourceKey, canonicalConnectivitySpecID(resourceKey)) != 1 {+ t.Errorf("expected 1 confirmation, got %d", testCoreConfirmations(m, resourceKey, canonicalConnectivitySpecID(resourceKey)))}m.HandleHostOffline(host)if len(m.activeAlerts) != 0 {t.Errorf("expected 0 alerts after 2nd call, got %d", len(m.activeAlerts))}- if m.offlineConfirmations[resourceKey] != 2 {- t.Errorf("expected 2 confirmations, got %d", m.offlineConfirmations[resourceKey])+ if testCoreConfirmations(m, resourceKey, canonicalConnectivitySpecID(resourceKey)) != 2 {+ t.Errorf("expected 2 confirmations, got %d", testCoreConfirmations(m, resourceKey, canonicalConnectivitySpecID(resourceKey)))}})@@ -8205,14 +8151,13 @@ func TestHandleHostRemoved(t *testing.T) {ID: "host-offline-host1",ResourceID: hostResourceID("host1"),}- m.offlineConfirmations[hostResourceID("host1")] = 5m.mu.Unlock()m.HandleHostRemoved(models.Host{ID: "host1", Hostname: "testhost"})m.mu.RLock()_, alertExists := testLookupActiveAlert(t, m, "host-offline-host1")- _, confirmExists := m.offlineConfirmations[hostResourceID("host1")]+ confirmExists := testCoreHasIncident(m, hostResourceID("host1"), canonicalConnectivitySpecID(hostResourceID("host1")))m.mu.RUnlock()if alertExists {@@ -8293,7 +8238,6 @@ func TestHandleHostRemoved(t *testing.T) {m.setActiveAlertNoLock(cpuState, cpuAlert)m.setActiveAlertNoLock(memState, memAlert)m.activeAlerts["agent:host1/disk:sda-usage"] = &Alert{ID: "agent:host1/disk:sda-usage", ResourceID: fmt.Sprintf("%s/disk:sda", hostResourceID("host1"))}- m.offlineConfirmations[hostResourceID("host1")] = 3m.mu.Unlock()m.HandleHostRemoved(models.Host{ID: "host1", Hostname: "testhost"})@@ -8305,7 +8249,7 @@ func TestHandleHostRemoved(t *testing.T) {alertCount++}}- _, confirmExists := m.offlineConfirmations[hostResourceID("host1")]+ confirmExists := testCoreHasIncident(m, hostResourceID("host1"), canonicalConnectivitySpecID(hostResourceID("host1")))m.mu.RUnlock()if alertCount > 0 {@@ -8496,7 +8440,7 @@ func TestReevaluateGuestAlert(t *testing.T) {state, alert := testNewCanonicalAlert("guest1", canonicalMetricSpecID("guest1", "cpu"), string(alertspecs.AlertSpecKindMetricThreshold), "cpu")alert.Value = 90m.setActiveAlertNoLock(state, alert)- m.pendingAlerts[state] = time.Now()+ m.core.ApplyDiscrete(reducer.DiscreteSignal{ResourceID: "guest1", Key: canonicalMetricSpecID("guest1", "cpu"), Matched: true, Severity: reducer.SeverityWarning, ObservedAt: time.Now()}, reducer.DiscreteRule{Confirmations: 3})m.config.GuestDefaults.CPU = nil // Disabledm.mu.Unlock()@@ -8504,7 +8448,7 @@ func TestReevaluateGuestAlert(t *testing.T) {m.mu.RLock()_, alertExists := testLookupActiveAlert(t, m, state)- _, pendingExists := m.pendingAlerts[state]+ pendingExists := testCoreIsPending(m, "guest1", canonicalMetricSpecID("guest1", "cpu"))m.mu.RUnlock()if alertExists {t.Error("expected active alert to be cleared")@@ -8617,7 +8561,6 @@ func TestHandleDockerHostOffline(t *testing.T) {m.mu.Lock()m.config.Enabled = truem.config.DisableAllDockerHostsOffline = true- m.dockerOfflineCount["docker1"] = 5state, alert := testNewCanonicalAlert("docker:docker1", canonicalConnectivitySpecID("docker:docker1"), string(alertspecs.AlertSpecKindConnectivity), "docker-host-offline")m.setActiveAlertNoLock(state, alert)m.mu.Unlock()@@ -8626,7 +8569,7 @@ func TestHandleDockerHostOffline(t *testing.T) {m.mu.RLock()_, alertExists := testLookupActiveAlert(t, m, state)- _, countExists := m.dockerOfflineCount["docker1"]+ countExists := testCoreHasIncident(m, "docker:docker1", canonicalConnectivitySpecID("docker:docker1"))m.mu.RUnlock()if alertExists {t.Error("expected alert to be cleared")@@ -8644,7 +8587,6 @@ func TestHandleDockerHostOffline(t *testing.T) {m.config.Overrides = map[string]ThresholdConfig{"docker1": {DisableConnectivity: true},}- m.dockerOfflineCount["docker1"] = 3state, alert := testNewCanonicalAlert("docker:docker1", canonicalConnectivitySpecID("docker:docker1"), string(alertspecs.AlertSpecKindConnectivity), "docker-host-offline")m.setActiveAlertNoLock(state, alert)m.mu.Unlock()@@ -8653,7 +8595,7 @@ func TestHandleDockerHostOffline(t *testing.T) {m.mu.RLock()_, alertExists := testLookupActiveAlert(t, m, state)- _, countExists := m.dockerOfflineCount["docker1"]+ countExists := testCoreHasIncident(m, "docker:docker1", canonicalConnectivitySpecID("docker:docker1"))m.mu.RUnlock()if alertExists {t.Error("expected alert to be cleared with override")@@ -8699,7 +8641,7 @@ func TestHandleDockerHostOffline(t *testing.T) {// First call - confirmation 1m.HandleDockerHostOffline(host)m.mu.RLock()- count1 := m.dockerOfflineCount["docker1"]+ count1 := testCoreConfirmations(m, "docker:docker1", canonicalConnectivitySpecID("docker:docker1"))alert1, _ := testLookupActiveAlert(t, m, "docker-host-offline-docker1")m.mu.RUnlock()if count1 != 1 {@@ -8712,7 +8654,7 @@ func TestHandleDockerHostOffline(t *testing.T) {// Second call - confirmation 2m.HandleDockerHostOffline(host)m.mu.RLock()- count2 := m.dockerOfflineCount["docker1"]+ count2 := testCoreConfirmations(m, "docker:docker1", canonicalConnectivitySpecID("docker:docker1"))alert2, _ := testLookupActiveAlert(t, m, "docker-host-offline-docker1")m.mu.RUnlock()if count2 != 2 {@@ -8725,7 +8667,7 @@ func TestHandleDockerHostOffline(t *testing.T) {// Third call - confirmation 3 - should create alertm.HandleDockerHostOffline(host)m.mu.RLock()- count3 := m.dockerOfflineCount["docker1"]+ count3 := testCoreConfirmations(m, "docker:docker1", canonicalConnectivitySpecID("docker:docker1"))alert3 := testRequireActiveAlert(t, m, "docker-host-offline-docker1")m.mu.RUnlock()if count3 != 3 {@@ -9081,14 +9023,14 @@ func TestClearNodeOfflineAlert(t *testing.T) {// t.Parallel()m := newTestManager(t)m.mu.Lock()- m.nodeOfflineCount["node1"] = 5+ m.core.ApplyDiscrete(reducer.DiscreteSignal{ResourceID: "node1", Key: canonicalConnectivitySpecID("node1"), Matched: true, Severity: reducer.SeverityCritical, ObservedAt: time.Now()}, reducer.DiscreteRule{Confirmations: 3})m.mu.Unlock()node := models.Node{ID: "node1", Name: "Node 1"}m.clearNodeOfflineAlert(node)m.mu.RLock()- _, exists := m.nodeOfflineCount["node1"]+ exists := testCoreHasIncident(m, "node1", canonicalConnectivitySpecID("node1"))m.mu.RUnlock()if exists {t.Error("expected offline count to be cleared")@@ -9104,7 +9046,6 @@ func TestClearNodeOfflineAlert(t *testing.T) {})m.mu.Lock()- m.nodeOfflineCount["node1"] = 3state, alert := testNewCanonicalAlert("node1", canonicalConnectivitySpecID("node1"), string(alertspecs.AlertSpecKindConnectivity), "offline")alert.StartTime = time.Now().Add(-10 * time.Minute)m.setActiveAlertNoLock(state, alert)@@ -9114,7 +9055,7 @@ func TestClearNodeOfflineAlert(t *testing.T) {m.clearNodeOfflineAlert(node)m.mu.RLock()_, existsAfterFirst := testLookupActiveAlert(t, m, state)- recoveryCountAfterFirst := m.offlineRecoveryConfirmations[state]+ recoveryCountAfterFirst := testCoreRecoveryCount(m, "node1", canonicalConnectivitySpecID("node1"))m.mu.RUnlock()if !existsAfterFirst {t.Fatal("expected node alert to remain active until recovery confirmations are satisfied")@@ -9126,7 +9067,7 @@ func TestClearNodeOfflineAlert(t *testing.T) {m.clearNodeOfflineAlert(node)m.mu.RLock()_, existsAfterSecond := testLookupActiveAlert(t, m, state)- recoveryCountAfterSecond := m.offlineRecoveryConfirmations[state]+ recoveryCountAfterSecond := testCoreRecoveryCount(m, "node1", canonicalConnectivitySpecID("node1"))m.mu.RUnlock()if !existsAfterSecond {t.Fatal("expected node alert to remain active after second recovery confirmation")@@ -9139,7 +9080,7 @@ func TestClearNodeOfflineAlert(t *testing.T) {m.mu.RLock()_, alertExists := testLookupActiveAlert(t, m, state)- _, countExists := m.nodeOfflineCount["node1"]+ countExists := testCoreHasIncident(m, "node1", canonicalConnectivitySpecID("node1"))m.mu.RUnlock()if alertExists {@@ -9315,14 +9256,14 @@ func TestClearPBSOfflineAlert(t *testing.T) {// t.Parallel()m := newTestManager(t)m.mu.Lock()- m.offlineConfirmations["pbs1"] = 5+ m.core.ApplyDiscrete(reducer.DiscreteSignal{ResourceID: "pbs1", Key: canonicalConnectivitySpecID("pbs1"), Matched: true, Severity: reducer.SeverityCritical, ObservedAt: time.Now()}, reducer.DiscreteRule{Confirmations: 3})m.mu.Unlock()pbs := models.PBSInstance{ID: "pbs1", Name: "PBS 1"}m.clearPBSOfflineAlert(pbs)m.mu.RLock()- _, exists := m.offlineConfirmations["pbs1"]+ exists := testCoreHasIncident(m, "pbs1", canonicalConnectivitySpecID("pbs1"))m.mu.RUnlock()if exists {t.Error("expected offline confirmation count to be cleared")@@ -9338,7 +9279,6 @@ func TestClearPBSOfflineAlert(t *testing.T) {})m.mu.Lock()- m.offlineConfirmations["pbs1"] = 3m.activeAlerts["pbs-offline-pbs1"] = &Alert{ID: "pbs-offline-pbs1",Type: "offline",@@ -9350,7 +9290,7 @@ func TestClearPBSOfflineAlert(t *testing.T) {m.clearPBSOfflineAlert(pbs)m.mu.RLock()_, existsAfterFirst := testLookupActiveAlert(t, m, "pbs-offline-pbs1")- recoveryCountAfterFirst := m.offlineRecoveryConfirmations[canonicalConnectivityStateID("pbs1")]+ recoveryCountAfterFirst := testCoreRecoveryCount(m, "pbs1", canonicalConnectivitySpecID("pbs1"))m.mu.RUnlock()if !existsAfterFirst {t.Fatal("expected PBS alert to remain active until recovery confirmations are satisfied")@@ -9362,7 +9302,7 @@ func TestClearPBSOfflineAlert(t *testing.T) {m.clearPBSOfflineAlert(pbs)m.mu.RLock()_, existsAfterSecond := testLookupActiveAlert(t, m, "pbs-offline-pbs1")- recoveryCountAfterSecond := m.offlineRecoveryConfirmations[canonicalConnectivityStateID("pbs1")]+ recoveryCountAfterSecond := testCoreRecoveryCount(m, "pbs1", canonicalConnectivitySpecID("pbs1"))m.mu.RUnlock()if !existsAfterSecond {t.Fatal("expected PBS alert to remain active after second recovery confirmation")@@ -9375,7 +9315,7 @@ func TestClearPBSOfflineAlert(t *testing.T) {m.mu.RLock()_, alertExists := testLookupActiveAlert(t, m, "pbs-offline-pbs1")- _, countExists := m.offlineConfirmations["pbs1"]+ countExists := testCoreHasIncident(m, "pbs1", canonicalConnectivitySpecID("pbs1"))m.mu.RUnlock()if alertExists {@@ -9422,14 +9362,14 @@ func TestClearPMGOfflineAlert(t *testing.T) {// t.Parallel()m := newTestManager(t)m.mu.Lock()- m.offlineConfirmations["pmg1"] = 5+ m.core.ApplyDiscrete(reducer.DiscreteSignal{ResourceID: "pmg1", Key: canonicalConnectivitySpecID("pmg1"), Matched: true, Severity: reducer.SeverityCritical, ObservedAt: time.Now()}, reducer.DiscreteRule{Confirmations: 3})m.mu.Unlock()pmg := models.PMGInstance{ID: "pmg1", Name: "PMG 1"}m.clearPMGOfflineAlert(pmg)m.mu.RLock()- _, exists := m.offlineConfirmations["pmg1"]+ exists := testCoreHasIncident(m, "pmg1", canonicalConnectivitySpecID("pmg1"))m.mu.RUnlock()if exists {t.Error("expected offline confirmation count to be cleared")@@ -9445,7 +9385,6 @@ func TestClearPMGOfflineAlert(t *testing.T) {})m.mu.Lock()- m.offlineConfirmations["pmg1"] = 3m.activeAlerts["pmg-offline-pmg1"] = &Alert{ID: "pmg-offline-pmg1",Type: "offline",@@ -9457,7 +9396,7 @@ func TestClearPMGOfflineAlert(t *testing.T) {m.clearPMGOfflineAlert(pmg)m.mu.RLock()_, existsAfterFirst := testLookupActiveAlert(t, m, "pmg-offline-pmg1")- recoveryCountAfterFirst := m.offlineRecoveryConfirmations[canonicalConnectivityStateID("pmg1")]+ recoveryCountAfterFirst := testCoreRecoveryCount(m, "pmg1", canonicalConnectivitySpecID("pmg1"))m.mu.RUnlock()if !existsAfterFirst {t.Fatal("expected PMG alert to remain active until recovery confirmations are satisfied")@@ -9469,7 +9408,7 @@ func TestClearPMGOfflineAlert(t *testing.T) {m.clearPMGOfflineAlert(pmg)m.mu.RLock()_, existsAfterSecond := testLookupActiveAlert(t, m, "pmg-offline-pmg1")- recoveryCountAfterSecond := m.offlineRecoveryConfirmations[canonicalConnectivityStateID("pmg1")]+ recoveryCountAfterSecond := testCoreRecoveryCount(m, "pmg1", canonicalConnectivitySpecID("pmg1"))m.mu.RUnlock()if !existsAfterSecond {t.Fatal("expected PMG alert to remain active after second recovery confirmation")@@ -9482,7 +9421,7 @@ func TestClearPMGOfflineAlert(t *testing.T) {m.mu.RLock()_, alertExists := testLookupActiveAlert(t, m, "pmg-offline-pmg1")- _, countExists := m.offlineConfirmations["pmg1"]+ countExists := testCoreHasIncident(m, "pmg1", canonicalConnectivitySpecID("pmg1"))m.mu.RUnlock()if alertExists {@@ -9519,7 +9458,6 @@ func TestCheckNodeOffline(t *testing.T) {}state, alert := testNewCanonicalAlert("node1", canonicalConnectivitySpecID("node1"), string(alertspecs.AlertSpecKindConnectivity), "offline")m.setActiveAlertNoLock(state, alert)- m.nodeOfflineCount["node1"] = 5m.mu.Unlock()node := models.Node{ID: "node1", Name: "Node 1"}@@ -9527,7 +9465,7 @@ func TestCheckNodeOffline(t *testing.T) {m.mu.RLock()_, alertExists := testLookupActiveAlert(t, m, state)- _, countExists := m.nodeOfflineCount["node1"]+ countExists := testCoreHasIncident(m, "node1", canonicalConnectivitySpecID("node1"))m.mu.RUnlock()if alertExists {@@ -9576,7 +9514,7 @@ func TestCheckNodeOffline(t *testing.T) {// First call - count 1m.checkNodeOffline(node)m.mu.RLock()- count1 := m.nodeOfflineCount["node1"]+ count1 := testCoreConfirmations(m, "node1", canonicalConnectivitySpecID("node1"))alert1, _ := testLookupActiveAlert(t, m, "node-offline-node1")m.mu.RUnlock()if count1 != 1 {@@ -9589,7 +9527,7 @@ func TestCheckNodeOffline(t *testing.T) {// Second call - count 2m.checkNodeOffline(node)m.mu.RLock()- count2 := m.nodeOfflineCount["node1"]+ count2 := testCoreConfirmations(m, "node1", canonicalConnectivitySpecID("node1"))alert2, _ := testLookupActiveAlert(t, m, "node-offline-node1")m.mu.RUnlock()if count2 != 2 {@@ -9622,7 +9560,7 @@ func TestCheckNodeOffline(t *testing.T) {m.mu.RLock()alert := testRequireActiveAlert(t, m, "node-offline-node1")- count := m.nodeOfflineCount["node1"]+ count := testCoreConfirmations(m, "node1", canonicalConnectivitySpecID("node1"))m.mu.RUnlock()if count != 3 {@@ -9730,7 +9668,7 @@ func TestCheckPBSOffline(t *testing.T) {m.checkPBSOffline(pbs)m.mu.RLock()- count := m.offlineConfirmations["pbs1"]+ count := testCoreConfirmations(m, "pbs1", canonicalConnectivitySpecID("pbs1"))_, alertExists := testLookupActiveAlert(t, m, "pbs-offline-pbs1")m.mu.RUnlock()@@ -9757,7 +9695,7 @@ func TestCheckPBSOffline(t *testing.T) {m.mu.RLock()alert := testRequireActiveAlert(t, m, "pbs-offline-pbs1")- count := m.offlineConfirmations["pbs1"]+ count := testCoreConfirmations(m, "pbs1", canonicalConnectivitySpecID("pbs1"))m.mu.RUnlock()if count != 3 {@@ -9779,7 +9717,6 @@ func TestCheckPBSOffline(t *testing.T) {m := newTestManager(t)oldTime := time.Now().Add(-1 * time.Hour)m.mu.Lock()- m.offlineConfirmations["pbs1"] = 3state, existing := testNewCanonicalAlert("pbs1", canonicalConnectivitySpecID("pbs1"), string(alertspecs.AlertSpecKindConnectivity), "offline")existing.LastSeen = oldTimem.setActiveAlertNoLock(state, existing)@@ -9859,7 +9796,7 @@ func TestCheckPMGOffline(t *testing.T) {m.checkPMGOffline(pmg)m.mu.RLock()- count := m.offlineConfirmations["pmg1"]+ count := testCoreConfirmations(m, "pmg1", canonicalConnectivitySpecID("pmg1"))_, alertExists := testLookupActiveAlert(t, m, "pmg-offline-pmg1")m.mu.RUnlock()@@ -9886,7 +9823,7 @@ func TestCheckPMGOffline(t *testing.T) {m.mu.RLock()alert := testRequireActiveAlert(t, m, "pmg-offline-pmg1")- count := m.offlineConfirmations["pmg1"]+ count := testCoreConfirmations(m, "pmg1", canonicalConnectivitySpecID("pmg1"))m.mu.RUnlock()if count != 3 {@@ -9908,7 +9845,6 @@ func TestCheckPMGOffline(t *testing.T) {m := newTestManager(t)oldTime := time.Now().Add(-1 * time.Hour)m.mu.Lock()- m.offlineConfirmations["pmg1"] = 3state, existing := testNewCanonicalAlert("pmg1", canonicalConnectivitySpecID("pmg1"), string(alertspecs.AlertSpecKindConnectivity), "offline")existing.LastSeen = oldTimem.setActiveAlertNoLock(state, existing)@@ -10701,7 +10637,7 @@ func TestCheckStorageOffline(t *testing.T) {m.checkStorageOffline(storage)m.mu.RLock()- confirmCount := m.offlineConfirmations["local-lvm"]+ confirmCount := testCoreConfirmations(m, "local-lvm", canonicalConnectivitySpecID("local-lvm"))_, alertExists := testLookupActiveAlert(t, m, "storage-offline-local-lvm")m.mu.RUnlock()@@ -10756,7 +10692,6 @@ func TestCheckStorageOffline(t *testing.T) {oldTime := time.Now().Add(-1 * time.Hour)m.mu.Lock()- m.offlineConfirmations["local-lvm"] = 5 // Already confirmedstate, alert := testNewCanonicalAlert("local-lvm", canonicalConnectivitySpecID("local-lvm"), string(alertspecs.AlertSpecKindConnectivity), "offline")alert.LastSeen = oldTimem.setActiveAlertNoLock(state, alert)@@ -10849,7 +10784,7 @@ func TestCheckGuestPoweredOff(t *testing.T) {m.checkGuestPoweredOff("vm100", "TestVM", "pve-node1", "pve-instance", "VM", false)m.mu.RLock()- confirmCount := m.offlineConfirmations["vm100"]+ confirmCount := testCoreConfirmations(m, "vm100", canonicalPoweredStateSpecID("vm100"))_, alertExists := testLookupActiveAlert(t, m, "guest-powered-off-vm100")m.mu.RUnlock()@@ -10942,7 +10877,6 @@ func TestCheckGuestPoweredOff(t *testing.T) {// Pre-create an alert and confirmation countm.mu.Lock()m.activeAlerts["guest-powered-off-vm100"] = &Alert{ID: "guest-powered-off-vm100"}- m.offlineConfirmations["vm100"] = 5m.config.Overrides = map[string]ThresholdConfig{"vm100": {Disabled: true},}@@ -10952,7 +10886,7 @@ func TestCheckGuestPoweredOff(t *testing.T) {m.mu.RLock()_, alertExists := testLookupActiveAlert(t, m, "guest-powered-off-vm100")- _, confirmExists := m.offlineConfirmations["vm100"]+ confirmExists := testCoreHasIncident(m, "vm100", canonicalPoweredStateSpecID("vm100"))m.mu.RUnlock()if alertExists {@@ -11344,13 +11278,13 @@ func TestCleanup(t *testing.T) {m := newTestManager(t)m.mu.Lock()- m.pendingAlerts["stale-pending"] = time.Now().Add(-15 * time.Minute)+ m.core.ApplyDiscrete(reducer.DiscreteSignal{ResourceID: "stale-pending", Key: "stale-pending-spec", Matched: true, Severity: reducer.SeverityWarning, ObservedAt: time.Now().Add(-15 * time.Minute)}, reducer.DiscreteRule{Confirmations: 3})m.mu.Unlock()m.Cleanup(1 * time.Hour)m.mu.RLock()- _, exists := m.pendingAlerts["stale-pending"]+ exists := testCoreIsPending(m, "stale-pending", "stale-pending-spec")m.mu.RUnlock()if exists {@@ -14124,11 +14058,11 @@ func TestSuppressGuestAlerts(t *testing.T) {ResourceID: "vm100",Type: "cpu",}- m.pendingAlerts["vm100-memory"] = now+ m.core.ApplyDiscrete(reducer.DiscreteSignal{ResourceID: "vm100", Key: canonicalMetricSpecID("vm100", "memory"), Matched: true, Severity: reducer.SeverityWarning, ObservedAt: now}, reducer.DiscreteRule{Confirmations: 3})m.recentAlerts["vm100-disk"] = &Alert{ID: "vm100-disk", ResourceID: "vm100"}m.suppressedUntil["vm100-network"] = now.Add(time.Hour)m.alertRateLimit["vm100-io"] = []time.Time{now}- m.offlineConfirmations["vm100"] = 1+ m.core.ApplyDiscrete(reducer.DiscreteSignal{ResourceID: "vm100", Key: canonicalPoweredStateSpecID("vm100"), Matched: true, Severity: reducer.SeverityWarning, ObservedAt: now}, reducer.DiscreteRule{Confirmations: 3})m.mu.Unlock()result := m.suppressGuestAlerts("vm100")@@ -14142,7 +14076,7 @@ func TestSuppressGuestAlerts(t *testing.T) {if testHasActiveAlert(t, m, "vm100-cpu") {t.Error("expected activeAlerts to be cleared")}- if _, exists := m.pendingAlerts["vm100-memory"]; exists {+ if testCoreIsPending(m, "vm100", canonicalMetricSpecID("vm100", "memory")) {t.Error("expected pendingAlerts to be cleared")}if _, exists := m.recentAlerts["vm100-disk"]; exists {@@ -14154,7 +14088,7 @@ func TestSuppressGuestAlerts(t *testing.T) {if _, exists := m.alertRateLimit["vm100-io"]; exists {t.Error("expected alertRateLimit to be cleared")}- if _, exists := m.offlineConfirmations["vm100"]; exists {+ if testCoreHasIncident(m, "vm100", canonicalPoweredStateSpecID("vm100")) {t.Error("expected offlineConfirmations to be cleared")}})@@ -14214,11 +14148,11 @@ func TestSuppressGuestAlerts(t *testing.T) {now := time.Now()m.mu.Lock()// No active alerts, but has entries in auxiliary maps- m.pendingAlerts["vm100-memory"] = now+ m.core.ApplyDiscrete(reducer.DiscreteSignal{ResourceID: "vm100", Key: canonicalMetricSpecID("vm100", "memory"), Matched: true, Severity: reducer.SeverityWarning, ObservedAt: now}, reducer.DiscreteRule{Confirmations: 3})m.recentAlerts["vm100-disk"] = &Alert{ID: "vm100-disk", ResourceID: "vm100"}m.suppressedUntil["vm100-network"] = now.Add(time.Hour)m.alertRateLimit["vm100-io"] = []time.Time{now}- m.offlineConfirmations["vm100"] = 1+ m.core.ApplyDiscrete(reducer.DiscreteSignal{ResourceID: "vm100", Key: canonicalPoweredStateSpecID("vm100"), Matched: true, Severity: reducer.SeverityWarning, ObservedAt: now}, reducer.DiscreteRule{Confirmations: 3})m.mu.Unlock()result := m.suppressGuestAlerts("vm100")@@ -14231,7 +14165,7 @@ func TestSuppressGuestAlerts(t *testing.T) {defer m.mu.RUnlock()// But auxiliary maps should still be cleared- if _, exists := m.pendingAlerts["vm100-memory"]; exists {+ if testCoreIsPending(m, "vm100", canonicalMetricSpecID("vm100", "memory")) {t.Error("expected pendingAlerts to be cleared")}if _, exists := m.recentAlerts["vm100-disk"]; exists {@@ -14243,7 +14177,7 @@ func TestSuppressGuestAlerts(t *testing.T) {if _, exists := m.alertRateLimit["vm100-io"]; exists {t.Error("expected alertRateLimit to be cleared")}- if _, exists := m.offlineConfirmations["vm100"]; exists {+ if testCoreHasIncident(m, "vm100", canonicalPoweredStateSpecID("vm100")) {t.Error("expected offlineConfirmations to be cleared")}})@@ -14397,7 +14331,6 @@ func TestCheckNode(t *testing.T) {m.activeAlerts["node1-disk"] = &Alert{ID: "node1-disk", ResourceID: "node1", Type: "disk"}m.activeAlerts["node1-temperature"] = &Alert{ID: "node1-temperature", ResourceID: "node1", Type: "temperature"}m.activeAlerts["node-offline-node1"] = &Alert{ID: "node-offline-node1", ResourceID: "node1", Type: "connectivity"}- m.nodeOfflineCount["node1"] = 5m.config.DisableAllNodes = truem.mu.Unlock()@@ -14410,7 +14343,7 @@ func TestCheckNode(t *testing.T) {_, diskExists := testLookupActiveAlert(t, m, "node1-disk")_, tempExists := testLookupActiveAlert(t, m, "node1-temperature")_, offlineExists := testLookupActiveAlert(t, m, "node-offline-node1")- _, countExists := m.nodeOfflineCount["node1"]+ countExists := testCoreHasIncident(m, "node1", canonicalConnectivitySpecID("node1"))m.mu.RUnlock()if cpuExists {@@ -14440,7 +14373,6 @@ func TestCheckNode(t *testing.T) {// Pre-create offline alert and trackingm.mu.Lock()m.activeAlerts["node-offline-node1"] = &Alert{ID: "node-offline-node1", ResourceID: "node1", Type: "connectivity"}- m.nodeOfflineCount["node1"] = 3m.config.DisableAllNodesOffline = truem.mu.Unlock()@@ -14449,7 +14381,7 @@ func TestCheckNode(t *testing.T) {m.mu.RLock()_, alertExists := testLookupActiveAlert(t, m, "node-offline-node1")- _, countExists := m.nodeOfflineCount["node1"]+ countExists := testCoreHasIncident(m, "node1", canonicalConnectivitySpecID("node1"))m.mu.RUnlock()if alertExists {@@ -14553,7 +14485,6 @@ func TestCheckNode(t *testing.T) {t.Run("online node clears offline alert", func(t *testing.T) {// t.Parallel()m := newTestManager(t)- state := canonicalConnectivityStateID("node1")// Pre-create offline alertm.mu.Lock()@@ -14562,7 +14493,6 @@ func TestCheckNode(t *testing.T) {ResourceID: "node1",Type: "connectivity",}- m.nodeOfflineCount["node1"] = 5m.mu.Unlock()node := models.Node{@@ -14575,7 +14505,7 @@ func TestCheckNode(t *testing.T) {m.CheckNode(node)m.mu.RLock()_, alertExistsAfterFirst := testLookupActiveAlert(t, m, "node-offline-node1")- recoveryCountAfterFirst := m.offlineRecoveryConfirmations[state]+ recoveryCountAfterFirst := testCoreRecoveryCount(m, "node1", canonicalConnectivitySpecID("node1"))m.mu.RUnlock()if !alertExistsAfterFirst {t.Fatal("expected offline alert to remain active until recovery confirmations are satisfied")@@ -14587,7 +14517,7 @@ func TestCheckNode(t *testing.T) {m.CheckNode(node)m.mu.RLock()_, alertExistsAfterSecond := testLookupActiveAlert(t, m, "node-offline-node1")- recoveryCountAfterSecond := m.offlineRecoveryConfirmations[state]+ recoveryCountAfterSecond := testCoreRecoveryCount(m, "node1", canonicalConnectivitySpecID("node1"))m.mu.RUnlock()if !alertExistsAfterSecond {t.Fatal("expected offline alert to remain active after second recovery confirmation")@@ -14600,8 +14530,8 @@ func TestCheckNode(t *testing.T) {m.mu.RLock()_, alertExists := testLookupActiveAlert(t, m, "node-offline-node1")- _, countExists := m.nodeOfflineCount["node1"]- _, recoveryExists := m.offlineRecoveryConfirmations[state]+ countExists := testCoreHasIncident(m, "node1", canonicalConnectivitySpecID("node1"))+ recoveryExists := testCoreRecoveryCount(m, "node1", canonicalConnectivitySpecID("node1")) != 0m.mu.RUnlock()if alertExists {@@ -15127,7 +15057,6 @@ func TestCheckGuest(t *testing.T) {m.mu.Lock()m.config.DisableAllGuestsOffline = true- m.offlineConfirmations["vm100"] = 5m.activeAlerts["guest-powered-off-vm100"] = &Alert{ID: "guest-powered-off-vm100",ResourceID: "vm100",@@ -15146,7 +15075,7 @@ func TestCheckGuest(t *testing.T) {m.mu.RLock()_, alertExists := testLookupActiveAlert(t, m, "guest-powered-off-vm100")- _, countExists := m.offlineConfirmations["vm100"]+ countExists := testCoreHasIncident(m, "vm100", canonicalPoweredStateSpecID("vm100"))m.mu.RUnlock()if alertExists {@@ -15311,7 +15240,6 @@ func TestCheckGuest(t *testing.T) {ResourceID: "vm100",Type: "powered-off",}- m.offlineConfirmations["vm100"] = 5m.mu.Unlock()vm := models.VM{@@ -16360,7 +16288,6 @@ func TestCheckHostComprehensive(t *testing.T) {ID: "host-offline-host1",Type: "connectivity",}- m.offlineConfirmations[resourceKey] = 5m.mu.Unlock()host := models.Host{@@ -16372,7 +16299,7 @@ func TestCheckHostComprehensive(t *testing.T) {m.mu.RLock()_, alertExists := testLookupActiveAlert(t, m, "host-offline-host1")- _, countExists := m.offlineConfirmations[resourceKey]+ countExists := testCoreHasIncident(m, resourceKey, canonicalConnectivitySpecID(resourceKey))m.mu.RUnlock()if alertExists {@@ -16576,7 +16503,6 @@ func TestCheckPBSComprehensive(t *testing.T) {m.activeAlerts[canonicalMetricStateID("pbs1", "cpu")] = &Alert{ID: canonicalMetricStateID("pbs1", "cpu"), Type: "cpu"}m.activeAlerts[canonicalMetricStateID("pbs1", "memory")] = &Alert{ID: canonicalMetricStateID("pbs1", "memory"), Type: "memory"}m.activeAlerts["pbs-offline-pbs1"] = &Alert{ID: "pbs-offline-pbs1", Type: "connectivity"}- m.offlineConfirmations["pbs1"] = 3m.config.DisableAllPBS = truem.mu.Unlock()@@ -16591,7 +16517,7 @@ func TestCheckPBSComprehensive(t *testing.T) {_, cpuExists := testLookupActiveAlert(t, m, canonicalMetricStateID("pbs1", "cpu"))_, memExists := testLookupActiveAlert(t, m, canonicalMetricStateID("pbs1", "memory"))_, offlineExists := testLookupActiveAlert(t, m, "pbs-offline-pbs1")- _, confirmExists := m.offlineConfirmations["pbs1"]+ confirmExists := testCoreHasIncident(m, "pbs1", canonicalConnectivitySpecID("pbs1"))m.mu.RUnlock()if cpuExists {@@ -16644,7 +16570,6 @@ func TestCheckPBSComprehensive(t *testing.T) {m.activeAlerts[canonicalMetricStateID("pbs1", "cpu")] = &Alert{ID: canonicalMetricStateID("pbs1", "cpu"), Type: "cpu"}m.activeAlerts[canonicalMetricStateID("pbs1", "memory")] = &Alert{ID: canonicalMetricStateID("pbs1", "memory"), Type: "memory"}m.activeAlerts["pbs-offline-pbs1"] = &Alert{ID: "pbs-offline-pbs1", Type: "connectivity"}- m.offlineConfirmations["pbs1"] = 3m.config.Overrides = map[string]ThresholdConfig{"pbs1": {Disabled: true},}@@ -16661,7 +16586,7 @@ func TestCheckPBSComprehensive(t *testing.T) {_, cpuExists := testLookupActiveAlert(t, m, canonicalMetricStateID("pbs1", "cpu"))_, memExists := testLookupActiveAlert(t, m, canonicalMetricStateID("pbs1", "memory"))_, offlineExists := testLookupActiveAlert(t, m, "pbs-offline-pbs1")- _, confirmExists := m.offlineConfirmations["pbs1"]+ confirmExists := testCoreHasIncident(m, "pbs1", canonicalConnectivitySpecID("pbs1"))m.mu.RUnlock()if cpuExists {@@ -16684,7 +16609,6 @@ func TestCheckPBSComprehensive(t *testing.T) {m.mu.Lock()m.activeAlerts["pbs-offline-pbs1"] = &Alert{ID: "pbs-offline-pbs1", Type: "connectivity"}- m.offlineConfirmations["pbs1"] = 3m.config.DisableAllPBSOffline = truem.mu.Unlock()@@ -16698,7 +16622,7 @@ func TestCheckPBSComprehensive(t *testing.T) {m.mu.RLock()_, offlineExists := testLookupActiveAlert(t, m, "pbs-offline-pbs1")- _, confirmExists := m.offlineConfirmations["pbs1"]+ confirmExists := testCoreHasIncident(m, "pbs1", canonicalConnectivitySpecID("pbs1"))m.mu.RUnlock()if offlineExists {@@ -16975,11 +16899,9 @@ func TestCheckPBSComprehensive(t *testing.T) {t.Run("clears offline alert when back online", func(t *testing.T) {// t.Parallel()m := newTestManager(t)- state := canonicalConnectivityStateID("pbs1")m.mu.Lock()m.activeAlerts["pbs-offline-pbs1"] = &Alert{ID: "pbs-offline-pbs1", Type: "connectivity"}- m.offlineConfirmations["pbs1"] = 5m.mu.Unlock()pbs := models.PBSInstance{@@ -16992,7 +16914,7 @@ func TestCheckPBSComprehensive(t *testing.T) {m.CheckPBS(pbs)m.mu.RLock()_, offlineExistsAfterFirst := testLookupActiveAlert(t, m, "pbs-offline-pbs1")- recoveryCountAfterFirst := m.offlineRecoveryConfirmations[state]+ recoveryCountAfterFirst := testCoreRecoveryCount(m, "pbs1", canonicalConnectivitySpecID("pbs1"))m.mu.RUnlock()if !offlineExistsAfterFirst {t.Fatal("expected offline alert to remain active until recovery confirmations are satisfied")@@ -17004,7 +16926,7 @@ func TestCheckPBSComprehensive(t *testing.T) {m.CheckPBS(pbs)m.mu.RLock()_, offlineExistsAfterSecond := testLookupActiveAlert(t, m, "pbs-offline-pbs1")- recoveryCountAfterSecond := m.offlineRecoveryConfirmations[state]+ recoveryCountAfterSecond := testCoreRecoveryCount(m, "pbs1", canonicalConnectivitySpecID("pbs1"))m.mu.RUnlock()if !offlineExistsAfterSecond {t.Fatal("expected offline alert to remain active after second recovery confirmation")@@ -17017,8 +16939,8 @@ func TestCheckPBSComprehensive(t *testing.T) {m.mu.RLock()_, offlineExists := testLookupActiveAlert(t, m, "pbs-offline-pbs1")- _, confirmExists := m.offlineConfirmations["pbs1"]- _, recoveryExists := m.offlineRecoveryConfirmations[state]+ confirmExists := testCoreHasIncident(m, "pbs1", canonicalConnectivitySpecID("pbs1"))+ recoveryExists := testCoreRecoveryCount(m, "pbs1", canonicalConnectivitySpecID("pbs1")) != 0m.mu.RUnlock()if offlineExists {@@ -17079,7 +17001,6 @@ func TestCheckPMGComprehensive(t *testing.T) {m.setActiveAlertNoLock(queueHoldStorageKey, queueHoldAlert)m.setActiveAlertNoLock(oldestMessageStorageKey, oldestMessageAlert)m.setActiveAlertNoLock(offlineState, offlineAlert)- m.offlineConfirmations["pmg1"] = 3m.config.DisableAllPMG = truem.mu.Unlock()@@ -17096,7 +17017,7 @@ func TestCheckPMGComprehensive(t *testing.T) {_, queueHoldExists := testLookupActiveAlert(t, m, queueHoldState)_, oldestMsgExists := testLookupActiveAlert(t, m, oldestMessageState)_, offlineExists := testLookupActiveAlert(t, m, offlineState)- _, confirmExists := m.offlineConfirmations["pmg1"]+ confirmExists := testCoreHasIncident(m, "pmg1", canonicalConnectivitySpecID("pmg1"))m.mu.RUnlock()if queueTotalExists {@@ -17132,7 +17053,6 @@ func TestCheckPMGComprehensive(t *testing.T) {m.setActiveAlertNoLock(queueTotalStorageKey, queueTotalAlert)m.setActiveAlertNoLock(oldestMessageStorageKey, oldestMessageAlert)m.setActiveAlertNoLock(offlineState, offlineAlert)- m.offlineConfirmations["pmg1"] = 3m.config.Overrides = map[string]ThresholdConfig{"pmg1": {Disabled: true},}@@ -17149,7 +17069,7 @@ func TestCheckPMGComprehensive(t *testing.T) {_, queueExists := testLookupActiveAlert(t, m, queueTotalState)_, oldestExists := testLookupActiveAlert(t, m, oldestMessageState)_, offlineExists := testLookupActiveAlert(t, m, offlineState)- _, confirmExists := m.offlineConfirmations["pmg1"]+ confirmExists := testCoreHasIncident(m, "pmg1", canonicalConnectivitySpecID("pmg1"))m.mu.RUnlock()if queueExists {@@ -17172,7 +17092,6 @@ func TestCheckPMGComprehensive(t *testing.T) {m.mu.Lock()m.activeAlerts["pmg-offline-pmg1"] = &Alert{ID: "pmg-offline-pmg1", Type: "connectivity"}- m.offlineConfirmations["pmg1"] = 3m.config.DisableAllPMGOffline = truem.mu.Unlock()@@ -17186,7 +17105,7 @@ func TestCheckPMGComprehensive(t *testing.T) {m.mu.RLock()_, offlineExists := testLookupActiveAlert(t, m, "pmg-offline-pmg1")- _, confirmExists := m.offlineConfirmations["pmg1"]+ confirmExists := testCoreHasIncident(m, "pmg1", canonicalConnectivitySpecID("pmg1"))m.mu.RUnlock()if offlineExists {@@ -17376,11 +17295,9 @@ func TestCheckPMGComprehensive(t *testing.T) {t.Run("clears offline alert when back online", func(t *testing.T) {// t.Parallel()m := newTestManager(t)- state := canonicalConnectivityStateID("pmg1")m.mu.Lock()m.activeAlerts["pmg-offline-pmg1"] = &Alert{ID: "pmg-offline-pmg1", Type: "connectivity"}- m.offlineConfirmations["pmg1"] = 5m.mu.Unlock()pmg := models.PMGInstance{@@ -17393,7 +17310,7 @@ func TestCheckPMGComprehensive(t *testing.T) {m.CheckPMG(pmg)m.mu.RLock()_, offlineExistsAfterFirst := testLookupActiveAlert(t, m, "pmg-offline-pmg1")- recoveryCountAfterFirst := m.offlineRecoveryConfirmations[state]+ recoveryCountAfterFirst := testCoreRecoveryCount(m, "pmg1", canonicalConnectivitySpecID("pmg1"))m.mu.RUnlock()if !offlineExistsAfterFirst {t.Fatal("expected offline alert to remain active until recovery confirmations are satisfied")@@ -17405,7 +17322,7 @@ func TestCheckPMGComprehensive(t *testing.T) {m.CheckPMG(pmg)m.mu.RLock()_, offlineExistsAfterSecond := testLookupActiveAlert(t, m, "pmg-offline-pmg1")- recoveryCountAfterSecond := m.offlineRecoveryConfirmations[state]+ recoveryCountAfterSecond := testCoreRecoveryCount(m, "pmg1", canonicalConnectivitySpecID("pmg1"))m.mu.RUnlock()if !offlineExistsAfterSecond {t.Fatal("expected offline alert to remain active after second recovery confirmation")@@ -17418,8 +17335,8 @@ func TestCheckPMGComprehensive(t *testing.T) {m.mu.RLock()_, offlineExists := testLookupActiveAlert(t, m, "pmg-offline-pmg1")- _, confirmExists := m.offlineConfirmations["pmg1"]- _, recoveryExists := m.offlineRecoveryConfirmations[state]+ confirmExists := testCoreHasIncident(m, "pmg1", canonicalConnectivitySpecID("pmg1"))+ recoveryExists := testCoreRecoveryCount(m, "pmg1", canonicalConnectivitySpecID("pmg1")) != 0m.mu.RUnlock()if offlineExists {@@ -17753,11 +17670,9 @@ func TestCheckStorageComprehensive(t *testing.T) {t.Run("clears offline alert when back online", func(t *testing.T) {// t.Parallel()m := newTestManager(t)- state := canonicalConnectivityStateID("storage1")m.mu.Lock()m.activeAlerts["storage-offline-storage1"] = &Alert{ID: "storage-offline-storage1", Type: "connectivity"}- m.offlineConfirmations["storage1"] = 5m.mu.Unlock()storage := models.Storage{@@ -17769,7 +17684,7 @@ func TestCheckStorageComprehensive(t *testing.T) {m.CheckStorage(storage)m.mu.RLock()_, offlineExistsAfterFirst := testLookupActiveAlert(t, m, "storage-offline-storage1")- recoveryCountAfterFirst := m.offlineRecoveryConfirmations[state]+ recoveryCountAfterFirst := testCoreRecoveryCount(m, "storage1", canonicalConnectivitySpecID("storage1"))m.mu.RUnlock()if !offlineExistsAfterFirst {t.Fatal("expected offline alert to remain active until recovery confirmations are satisfied")@@ -17782,8 +17697,8 @@ func TestCheckStorageComprehensive(t *testing.T) {m.mu.RLock()_, offlineExists := testLookupActiveAlert(t, m, "storage-offline-storage1")- _, confirmExists := m.offlineConfirmations["storage1"]- _, recoveryExists := m.offlineRecoveryConfirmations[state]+ confirmExists := testCoreHasIncident(m, "storage1", canonicalConnectivitySpecID("storage1"))+ recoveryExists := testCoreRecoveryCount(m, "storage1", canonicalConnectivitySpecID("storage1")) != 0m.mu.RUnlock()if offlineExists {@@ -18839,7 +18754,7 @@ func TestCheckPMGAnomalies(t *testing.T) {m.mu.RLock()_, alertExists := testLookupActiveAlert(t, m, "pmg1-anomaly-spamIn")- _, pendingExists := m.pendingAlerts["pmg-anomaly-pmg1-spamIn"]+ pendingExists := testCoreIsPending(m, "pmg1", "pmg1-anomaly-spamIn")m.mu.RUnlock()if alertExists {@@ -18861,7 +18776,7 @@ func TestCheckPMGAnomalies(t *testing.T) {m.mu.RLock()alert := testRequireActiveAlert(t, m, "pmg1-anomaly-spamIn")- _, pendingExists = m.pendingAlerts["pmg-anomaly-pmg1-spamIn"]+ pendingExists = testCoreIsPending(m, "pmg1", "pmg1-anomaly-spamIn")m.mu.RUnlock()if alert == nil {@@ -18903,7 +18818,7 @@ func TestCheckPMGAnomalies(t *testing.T) {m.mu.RLock()_, alertExists := testLookupActiveAlert(t, m, "pmg1-anomaly-spamIn")- _, pendingExists := m.pendingAlerts["pmg-anomaly-pmg1-spamIn"]+ pendingExists := testCoreIsPending(m, "pmg1", "pmg1-anomaly-spamIn")m.mu.RUnlock()if alertExists {@@ -18934,7 +18849,7 @@ func TestCheckPMGAnomalies(t *testing.T) {m.mu.RLock()tracker := m.pmgAnomalyTrackers["pmg1"]_, alertExists := testLookupActiveAlert(t, m, "pmg1-anomaly-spamIn")- _, pendingExists := m.pendingAlerts["pmg-anomaly-pmg1-spamIn"]+ pendingExists := testCoreIsPending(m, "pmg1", "pmg1-anomaly-spamIn")m.mu.RUnlock()if tracker == nil || len(tracker.Samples) != 1 {@@ -19445,16 +19360,15 @@ func TestLoadActiveAlertsHardensExistingFilePermissions(t *testing.T) {}m := &Manager{- alertsDir: alertsDir,- activeAlerts: make(map[string]*Alert),- activeAlertAlias: make(map[string]string),- ackState: make(map[string]ackRecord),- ackStateByCanonical: make(map[string]ackRecord),- escalationStop: make(chan struct{}),- recentlyResolved: make(map[string]*ResolvedAlert),- resolvedAlias: make(map[string]string),- pendingAlerts: make(map[string]time.Time),- offlineConfirmations: make(map[string]int),+ alertsDir: alertsDir,+ activeAlerts: make(map[string]*Alert),+ activeAlertAlias: make(map[string]string),+ ackState: make(map[string]ackRecord),+ ackStateByCanonical: make(map[string]ackRecord),+ escalationStop: make(chan struct{}),+ recentlyResolved: make(map[string]*ResolvedAlert),+ resolvedAlias: make(map[string]string),+ core: reducer.NewState(),}if err := m.LoadActiveAlerts(); err != nil {diff --git a/internal/alerts/canonical_lifecycle.go b/internal/alerts/canonical_lifecycle.goindex 1c1eb5942b..73d35c45d3 100644--- a/internal/alerts/canonical_lifecycle.go+++ b/internal/alerts/canonical_lifecycle.go@@ -17,8 +17,6 @@ type canonicalLifecycleAlertParams struct {Evidence alertspecs.AlertEvidenceIntentSignal stringPolicyDisabledNoLock func() bool- Tracking map[string]int- TrackingKey stringAlertID stringAlertType stringResourceID string@@ -37,8 +35,6 @@ type canonicalLifecycleAlertParams struct {type canonicalStatefulAlertParams struct {Spec alertspecs.ResourceAlertSpecEvidence alertspecs.AlertEvidence- PendingTracking map[string]time.Time- PendingKey stringAlertID stringAlertType stringResourceID string@@ -268,34 +264,6 @@ func canonicalAlertSeverity(level AlertLevel) alertspecs.AlertSeverity {}}-func statefulPreviousState(spec alertspecs.ResourceAlertSpec, existing *Alert, pendingSince time.Time) alertspecs.EvaluatorState {- if existing != nil {- return alertspecs.EvaluatorState{- SpecID: spec.ID,- State: alertspecs.AlertStateFiring,- Severity: canonicalAlertSeverity(existing.Level),- Reason: "",- ActiveSince: existing.StartTime,- FirstMatchedAt: existing.StartTime,- LastObservedAt: existing.LastSeen,- }- }- if !pendingSince.IsZero() {- return alertspecs.EvaluatorState{- SpecID: spec.ID,- State: alertspecs.AlertStatePending,- Severity: spec.Severity,- ConsecutiveMatches: 1,- FirstMatchedAt: pendingSince,- LastObservedAt: pendingSince,- }- }- return alertspecs.EvaluatorState{- SpecID: spec.ID,- State: alertspecs.AlertStateClear,- }-}-func (m *Manager) evaluateCanonicalLifecycleAlert(params canonicalLifecycleAlertParams) (alertspecs.EvaluationResult, bool) {if params.Evidence.ObservedAt.IsZero() {params.Evidence.ObservedAt = time.Now()@@ -444,17 +412,6 @@ func (m *Manager) evaluateCanonicalLifecycleAlert(params canonicalLifecycleAlertincident, hasIncident := m.core.Incident(params.Spec.ResourceID, params.Spec.ID)- // The legacy count maps are maintained as read-only mirrors of the core- // during the Phase 2 transition, for external readers; the engine never- // consults them. They are deleted with the Phase 3 cleanup.- if params.Tracking != nil {- if hasIncident {- params.Tracking[params.TrackingKey] = incident.Confirmations- } else {- delete(params.Tracking, params.TrackingKey)- }- }-// Synthesize the evaluator-shaped result the callers consume.result := alertspecs.EvaluationResult{}result.State.SpecID = params.Spec.ID@@ -707,18 +664,6 @@ func (m *Manager) evaluateCanonicalStatefulAlert(params canonicalStatefulAlertPa}incident, hasIncident := m.core.Incident(params.Spec.ResourceID, params.Spec.ID)- // Legacy pending-since maps stay as read-only mirrors of the core- // during the transition.- if params.PendingTracking != nil {- if hasIncident && incident.State == reducer.StatePending {- if _, tracked := params.PendingTracking[params.PendingKey]; !tracked {- params.PendingTracking[params.PendingKey] = incident.PendingSince- }- } else {- delete(params.PendingTracking, params.PendingKey)- }- }-result := alertspecs.EvaluationResult{}result.State.SpecID = params.Spec.IDresult.State.LastObservedAt = params.Evidence.ObservedAtdiff --git a/internal/alerts/canonical_metric.go b/internal/alerts/canonical_metric.goindex c656d930ff..a911614696 100644--- a/internal/alerts/canonical_metric.go+++ b/internal/alerts/canonical_metric.go@@ -12,29 +12,6 @@ import ("github.com/rs/zerolog/log")-func metricPreviousState(spec alertspecs.ResourceAlertSpec, existing *Alert) alertspecs.EvaluatorState {- if existing == nil {- return alertspecs.EvaluatorState{- SpecID: spec.ID,- State: alertspecs.AlertStateClear,- }- }-- severity := alertspecs.AlertSeverityWarning- if existing.Level == AlertLevelCritical {- severity = alertspecs.AlertSeverityCritical- }-- return alertspecs.EvaluatorState{- SpecID: spec.ID,- State: alertspecs.AlertStateFiring,- Severity: severity,- ActiveSince: existing.StartTime,- FirstMatchedAt: existing.StartTime,- LastObservedAt: existing.LastSeen,- }-}-func metricClearThreshold(spec *alertspecs.MetricThresholdSpec, threshold *HysteresisThreshold) float64 {if threshold != nil && threshold.Clear > 0 {return threshold.Clear@@ -104,7 +81,6 @@ func (m *Manager) evaluateCanonicalMetricAlert(spec alertspecs.ResourceAlertSpecmetricType := spec.MetricThreshold.Metricif spec.Disabled || spec.MetricThreshold.Trigger <= 0 {m.mu.Lock()- delete(m.pendingAlerts, trackingKey)m.core.ApplyMetric(reducer.MetricSignal{ResourceID: spec.ResourceID,Key: spec.ID,diff --git a/internal/alerts/cleanup_test.go b/internal/alerts/cleanup_test.goindex e0b8b79348..fdac78632f 100644--- a/internal/alerts/cleanup_test.go+++ b/internal/alerts/cleanup_test.go@@ -23,10 +23,6 @@ func TestCleanupStaleMaps(t *testing.T) {m.suppressedUntil["expired-suppression"] = oldTimem.suppressedUntil["active-suppression"] = time.Now().Add(1 * time.Hour)- // Pending alerts- m.pendingAlerts["stale-pending"] = oldTime- m.pendingAlerts["recent-pending"] = recentTime-// Should not be cleaned if active alert existsm.flappingHistory["active-alert-flapping"] = []time.Time{oldTime}m.activeAlerts["active-alert-flapping"] = &Alert{ID: "active-alert-flapping"}@@ -61,50 +57,12 @@ func TestCleanupStaleMaps(t *testing.T) {t.Error("active-suppression should NOT get removed")}- if _, exists := m.pendingAlerts["stale-pending"]; exists {- t.Error("stale-pending should get removed")- }- if _, exists := m.pendingAlerts["recent-pending"]; !exists {- t.Error("recent-pending should NOT get removed")- }-if _, exists := m.flappingHistory["active-alert-flapping"]; !exists {t.Error("active-alert-flapping should NOT get removed")}m.mu.Unlock()- // Should not be cleaned if active alert exists for pending- m.mu.Lock()- m.pendingAlerts["active-alert-pending"] = oldTime- m.activeAlerts["active-alert-pending"] = &Alert{ID: "active-alert-pending"}- m.mu.Unlock()-- // Run cleanup- m.cleanupStaleMaps()-- // Verifym.mu.Lock()- // Test additional maps- // Offline confirmations- m.offlineConfirmations["stale-node"] = 3- m.activeAlerts["node:active-node:offline"] = &Alert{ID: "node:active-node:offline"}- m.offlineConfirmations["active-node"] = 3-- // Node offline count- m.nodeOfflineCount["stale-node-legacy"] = 5- m.activeAlerts["node:active-node-legacy:offline"] = &Alert{ID: "node:active-node-legacy:offline"}- m.nodeOfflineCount["active-node-legacy"] = 5-- // Docker state confirm- m.dockerStateConfirm["stale-container"] = 2- m.activeAlerts["docker:active-container:state"] = &Alert{ID: "docker:active-container:state"}- m.dockerStateConfirm["active-container"] = 2-- // Docker offline count- m.dockerOfflineCount["stale-host"] = 4- m.activeAlerts["docker:active-host:offline"] = &Alert{ID: "docker:active-host:offline"}- m.dockerOfflineCount["active-host"] = 4-// Docker restart trackingm.dockerRestartTracking["stale-restart"] = &dockerRestartRecord{lastChecked: oldTime}m.dockerRestartTracking["recent-restart"] = &dockerRestartRecord{lastChecked: recentTime}@@ -133,34 +91,6 @@ func TestCleanupStaleMaps(t *testing.T) {m.mu.Lock()defer m.mu.Unlock()- if _, exists := m.offlineConfirmations["stale-node"]; exists {- t.Error("stale-node offline connection should be removed")- }- if _, exists := m.offlineConfirmations["active-node"]; !exists {- t.Error("active-node offline connection should NOT be removed")- }-- if _, exists := m.nodeOfflineCount["stale-node-legacy"]; exists {- t.Error("stale-node-legacy should be removed")- }- if _, exists := m.nodeOfflineCount["active-node-legacy"]; !exists {- t.Error("active-node-legacy should NOT be removed")- }-- if _, exists := m.dockerStateConfirm["stale-container"]; exists {- t.Error("stale-container should be removed")- }- if _, exists := m.dockerStateConfirm["active-container"]; !exists {- t.Error("active-container should NOT be removed")- }-- if _, exists := m.dockerOfflineCount["stale-host"]; exists {- t.Error("stale-host should be removed")- }- if _, exists := m.dockerOfflineCount["active-host"]; !exists {- t.Error("active-host should NOT be removed")- }-if _, exists := m.dockerRestartTracking["stale-restart"]; exists {t.Error("stale-restart should be removed")}diff --git a/internal/alerts/config_runtime.go b/internal/alerts/config_runtime.goindex 3f792c8dbe..eed844f9cd 100644--- a/internal/alerts/config_runtime.go+++ b/internal/alerts/config_runtime.go@@ -170,7 +170,6 @@ func (m *Manager) applyGlobalOfflineSettingsLocked() {for _, alertID := range nodeAlerts {m.clearAlertNoLock(alertID)}- m.nodeOfflineCount = make(map[string]int)}if m.config.DisableAllPBSOffline {@@ -180,7 +179,6 @@ func (m *Manager) applyGlobalOfflineSettingsLocked() {if resourceType, _ := alert.Metadata["resourceType"].(string); resourceType == "pbs" {pbsAlerts = append(pbsAlerts, storageKey)}- delete(m.offlineConfirmations, alert.ResourceID)}}for _, alertID := range pbsAlerts {@@ -193,7 +191,6 @@ func (m *Manager) applyGlobalOfflineSettingsLocked() {for storageKey, alert := range m.activeAlerts {if alert != nil && alert.CanonicalKind == string(alertspecs.AlertSpecKindPoweredState) {guestAlerts = append(guestAlerts, storageKey)- delete(m.offlineConfirmations, alert.ResourceID)}}for _, alertID := range guestAlerts {@@ -213,7 +210,6 @@ func (m *Manager) applyGlobalOfflineSettingsLocked() {for _, alertID := range hostAlerts {m.clearAlertNoLock(alertID)}- m.dockerOfflineCount = make(map[string]int)}if m.config.DisableAllDockerContainers {@@ -227,7 +223,6 @@ func (m *Manager) applyGlobalOfflineSettingsLocked() {for _, alertID := range containerAlerts {m.clearAlertNoLock(alertID)}- m.dockerStateConfirm = make(map[string]int)m.dockerRestartTracking = make(map[string]*dockerRestartRecord)m.dockerUpdateFirstSeen = make(map[string]time.Time)m.dockerUpdateFirstSeenByIdentity = make(map[string]time.Time)@@ -381,8 +376,6 @@ func (m *Manager) reevaluateActiveAlertsLocked() {policyResourceID := metadataStringValue(alert.Metadata, "policyResourceID")if m.connectionDegradedPolicyDisabledNoLock(resourceID, policyResourceID, connectionType) {alertsToResolve = append(alertsToResolve, alertID)- delete(m.connectionDegradedCount, resourceID)- delete(m.offlineRecoveryConfirmations, alertID)}continue}@@ -590,14 +583,7 @@ func (m *Manager) reevaluateActiveAlertsLocked() {if alert, exists := m.getActiveAlertNoLock(alertID); exists {resolvedAlert := m.newResolvedAlert(alert, time.Now(), nil)- trackingKey := canonicalTrackingKeyForAlert(alert)- if _, isPending := m.pendingAlerts[trackingKey]; isPending {- delete(m.pendingAlerts, trackingKey)- log.Debug().- Str("alertID", alertID).- Msg("Cleared pending alert after configuration update")- }-+ m.mirrorForgetAlertNoLock(alert)m.removeActiveAlertNoLock(alertID)m.addRecentlyResolvedWithPrimaryLock(resolvedAlert)diff --git a/internal/alerts/connection.go b/internal/alerts/connection.goindex afa7f5062c..19fc83afcc 100644--- a/internal/alerts/connection.go+++ b/internal/alerts/connection.go@@ -148,8 +148,6 @@ func (m *Manager) suppressConnectionDegradedAlert(snap ConnectionSnapshot) {alertID := canonicalDiscreteStateStateID(snap.ID, connectionDegradedStateKey)m.mu.Lock()- delete(m.connectionDegradedCount, snap.ID)- delete(m.offlineRecoveryConfirmations, alertID)m.mu.Unlock()m.clearAlert(alertID)@@ -186,7 +184,6 @@ func (m *Manager) CheckConnection(snap ConnectionSnapshot) {// later degraded run starts from zero instead of accumulating across// a transient pending blip.m.mu.Lock()- delete(m.connectionDegradedCount, snap.ID)m.mu.Unlock()return}@@ -200,7 +197,6 @@ func (m *Manager) CheckConnection(snap ConnectionSnapshot) {// confirmations — recovery must build back up from zero.alertID := canonicalDiscreteStateStateID(snap.ID, connectionDegradedStateKey)m.mu.Lock()- delete(m.offlineRecoveryConfirmations, alertID)m.mu.Unlock()spec, err := buildCanonicalDiscreteStateSpec(@@ -269,8 +265,6 @@ func (m *Manager) CheckConnection(snap ConnectionSnapshot) {PolicyDisabledNoLock: func() bool {return m.connectionDegradedPolicyDisabledNoLock(snap.ID, snap.PolicyResourceID, snap.Type)},- Tracking: m.connectionDegradedCount,- TrackingKey: snap.ID,AlertID: alertID,AlertType: connectionDegradedAlertType,ResourceID: snap.ID,@@ -299,9 +293,6 @@ func (m *Manager) clearConnectionDegradedAlert(snap ConnectionSnapshot) {// Reset the legacy degraded counter; the reducer core owns the// confirmation run itself.- if m.connectionDegradedCount[snap.ID] > 0 {- delete(m.connectionDegradedCount, snap.ID)- }m.resolveDiscreteRecoveryNoLock(snap.ID, specKey, alertID, offlineRecoveryConfirmationsDefault, "Connection", snap.Name, snap.ID)}diff --git a/internal/alerts/connection_test.go b/internal/alerts/connection_test.goindex 056dde2994..36bae10a79 100644--- a/internal/alerts/connection_test.go+++ b/internal/alerts/connection_test.go@@ -32,7 +32,7 @@ func TestCheckConnection(t *testing.T) {t.Fatal("expected no alert for active connection")}m.mu.RLock()- count := m.connectionDegradedCount[snap.ID]+ count := testCoreConfirmations(m, snap.ID, canonicalDiscreteStateSpecID(snap.ID, connectionDegradedStateKey))m.mu.RUnlock()if count != 0 {t.Errorf("expected degraded count 0, got %d", count)@@ -171,7 +171,7 @@ func TestCheckConnection(t *testing.T) {t.Fatal("expected no alert for non-platform connection type")}m.mu.RLock()- count := m.connectionDegradedCount[snap.ID]+ count := testCoreConfirmations(m, snap.ID, canonicalDiscreteStateSpecID(snap.ID, connectionDegradedStateKey))m.mu.RUnlock()if count != 0 {t.Errorf("expected degraded count untouched for non-platform type, got %d", count)@@ -224,7 +224,7 @@ func TestCheckConnectionHonorsOwningResourceAvailabilityPolicy(t *testing.T) {t.Fatal("offline-disabled PBS created a connection-degraded alert")}m.mu.RLock()- _, tracked := m.connectionDegradedCount[snap.ID]+ tracked := testCoreHasIncident(m, snap.ID, canonicalDiscreteStateSpecID(snap.ID, connectionDegradedStateKey))m.mu.RUnlock()if tracked {t.Fatal("offline-disabled PBS retained connection-degraded confirmation state")@@ -278,7 +278,7 @@ func TestCheckConnectionHonorsOwningResourceAvailabilityPolicy(t *testing.T) {t.Fatal("policy update did not immediately resolve connection-degraded")}m.mu.RLock()- _, tracked := m.connectionDegradedCount[snap.ID]+ tracked := testCoreHasIncident(m, snap.ID, canonicalDiscreteStateSpecID(snap.ID, connectionDegradedStateKey))m.mu.RUnlock()if tracked {t.Fatal("policy update left connection-degraded confirmation state")@@ -382,7 +382,7 @@ func TestClearConnectionDegradedAlert(t *testing.T) {t.Fatal("expected alert to remain active until recovery confirmations are met")}m.mu.RLock()- count1 := m.offlineRecoveryConfirmations[alertID]+ count1 := testCoreRecoveryCount(m, snap.ID, canonicalDiscreteStateSpecID(snap.ID, connectionDegradedStateKey))m.mu.RUnlock()if count1 != 1 {t.Errorf("expected recovery confirmation 1, got %d", count1)@@ -415,7 +415,7 @@ func TestClearConnectionDegradedAlert(t *testing.T) {m.mu.RLock()alertCount := len(m.activeAlerts)- recovery := m.offlineRecoveryConfirmations[canonicalDiscreteStateStateID(snap.ID, connectionDegradedStateKey)]+ recovery := testCoreRecoveryCount(m, snap.ID, canonicalDiscreteStateSpecID(snap.ID, connectionDegradedStateKey))m.mu.RUnlock()if alertCount != 0 {@@ -441,7 +441,7 @@ func TestClearConnectionDegradedAlert(t *testing.T) {snap.State = ConnectionStateActivem.CheckConnection(snap)m.mu.RLock()- recoveryBefore := m.offlineRecoveryConfirmations[alertID]+ recoveryBefore := testCoreRecoveryCount(m, snap.ID, canonicalDiscreteStateSpecID(snap.ID, connectionDegradedStateKey))m.mu.RUnlock()if recoveryBefore != 1 {t.Fatalf("expected 1 recovery confirmation, got %d", recoveryBefore)@@ -452,7 +452,7 @@ func TestClearConnectionDegradedAlert(t *testing.T) {snap.State = ConnectionStateStalem.CheckConnection(snap)m.mu.RLock()- recoveryAfter := m.offlineRecoveryConfirmations[alertID]+ recoveryAfter := testCoreRecoveryCount(m, snap.ID, canonicalDiscreteStateSpecID(snap.ID, connectionDegradedStateKey))m.mu.RUnlock()if recoveryAfter != 0 {t.Errorf("expected recovery confirmations reset to 0, got %d", recoveryAfter)diff --git a/internal/alerts/docker.go b/internal/alerts/docker.goindex ddc19d068f..c67ff1af74 100644--- a/internal/alerts/docker.go+++ b/internal/alerts/docker.go@@ -6,6 +6,7 @@ import ("strings""time"+ "github.com/rcourtman/pulse-go-rewrite/internal/alerts/reducer"alertspecs "github.com/rcourtman/pulse-go-rewrite/internal/alerts/specs""github.com/rcourtman/pulse-go-rewrite/internal/models""github.com/rcourtman/pulse-go-rewrite/internal/unifiedresources"@@ -655,11 +656,14 @@ func (m *Manager) HandleDockerHostOnline(host models.DockerHost) {return}- alertID := canonicalConnectivityStateID(fmt.Sprintf("docker:%s", strings.TrimSpace(host.ID)))+ resourceID := fmt.Sprintf("docker:%s", strings.TrimSpace(host.ID))+ alertID := canonicalConnectivityStateID(resourceID)m.mu.Lock()- delete(m.dockerOfflineCount, host.ID)exists := m.hasActiveAlertNoLock(alertID)+ // The host was observed online: a healthy observation ends any+ // in-flight offline confirmation run in the core.+ m.core.ApplyDiscrete(reducer.DiscreteSignal{ResourceID: resourceID, Key: canonicalConnectivitySpecID(resourceID), Matched: false, ObservedAt: m.policyNow()}, reducer.DiscreteRule{})m.mu.Unlock()if exists {@@ -700,7 +704,6 @@ func (m *Manager) HandleDockerHostOffline(host models.DockerHost) {if disableDockerHostsOffline {m.mu.Lock()- delete(m.dockerOfflineCount, host.ID)m.mu.Unlock()m.clearAlert(alertID)return@@ -716,7 +719,6 @@ func (m *Manager) HandleDockerHostOffline(host models.DockerHost) {if disableConnectivity {m.clearAlert(alertID)m.mu.Lock()- delete(m.dockerOfflineCount, host.ID)m.mu.Unlock()return}@@ -734,8 +736,6 @@ func (m *Manager) HandleDockerHostOffline(host models.DockerHost) {result, ok := m.evaluateCanonicalLifecycleAlert(canonicalLifecycleAlertParams{Spec: spec,Evidence: alertspecs.AlertEvidence{ObservedAt: time.Now(), Connectivity: &alertspecs.ConnectivityEvidence{Signal: "status", Connected: false}},- Tracking: m.dockerOfflineCount,- TrackingKey: host.ID,AlertID: alertID,AlertType: "docker-host-offline",ResourceID: resourceID,@@ -783,7 +783,6 @@ func (m *Manager) HandleDockerHostOffline(host models.DockerHost) {func (m *Manager) checkDockerContainerState(host models.DockerHost, container models.DockerContainer, resourceID, containerName, instanceName, nodeName string) {alertID := fmt.Sprintf("docker-container-state-%s", resourceID)- stateKey := resourceIDm.mu.RLock()override, hasOverride := m.lookupDockerContainerOverrideNoLock(host.ID, container.Name, resourceID)@@ -835,8 +834,6 @@ func (m *Manager) checkDockerContainerState(host models.DockerHost, container moObserved: observedState,},},- Tracking: m.dockerStateConfirm,- TrackingKey: stateKey,AlertID: alertID,AlertType: "docker-container-state",ResourceID: resourceID,@@ -853,7 +850,6 @@ func (m *Manager) checkDockerContainerState(host models.DockerHost, container mofunc (m *Manager) clearDockerContainerStateAlert(resourceID string) {m.mu.Lock()- delete(m.dockerStateConfirm, resourceID)m.mu.Unlock()m.clearAlert(canonicalDiscreteStateStateID(resourceID, "runtime-state"))}@@ -1465,10 +1461,12 @@ func (m *Manager) cleanupDockerContainerAlertsWithTracking(host models.DockerHos}toClear = append(toClear, alertID)}- for resourceID := range m.dockerStateConfirm {+ // Removed containers stop being observed, so their in-flight+ // confirmation runs in the core would never see a closing observation.+ for _, resourceID := range m.core.PendingResourceIDs() {if strings.HasPrefix(resourceID, prefix) {if _, exists := seen[resourceID]; !exists {- delete(m.dockerStateConfirm, resourceID)+ m.core.DropPendingForResource(resourceID)}}}@@ -1509,9 +1507,9 @@ func (m *Manager) clearDockerHostContainerAlerts(host models.DockerHost) {toClear = append(toClear, alertID)}}- for resourceID := range m.dockerStateConfirm {+ for _, resourceID := range m.core.PendingResourceIDs() {if strings.HasPrefix(resourceID, prefix) {- delete(m.dockerStateConfirm, resourceID)+ m.core.DropPendingForResource(resourceID)}}for resourceID := range m.dockerRestartTracking {diff --git a/internal/alerts/external_probe.go b/internal/alerts/external_probe.goindex 55addf8aa9..2183782e97 100644--- a/internal/alerts/external_probe.go+++ b/internal/alerts/external_probe.go@@ -5,6 +5,7 @@ import ("sort""strings"+ "github.com/rcourtman/pulse-go-rewrite/internal/alerts/reducer"alertspecs "github.com/rcourtman/pulse-go-rewrite/internal/alerts/specs""github.com/rcourtman/pulse-go-rewrite/internal/unifiedresources""github.com/rs/zerolog/log"@@ -110,7 +111,6 @@ func (m *Manager) checkExternalProbe(snapshot ExternalProbeSnapshot) {resourceID := hostResourceID(snapshot.AgentID)alertID := canonicalDiscreteStateStateID(resourceID, externalProbeUnavailableStateKey)- trackingKey := externalProbeUnavailableTrackingPrefix + snapshot.AgentIDtargetIDs := normalizedExternalProbeTargetIDs(snapshot.TargetIDs)staleTargetIDs := normalizedExternalProbeTargetIDs(snapshot.StaleTargetIDs)@@ -156,8 +156,6 @@ func (m *Manager) checkExternalProbe(snapshot ExternalProbeSnapshot) {Observed: string(ExternalProbeStateUnavailable),},},- Tracking: m.offlineConfirmations,- TrackingKey: trackingKey,AlertID: alertID,AlertType: ExternalProbeUnavailableAlertType,ResourceID: resourceID,@@ -190,10 +188,10 @@ func (m *Manager) clearExternalProbeAlert(agentID string) {}resourceID := hostResourceID(agentID)alertID := canonicalDiscreteStateStateID(resourceID, externalProbeUnavailableStateKey)- trackingKey := externalProbeUnavailableTrackingPrefix + agentIDm.mu.Lock()- delete(m.offlineConfirmations, trackingKey)+ // Clear any pending core run alongside the alert.+ m.core.ApplyDiscrete(reducer.DiscreteSignal{ResourceID: resourceID, Key: canonicalDiscreteStateSpecID(resourceID, externalProbeUnavailableStateKey), Matched: false, ObservedAt: m.policyNow()}, reducer.DiscreteRule{})exists := m.hasActiveAlertNoLock(alertID)m.mu.Unlock()if exists {diff --git a/internal/alerts/guest.go b/internal/alerts/guest.goindex d8c93275e8..bd84f94bde 100644--- a/internal/alerts/guest.go+++ b/internal/alerts/guest.go@@ -60,13 +60,6 @@ func (m *Manager) ReevaluateGuestAlert(guest any, guestID string) {// If threshold is disabled or doesn't exist, clear the alertif threshold == nil || threshold.Trigger <= 0 {m.clearAlertNoLock(trackingKey)- // Also clear any pending alert for this metric- if _, isPending := m.pendingAlerts[trackingKey]; isPending {- delete(m.pendingAlerts, trackingKey)- log.Debug().- Str("alertID", alertID).- Msg("Cleared pending alert - threshold disabled")- }log.Info().Str("alertID", alertID).Str("metric", metricType).@@ -166,7 +159,6 @@ func (m *Manager) CheckGuest(guest any, instanceName string) {if disableAllGuestsOffline {// Clear any pending powered-off tracking and alerts when globally disabledm.mu.Lock()- delete(m.offlineConfirmations, guestID)intentCleared := m.clearIntentPendingNoLock(canonicalPoweredStateStateID(guestID))m.mu.Unlock()if intentCleared {@@ -178,7 +170,6 @@ func (m *Manager) CheckGuest(guest any, instanceName string) {// Guest is explicitly not configured to autostart (onboot=0).// Being stopped is the expected state — suppress the alert.m.mu.Lock()- delete(m.offlineConfirmations, guestID)m.mu.Unlock()m.clearAlert(canonicalPoweredStateStateID(guestID))m.clearGuestPoweredOffAlert(guestID, name)@@ -481,7 +472,6 @@ func (m *Manager) checkGuestPoweredOffWithThresholdsAndIntentAndTags(guestID, naeffectiveIntent := m.resolveEffectiveIntentPolicyNoLock(guestID, string(resourceType), string(AlertIntentSignalOffline))m.mu.RUnlock()confirmations := 2- tracking := m.offlineConfirmationsdurationAuthoritative := effectiveIntent.Sources["graceSeconds"] != "factory" ||(effectiveIntent.BackupOffline != nil && effectiveIntent.BackupOffline.Enabled)if durationAuthoritative {@@ -489,7 +479,6 @@ func (m *Manager) checkGuestPoweredOffWithThresholdsAndIntentAndTags(guestID, na// grace therefore fires on the first stopped observation, while a// positive grace is independent of polling cadence.confirmations = 1- tracking = nil}spec, err := buildCanonicalPoweredStateSpec(guestID, name, resourceType, severity, confirmations, thresholds.Disabled || thresholds.DisableConnectivity)if err != nil {@@ -518,8 +507,6 @@ func (m *Manager) checkGuestPoweredOffWithThresholdsAndIntentAndTags(guestID, naObserved: alertspecs.PowerStateOff,},},- Tracking: tracking,- TrackingKey: guestID,AlertID: alertID,AlertType: "powered-off",ResourceID: guestID,@@ -549,13 +536,6 @@ func (m *Manager) clearGuestPoweredOffAlert(guestID, name string) {defer m.mu.Unlock()// Reset confirmation count when guest comes back online- if count, exists := m.offlineConfirmations[guestID]; exists && count > 0 {- log.Debug().- Str("guest", name).- Int("previousCount", count).- Msg("Guest is running, resetting powered-off confirmation count")- delete(m.offlineConfirmations, guestID)- }if decision := m.evaluateIntentNoLock(guestID, "", string(AlertIntentSignalOffline), alertID, m.policyNow().UTC(), false, BackupIntentContext{}); decision.StateChanged {m.saveActiveAlertsAsync("guest offline intent cleared")}@@ -718,18 +698,13 @@ func (m *Manager) suppressGuestAlerts(guestID string) bool {guestAlertBelongsToGuest(alert.ResourceID, guestID) {m.clearAlertNoLock(alertID)delete(m.recentAlerts, trackingKey)- delete(m.pendingAlerts, trackingKey)delete(m.suppressedUntil, trackingKey)delete(m.alertRateLimit, trackingKey)cleared = true}}- for key := range m.pendingAlerts {- if strings.HasPrefix(key, guestID) {- delete(m.pendingAlerts, key)- }- }+ m.core.DropPendingForResource(guestID)for key := range m.recentAlerts {if strings.HasPrefix(key, guestID) {delete(m.recentAlerts, key)@@ -746,7 +721,6 @@ func (m *Manager) suppressGuestAlerts(guestID string) bool {}}- delete(m.offlineConfirmations, guestID)for key, pending := range m.intentPending {if pending.ResourceID == guestID || strings.HasPrefix(pending.ResourceID, guestID+"/") {if m.clearIntentPendingNoLock(key) {diff --git a/internal/alerts/guest_metric_migration.go b/internal/alerts/guest_metric_migration.goindex 4e247d1468..89676e3d51 100644--- a/internal/alerts/guest_metric_migration.go+++ b/internal/alerts/guest_metric_migration.go@@ -236,10 +236,9 @@ func (m *Manager) moveAlertTrackingStateNoLock(oldTrackingKey, newTrackingKey streturn}- if pending, exists := m.pendingAlerts[oldTrackingKey]; exists {- delete(m.pendingAlerts, oldTrackingKey)- m.pendingAlerts[newTrackingKey] = pending- }+ // Pending sustained-for runs are core-owned and keyed by resource ID;+ // a node move restarts an in-flight pending run (firing continuity is+ // preserved through alert adoption). Deliberate simplification.if recent, exists := m.recentAlerts[oldTrackingKey]; exists {delete(m.recentAlerts, oldTrackingKey)diff --git a/internal/alerts/host.go b/internal/alerts/host.goindex 6c46bc27d5..17030b1178 100644--- a/internal/alerts/host.go+++ b/internal/alerts/host.go@@ -5,6 +5,7 @@ import ("strings""time"+ "github.com/rcourtman/pulse-go-rewrite/internal/alerts/reducer"alertspecs "github.com/rcourtman/pulse-go-rewrite/internal/alerts/specs""github.com/rcourtman/pulse-go-rewrite/internal/models""github.com/rcourtman/pulse-go-rewrite/internal/storagehealth"@@ -593,8 +594,10 @@ func (m *Manager) HandleHostOnline(host models.Host) {alertID := canonicalConnectivityStateID(resourceKey)m.mu.Lock()- delete(m.offlineConfirmations, resourceKey)exists := m.hasActiveAlertNoLock(alertID)+ // The host was observed online: a healthy observation ends any+ // in-flight offline confirmation run in the core.+ m.core.ApplyDiscrete(reducer.DiscreteSignal{ResourceID: resourceKey, Key: canonicalConnectivitySpecID(resourceKey), Matched: false, ObservedAt: m.policyNow()}, reducer.DiscreteRule{})m.mu.Unlock()if exists {@@ -735,7 +738,6 @@ func (m *Manager) HandleHostOffline(host models.Host) {if disableHostsOffline {m.mu.Lock()- delete(m.offlineConfirmations, resourceKey)m.mu.Unlock()m.clearAlert(alertID)return@@ -744,7 +746,6 @@ func (m *Manager) HandleHostOffline(host models.Host) {if thresholds.Disabled || thresholds.DisableConnectivity {m.clearAlert(alertID)m.mu.Lock()- delete(m.offlineConfirmations, resourceKey)m.mu.Unlock()return}@@ -768,8 +769,6 @@ func (m *Manager) HandleHostOffline(host models.Host) {Connected: false,},},- Tracking: m.offlineConfirmations,- TrackingKey: resourceKey,AlertID: alertID,AlertType: HostOfflineAlertType,ResourceID: resourceKey,diff --git a/internal/alerts/host_disk_type_test.go b/internal/alerts/host_disk_type_test.goindex 9f26a52eb3..91cd9279d4 100644--- a/internal/alerts/host_disk_type_test.go+++ b/internal/alerts/host_disk_type_test.go@@ -131,9 +131,9 @@ func TestHostDiskFillUsesPerTypeThresholdForNVMe(t *testing.T) {t.Fatalf("expected no alert for nvme disk at 91%% (nvme trigger 92), got active: %v", alertKeys(m))}m.mu.RLock()- if _, pending := m.pendingAlerts[trackingKey]; pending {+ if m.core.PendingCount() != 0 {m.mu.RUnlock()- t.Fatalf("expected no pending alert for nvme disk at 91%%, but pendingAlerts has %q", trackingKey)+ t.Fatalf("expected no pending alert for nvme disk at 91%%, but the core has a pending run")}m.mu.RUnlock()@@ -209,9 +209,9 @@ func TestHostDiskFillPerTypeThresholdDoesNotOverrideDisabledGlobalDefault(t *test.Fatalf("expected no alert when global agent disk threshold is disabled, active: %v", alertKeys(m))}m.mu.RLock()- if _, pending := m.pendingAlerts[trackingKey]; pending {+ if m.core.PendingCount() != 0 {m.mu.RUnlock()- t.Fatalf("expected no pending alert when global agent disk threshold is disabled, but pendingAlerts has %q", trackingKey)+ t.Fatalf("expected no pending alert when global agent disk threshold is disabled, but the core has a pending run")}m.mu.RUnlock()}@@ -241,9 +241,9 @@ func TestHostDiskTempUsesNVMeThreshold(t *testing.T) {t.Fatalf("expected no alert for nvme disk at 62C (nvme trigger 70), got active: %v", alertKeys(m))}m.mu.RLock()- if _, pending := m.pendingAlerts[trackingKey]; pending {+ if m.core.PendingCount() != 0 {m.mu.RUnlock()- t.Fatalf("expected no pending alert for nvme disk at 62C, but pendingAlerts has %q", trackingKey)+ t.Fatalf("expected no pending alert for nvme disk at 62C, but the core has a pending run")}m.mu.RUnlock()@@ -308,9 +308,9 @@ func TestHostDiskTempPerTypeThresholdDoesNotOverrideDisabledGlobalDefault(t *test.Fatalf("expected no alert when global agent disk temperature threshold is disabled, active: %v", alertKeys(m))}m.mu.RLock()- if _, pending := m.pendingAlerts[trackingKey]; pending {+ if m.core.PendingCount() != 0 {m.mu.RUnlock()- t.Fatalf("expected no pending alert when global agent disk temperature threshold is disabled, but pendingAlerts has %q", trackingKey)+ t.Fatalf("expected no pending alert when global agent disk temperature threshold is disabled, but the core has a pending run")}m.mu.RUnlock()}@@ -352,9 +352,9 @@ func TestHostDiskTempExplicitOverrideBeatsPerTypeThreshold(t *testing.T) {t.Fatalf("expected no alert for nvme disk at 75C with explicit override trigger 80, active: %v", alertKeys(m))}m.mu.RLock()- if _, pending := m.pendingAlerts[trackingKey]; pending {+ if m.core.PendingCount() != 0 {m.mu.RUnlock()- t.Fatalf("expected no pending alert for nvme disk at 75C with explicit override trigger 80, but pendingAlerts has %q", trackingKey)+ t.Fatalf("expected no pending alert for nvme disk at 75C with explicit override trigger 80, but the core has a pending run")}m.mu.RUnlock()}diff --git a/internal/alerts/intent_policy.go b/internal/alerts/intent_policy.goindex 8e6bc3c559..18feca0607 100644--- a/internal/alerts/intent_policy.go+++ b/internal/alerts/intent_policy.go@@ -485,7 +485,6 @@ func (m *Manager) PreviewIntentPolicy(request AlertIntentPolicyPreviewRequest) (elapsed = 0}m.intentPending[trackingKey] = IntentPendingState{- TrackingKey: trackingKey, ResourceID: request.ResourceID, ResourceType: request.ResourceType,Signal: request.Signal, FirstMatchedAt: firstMatchedAt, LastObservedAt: now, ElapsedNanos: int64(elapsed),}m.intentRuntimeTicks[trackingKey] = m.intentTickNoLock()diff --git a/internal/alerts/intent_policy_test.go b/internal/alerts/intent_policy_test.goindex 7837f72eca..e9dccb48ff 100644--- a/internal/alerts/intent_policy_test.go+++ b/internal/alerts/intent_policy_test.go@@ -329,7 +329,6 @@ func TestLifecycleAlertStartsAtFirstIntentMatch(t *testing.T) {if err != nil {t.Fatal(err)}- tracking := make(map[string]int)params := canonicalLifecycleAlertParams{Spec: spec,Evidence: alertspecs.AlertEvidence{@@ -339,7 +338,7 @@ func TestLifecycleAlertStartsAtFirstIntentMatch(t *testing.T) {Observed: alertspecs.PowerStateOff,},},- Tracking: tracking, TrackingKey: "vm:101", AlertID: "guest-powered-off-vm:101",+ AlertID: "guest-powered-off-vm:101",AlertType: "powered-off", ResourceID: "vm:101", ResourceName: "database",}if result, _ := m.evaluateCanonicalLifecycleAlert(params); result.State.State != alertspecs.AlertStatePending {diff --git a/internal/alerts/manager.go b/internal/alerts/manager.goindex 6a5857e527..cb0f99220b 100644--- a/internal/alerts/manager.go+++ b/internal/alerts/manager.go@@ -49,8 +49,6 @@ type Manager struct {recentlyResolved map[string]*ResolvedAlertresolvedAlias map[string]stringresolvedMutex sync.RWMutex // Secondary lock - see Lock Ordering Documentation above- // Time threshold tracking- pendingAlerts map[string]time.Time // Track when thresholds were first exceeded// Intent-policy pending state retains server timestamps, accumulated// monotonic elapsed time, and transient-context evidence for policy-enabled// candidates. It is keyed by canonical alert tracking key and persisted@@ -63,10 +61,6 @@ type Manager struct {backupIntentResolver BackupIntentContextResolverresourceIntentResolver ResourceIntentIdentityResolver// Offline confirmation tracking- nodeOfflineCount map[string]int // Track consecutive offline counts for nodes (legacy)- connectionDegradedCount map[string]int // Track consecutive degraded counts for platform connections (pve/pbs/pmg/vmware/truenas)- offlineConfirmations map[string]int // Track consecutive offline counts for all resources- offlineRecoveryConfirmations map[string]int // Track consecutive healthy confirmations before clearing poll-driven offline alerts// core is the authoritative transition state for the canonical// lifecycle (match-spec) family: the deterministic reducer owns// confirmations, pending runs, first-matched anchoring, recovery@@ -77,8 +71,6 @@ type Manager struct {unifiedIncidentConfirmations map[string]int // Track consecutive provider-incident observations before activationunifiedIncidentFirstSeen map[string]time.Time // Preserve the first confirmed observation as lifecycle startunifiedIncidentRecoveries map[string]int // Track consecutive healthy observations before provider-incident recovery- dockerOfflineCount map[string]int // Track consecutive offline counts for Docker hosts- dockerStateConfirm map[string]int // Track consecutive state confirmations for Docker containersdockerRestartTracking map[string]*dockerRestartRecord // Track restart counts and times for restart loop detectiondockerUpdateFirstSeen map[string]time.Time // Track when image updates were first detected for alert delay// Stable identity tracking prevents update-delay resets when host IDs churn.@@ -185,20 +177,13 @@ func NewManagerWithDataDir(dataDir string, options ...ManagerOption) *Manager {suppressedUntil: make(map[string]time.Time),recentlyResolved: make(map[string]*ResolvedAlert),resolvedAlias: make(map[string]string),- pendingAlerts: make(map[string]time.Time),intentPending: make(map[string]IntentPendingState),intentRuntimeTicks: make(map[string]time.Duration),intentPolicies: NewAlertIntentPolicyDocument(),- nodeOfflineCount: make(map[string]int),- connectionDegradedCount: make(map[string]int),- offlineConfirmations: make(map[string]int),- offlineRecoveryConfirmations: make(map[string]int),core: reducer.NewState(),unifiedIncidentConfirmations: make(map[string]int),unifiedIncidentFirstSeen: make(map[string]time.Time),unifiedIncidentRecoveries: make(map[string]int),- dockerOfflineCount: make(map[string]int),- dockerStateConfirm: make(map[string]int),dockerRestartTracking: make(map[string]*dockerRestartRecord),dockerUpdateFirstSeen: make(map[string]time.Time),dockerUpdateFirstSeenByIdentity: make(map[string]time.Time),diff --git a/internal/alerts/migration_characterization_test.go b/internal/alerts/migration_characterization_test.goindex d2034310f5..0d9520133b 100644--- a/internal/alerts/migration_characterization_test.go+++ b/internal/alerts/migration_characterization_test.go@@ -363,7 +363,7 @@ func TestAlertCharacterizationDisableConnectivitySuppressesPoweredOffButNotMetriassertAlertMissing(t, m, "guest-powered-off-"+resourceID)m.mu.RLock()- _, hasConfirmations := m.offlineConfirmations[resourceID]+ hasConfirmations := testCoreHasIncident(m, resourceID, canonicalPoweredStateSpecID(resourceID))m.mu.RUnlock()if hasConfirmations {t.Fatalf("expected powered-off tracking to stay clear when connectivity is disabled")@@ -388,7 +388,7 @@ func TestAlertCharacterizationOnBootFalseSuppressesPoweredOffAlert(t *testing.T)assertAlertMissing(t, m, "guest-powered-off-"+resourceID)m.mu.RLock()- _, hasConfirmations := m.offlineConfirmations[resourceID]+ hasConfirmations := testCoreHasIncident(m, resourceID, canonicalPoweredStateSpecID(resourceID))m.mu.RUnlock()if hasConfirmations {t.Fatalf("expected no powered-off tracking for guest with onboot=false")diff --git a/internal/alerts/node.go b/internal/alerts/node.goindex 340af773a1..223333e0a5 100644--- a/internal/alerts/node.go+++ b/internal/alerts/node.go@@ -29,7 +29,6 @@ func (m *Manager) CheckNode(node models.Node) {// Clear any existing node alerts when all node alerts are disabledm.mu.Lock()// Clear offline tracking- delete(m.nodeOfflineCount, node.ID)// Clear all possible node alert typesalertTypes := []string{"cpu", "memory", "disk", "temperature"}for _, alertType := range alertTypes {@@ -60,7 +59,6 @@ func (m *Manager) CheckNode(node models.Node) {if thresholds.Disabled {m.mu.Lock()- delete(m.nodeOfflineCount, node.ID)m.mu.Unlock()for _, alertID := range []string{canonicalMetricStateID(node.ID, "cpu"),@@ -77,7 +75,6 @@ func (m *Manager) CheckNode(node models.Node) {if disableNodesOffline || thresholds.DisableConnectivity {// Clear tracking and any existing offline alerts when globally disabledm.mu.Lock()- delete(m.nodeOfflineCount, node.ID)m.mu.Unlock()m.clearAlert(canonicalConnectivityStateID(node.ID))} else {@@ -247,7 +244,6 @@ func (m *Manager) checkNodeOffline(node models.Node) {alertID := fmt.Sprintf("node-offline-%s", node.ID)m.mu.Lock()- delete(m.offlineRecoveryConfirmations, canonicalConnectivityStateID(node.ID))m.mu.Unlock()thresholds := m.resolveResourceThresholds("node", node.ID)@@ -264,8 +260,6 @@ func (m *Manager) checkNodeOffline(node models.Node) {_, _ = m.evaluateCanonicalLifecycleAlert(canonicalLifecycleAlertParams{Spec: spec,Evidence: alertspecs.AlertEvidence{ObservedAt: time.Now(), Connectivity: &alertspecs.ConnectivityEvidence{Signal: "status", Connected: false}},- Tracking: m.nodeOfflineCount,- TrackingKey: node.ID,AlertID: alertID,AlertType: "connectivity",ResourceID: node.ID,@@ -295,9 +289,6 @@ func (m *Manager) clearNodeOfflineAlert(node models.Node) {// Reset the legacy offline counter; the reducer core owns the// confirmation run itself.- if m.nodeOfflineCount[node.ID] > 0 {- delete(m.nodeOfflineCount, node.ID)- }m.resolveDiscreteRecoveryNoLock(node.ID, canonicalConnectivitySpecID(node.ID), alertID, offlineRecoveryConfirmationsDefault, "Node", node.Name, node.Instance)}diff --git a/internal/alerts/offline_toggle_test.go b/internal/alerts/offline_toggle_test.goindex c75bbc94b4..f616f29a12 100644--- a/internal/alerts/offline_toggle_test.go+++ b/internal/alerts/offline_toggle_test.go@@ -13,7 +13,7 @@ func TestDisableAllNodesOfflinePreventsOfflineAlert(t *testing.T) {// Reset state to avoid interference from persisted alerts.manager.mu.Lock()manager.activeAlerts = make(map[string]*Alert)- manager.nodeOfflineCount = make(map[string]int)+ manager.core.Reset()manager.mu.Unlock()config := manager.GetConfig()@@ -31,7 +31,7 @@ func TestDisableAllNodesOfflinePreventsOfflineAlert(t *testing.T) {manager.mu.RLock()_, alertExists := manager.activeAlerts["node-offline-node-1"]- _, counterExists := manager.nodeOfflineCount["node-1"]+ counterExists := testCoreHasIncident(manager, "node-1", canonicalConnectivitySpecID("node-1"))manager.mu.RUnlock()if alertExists {@@ -47,7 +47,7 @@ func TestUpdateConfigClearsExistingNodeOfflineAlerts(t *testing.T) {manager.mu.Lock()manager.activeAlerts = make(map[string]*Alert)- manager.nodeOfflineCount = make(map[string]int)+ manager.core.Reset()manager.activeAlerts["node-offline-node-1"] = &Alert{ID: "node-offline-node-1",Type: "connectivity",@@ -57,7 +57,6 @@ func TestUpdateConfigClearsExistingNodeOfflineAlerts(t *testing.T) {StartTime: time.Now().Add(-5 * time.Minute),LastSeen: time.Now(),}- manager.nodeOfflineCount["node-1"] = 3manager.mu.Unlock()config := manager.GetConfig()@@ -69,7 +68,7 @@ func TestUpdateConfigClearsExistingNodeOfflineAlerts(t *testing.T) {manager.mu.RLock()_, alertExists := manager.activeAlerts["node-offline-node-1"]- _, counterExists := manager.nodeOfflineCount["node-1"]+ counterExists := testCoreHasIncident(manager, "node-1", canonicalConnectivitySpecID("node-1"))manager.mu.RUnlock()if alertExists {@@ -101,7 +100,6 @@ func TestUpdateConfigClearsDockerContainerAlertsWhenDisabled(t *testing.T) {for _, id := range containerAlertIDs {manager.activeAlerts[id] = &Alert{ID: id, ResourceID: containerResourceID}}- manager.dockerStateConfirm[containerResourceID] = 2manager.dockerRestartTracking[containerResourceID] = &dockerRestartRecord{}manager.mu.Unlock()@@ -118,8 +116,8 @@ func TestUpdateConfigClearsDockerContainerAlertsWhenDisabled(t *testing.T) {t.Fatalf("expected docker container alert %s to be cleared when DisableAllDockerContainers is enabled", id)}}- if len(manager.dockerStateConfirm) != 0 {- t.Fatalf("expected dockerStateConfirm map to be cleared when DisableAllDockerContainers is enabled")+ if testCoreHasIncident(manager, containerResourceID, canonicalDiscreteStateSpecID(containerResourceID, "runtime-state")) {+ t.Fatalf("expected container state confirmation tracking to be cleared when DisableAllDockerContainers is enabled")}if len(manager.dockerRestartTracking) != 0 {t.Fatalf("expected dockerRestartTracking map to be cleared when DisableAllDockerContainers is enabled")diff --git a/internal/alerts/pbs.go b/internal/alerts/pbs.goindex d29e6511bc..011193071d 100644--- a/internal/alerts/pbs.go+++ b/internal/alerts/pbs.go@@ -38,7 +38,6 @@ func (m *Manager) CheckPBS(pbs models.PBSInstance) {// Clear any existing PBS alerts when all PBS alerts are disabledm.mu.Lock()// Reset offline confirmation tracking- delete(m.offlineConfirmations, pbs.ID)// Clear CPU alertcpuAlertID := canonicalMetricStateID(pbs.ID, "cpu")if m.clearActiveAlertIfPresentNoLock(cpuAlertID) {@@ -75,7 +74,6 @@ func (m *Manager) CheckPBS(pbs models.PBSInstance) {if thresholds.Disabled {m.mu.Lock()// Reset offline confirmation tracking- delete(m.offlineConfirmations, pbs.ID)// Clear CPU alertcpuAlertID := canonicalMetricStateID(pbs.ID, "cpu")if m.clearActiveAlertIfPresentNoLock(cpuAlertID) {@@ -109,7 +107,6 @@ func (m *Manager) CheckPBS(pbs models.PBSInstance) {if disablePBSOffline || thresholds.DisableConnectivity {// Clear tracking and any existing offline alerts when globally disabledm.mu.Lock()- delete(m.offlineConfirmations, pbs.ID)m.mu.Unlock()m.clearAlert(canonicalConnectivityStateID(pbs.ID))} else {@@ -153,7 +150,6 @@ func (m *Manager) checkPBSOffline(pbs models.PBSInstance) {// between this observation's pre-dispatch gate and lifecycle evaluation.func (m *Manager) checkPBSOfflineWithThresholds(pbs models.PBSInstance, thresholds ThresholdConfig) {m.mu.Lock()- delete(m.offlineRecoveryConfirmations, canonicalConnectivityStateID(pbs.ID))m.mu.Unlock()spec, err := buildCanonicalConnectivitySpec(pbs.ID, pbs.Name, unifiedresources.ResourceTypePBS, AlertLevelCritical, 3, thresholds.Disabled || thresholds.DisableConnectivity)@@ -169,8 +165,6 @@ func (m *Manager) checkPBSOfflineWithThresholds(pbs models.PBSInstance, threshol_, _ = m.evaluateCanonicalLifecycleAlert(canonicalLifecycleAlertParams{Spec: spec,Evidence: alertspecs.AlertEvidence{ObservedAt: time.Now(), Connectivity: &alertspecs.ConnectivityEvidence{Signal: "status", Connected: false}},- Tracking: m.offlineConfirmations,- TrackingKey: pbs.ID,AlertID: fmt.Sprintf("pbs-offline-%s", pbs.ID),AlertType: "offline",ResourceID: pbs.ID,diff --git a/internal/alerts/pbs_offline_notification_test.go b/internal/alerts/pbs_offline_notification_test.goindex 36632cda60..046954816e 100644--- a/internal/alerts/pbs_offline_notification_test.go+++ b/internal/alerts/pbs_offline_notification_test.go@@ -131,7 +131,7 @@ func TestCheckPBSOfflineCanonicalOverrideBlocksAlertAndNotification(t *testing.Tt.Fatalf("disabled PBS offline policy created active alerts: %+v", active)}m.mu.RLock()- _, tracked := m.offlineConfirmations[pbs.ID]+ tracked := testCoreHasIncident(m, pbs.ID, canonicalConnectivitySpecID(pbs.ID))m.mu.RUnlock()if tracked {t.Fatalf("disabled PBS offline policy retained confirmation tracking for %q", pbs.ID)@@ -240,7 +240,6 @@ func TestCheckPBSOfflineDoesNotRenotifyExistingAlert(t *testing.T) {}m.mu.Lock()- m.offlineConfirmations["pbs1"] = 3m.setActiveAlertNoLock(state, existing)m.mu.Unlock()diff --git a/internal/alerts/per_metric_delay_example_test.go b/internal/alerts/per_metric_delay_example_test.goindex 83545a41f3..7570a3bc8b 100644--- a/internal/alerts/per_metric_delay_example_test.go+++ b/internal/alerts/per_metric_delay_example_test.go@@ -3,7 +3,6 @@ package alertsimport ("encoding/json""testing"- "time")// TestPerMetricDelayConfiguration demonstrates the per-metric delay feature@@ -133,8 +132,7 @@ func TestPerMetricDelayConfiguration(t *testing.T) {t.Run(tt.name, func(t *testing.T) {// Create a manager with the test configmanager := &Manager{- config: tt.config,- pendingAlerts: make(map[string]time.Time),+ config: tt.config,}// Get the time threshold for this resource/metric combinationdiff --git a/internal/alerts/pmg.go b/internal/alerts/pmg.goindex e062b6ad81..6ab2a71c05 100644--- a/internal/alerts/pmg.go+++ b/internal/alerts/pmg.go@@ -78,7 +78,6 @@ func (m *Manager) CheckPMG(pmg models.PMGInstance) {m.mu.RUnlock()// Clear any existing PMG alerts when all PMG alerts are disabled.m.mu.Lock()- delete(m.offlineConfirmations, pmg.ID)m.mu.Unlock()m.clearPMGMetricAlerts(pmg.ID)m.clearAlert(canonicalConnectivityStateID(pmg.ID))@@ -94,7 +93,6 @@ func (m *Manager) CheckPMG(pmg models.PMGInstance) {// Check override disable BEFORE offline detection to prevent spurious notificationsif hasOverride && override.Disabled {m.mu.Lock()- delete(m.offlineConfirmations, pmg.ID)m.mu.Unlock()m.clearPMGMetricAlerts(pmg.ID)m.clearAlert(canonicalConnectivityStateID(pmg.ID))@@ -107,7 +105,6 @@ func (m *Manager) CheckPMG(pmg models.PMGInstance) {if disablePMGOffline {// Clear tracking and any existing offline alerts when globally disabledm.mu.Lock()- delete(m.offlineConfirmations, pmg.ID)m.mu.Unlock()m.clearAlert(canonicalConnectivityStateID(pmg.ID))} else {@@ -141,7 +138,6 @@ func (m *Manager) CheckPMG(pmg models.PMGInstance) {// checkPMGOffline creates an alert for offline PMG instancesfunc (m *Manager) checkPMGOffline(pmg models.PMGInstance) {m.mu.Lock()- delete(m.offlineRecoveryConfirmations, canonicalConnectivityStateID(pmg.ID))m.mu.Unlock()m.mu.RLock()@@ -161,8 +157,6 @@ func (m *Manager) checkPMGOffline(pmg models.PMGInstance) {_, _ = m.evaluateCanonicalLifecycleAlert(canonicalLifecycleAlertParams{Spec: spec,Evidence: alertspecs.AlertEvidence{ObservedAt: time.Now(), Connectivity: &alertspecs.ConnectivityEvidence{Signal: "status", Connected: false}},- Tracking: m.offlineConfirmations,- TrackingKey: pmg.ID,AlertID: fmt.Sprintf("pmg-offline-%s", pmg.ID),AlertType: "offline",ResourceID: pmg.ID,@@ -952,7 +946,6 @@ func (m *Manager) checkAnomalyMetric(pmg models.PMGInstance, tracker *pmgAnomaly}alertID := fmt.Sprintf("%s-anomaly-%s", pmg.ID, metricName)- pendingKey := fmt.Sprintf("pmg-anomaly-%s-%s", pmg.ID, metricName)spec, err := buildCanonicalBaselineAnomalySpec(alertID, pmg.ID, pmg.Name, unifiedresources.ResourceTypePMG, metricName, 2, false)if err != nil {log.Warn().@@ -965,16 +958,14 @@ func (m *Manager) checkAnomalyMetric(pmg models.PMGInstance, tracker *pmgAnomaly}result, _ := m.evaluateCanonicalStatefulAlert(canonicalStatefulAlertParams{- Spec: spec,- Evidence: alertspecs.AlertEvidence{ObservedAt: now, BaselineAnomaly: &alertspecs.BaselineAnomalyEvidence{Metric: metricName, Observed: current, Baseline: baseline}},- PendingTracking: m.pendingAlerts,- PendingKey: pendingKey,- AlertID: alertID,- AlertType: fmt.Sprintf("anomaly-%s", metricName),- ResourceID: pmg.ID,- ResourceName: pmg.Name,- Node: pmg.Host,- Instance: pmg.Name,+ Spec: spec,+ Evidence: alertspecs.AlertEvidence{ObservedAt: now, BaselineAnomaly: &alertspecs.BaselineAnomalyEvidence{Metric: metricName, Observed: current, Baseline: baseline}},+ AlertID: alertID,+ AlertType: fmt.Sprintf("anomaly-%s", metricName),+ ResourceID: pmg.ID,+ ResourceName: pmg.Name,+ Node: pmg.Host,+ Instance: pmg.Name,MessageBuilder: func(_ alertspecs.EvaluationResult) (string, float64, float64) {return anomalyAlertMessage(pmg, metricName, current, baseline), current, baseline},diff --git a/internal/alerts/pmg_anomaly_test.go b/internal/alerts/pmg_anomaly_test.goindex c276e1dc26..73163629f8 100644--- a/internal/alerts/pmg_anomaly_test.go+++ b/internal/alerts/pmg_anomaly_test.go@@ -59,9 +59,8 @@ func TestCheckPMGAnomalies_QuietSite(t *testing.T) {feedSample(spikeTime, 100)// Verify pending- pendingKey := "pmg-anomaly-pmg1-spamIn"m.mu.Lock()- _, isPending := m.pendingAlerts[pendingKey]+ isPending := testCoreIsPending(m, "pmg1", "pmg1-anomaly-spamIn")m.mu.Unlock()if !isPending {t.Errorf("Expected pending alert for first spike")@@ -136,9 +135,8 @@ func TestCheckPMGAnomalies_NormalSite(t *testing.T) {feedSample(spikeTime, val) // Pending// Verify pending- pendingKey := "pmg-anomaly-pmg2-spamIn"m.mu.Lock()- _, isPending := m.pendingAlerts[pendingKey]+ isPending := testCoreIsPending(m, "pmg2", "pmg2-anomaly-spamIn")m.mu.Unlock()if !isPending {t.Errorf("Expected pending alert for first spike")diff --git a/internal/alerts/powered_off_tolerance_test.go b/internal/alerts/powered_off_tolerance_test.goindex 676c5d77f5..62a212cd31 100644--- a/internal/alerts/powered_off_tolerance_test.go+++ b/internal/alerts/powered_off_tolerance_test.go@@ -63,11 +63,8 @@ func TestPoweredOffToleranceUsesElapsedTimeForVMAndLXC(t *testing.T) {if hasPoweredOffAlert(manager, test.resourceID) {t.Fatal("duplicate reports activated the alert before the duration elapsed")}- manager.mu.RLock()- _, counted := manager.offlineConfirmations[test.resourceID]- manager.mu.RUnlock()- if counted {- t.Fatal("duration-based powered-off policy must not retain poll confirmations")+ if testCoreConfirmations(manager, test.resourceID, canonicalPoweredStateSpecID(test.resourceID)) > 1 {+ t.Fatal("duration-based powered-off policy must not accumulate poll confirmations")}clock.wall, clock.tick = start.Add(299*time.Second), 299*time.Seconddiff --git a/internal/alerts/reducer/reducer.go b/internal/alerts/reducer/reducer.goindex 569c0c284d..b05a85878c 100644--- a/internal/alerts/reducer/reducer.go+++ b/internal/alerts/reducer/reducer.go@@ -290,6 +290,32 @@ func (s *State) FiringCount() int {return count}+// PruneStalePending drops pending (never-activated) incidents whose last+// observation is older than cutoff. A resource that stops being observed+// mid-run would otherwise leak its pending incident forever.+func (s *State) PruneStalePending(cutoff time.Time) int {+ removed := 0+ for key, incident := range s.incidents {+ if incident.State == StatePending && incident.LastObservedAt.Before(cutoff) {+ delete(s.incidents, key)+ removed+++ }+ }+ return removed+}++// PendingCount reports how many incidents are in a pending (not yet+// activated) confirmation or delay run.+func (s *State) PendingCount() int {+ count := 0+ for _, incident := range s.incidents {+ if incident.State == StatePending {+ count+++ }+ }+ return count+}+// isPercentageMetric mirrors the manager's classification: these metrics// live on a 0–100 scale, which caps the derived critical threshold.func isPercentageMetric(metric string) bool {@@ -524,3 +550,45 @@ func (s *State) ShiftPending(delta time.Duration) {}}}++// Reset drops every incident and record — the mirror for the manager's+// full transition-state clears (mock-mode switches, clear-all actions).+func (s *State) Reset() {+ s.incidents = make(map[string]*Incident)+ s.resolved = make(map[string]resolvedRecord)+ s.acks = make(map[string]ackRecord)+}++// DropPendingForResource clears pending (not firing) incidents for one+// resource — the mirror for the manager's per-resource pending resets+// (guest suppression, threshold changes). It reports how many runs were+// dropped so callers can tell whether anything was cleared.+func (s *State) DropPendingForResource(resourceID string) int {+ dropped := 0+ for key, incident := range s.incidents {+ if incident.ResourceID == resourceID && incident.State == StatePending {+ delete(s.incidents, key)+ dropped+++ }+ }+ return dropped+}++// PendingResourceIDs lists the resource IDs with a pending (not firing)+// incident — the enumeration hook for callers that reap runs whose+// resources disappeared (removed containers, decommissioned hosts).+func (s *State) PendingResourceIDs() []string {+ ids := make([]string, 0)+ seen := make(map[string]struct{})+ for _, incident := range s.incidents {+ if incident.State != StatePending {+ continue+ }+ if _, dup := seen[incident.ResourceID]; dup {+ continue+ }+ seen[incident.ResourceID] = struct{}{}+ ids = append(ids, incident.ResourceID)+ }+ return ids+}diff --git a/internal/alerts/reducer_parity_ack_test.go b/internal/alerts/reducer_parity_ack_test.goindex c79fb105b5..f37b8fa44f 100644--- a/internal/alerts/reducer_parity_ack_test.go+++ b/internal/alerts/reducer_parity_ack_test.go@@ -111,8 +111,6 @@ func (e *managerAckParityEngine) step(t *testing.T, s ackParityStep) {ObservedAt: e.clock,DiscreteState: &alertspecs.DiscreteStateEvidence{StateKey: "parity-state", Observed: observed},},- Tracking: e.manager.offlineConfirmations,- TrackingKey: "parity:" + ackParityResourceID,AlertID: e.alertID(),AlertType: "parity-state",ResourceID: ackParityResourceID,diff --git a/internal/alerts/reducer_parity_backup_test.go b/internal/alerts/reducer_parity_backup_test.goindex 6f0293b0da..470b64aafb 100644--- a/internal/alerts/reducer_parity_backup_test.go+++ b/internal/alerts/reducer_parity_backup_test.go@@ -112,8 +112,6 @@ func TestReducerParityWithManagerBackupDeferral(t *testing.T) {ObservedAt: simClock,Connectivity: &alertspecs.ConnectivityEvidence{Signal: "status", Connected: !step.matched},},- Tracking: manager.offlineConfirmations,- TrackingKey: "parity:" + backupParityResourceID,AlertID: alertID,AlertType: "offline",ResourceID: backupParityResourceID,diff --git a/internal/alerts/reducer_parity_discrete_test.go b/internal/alerts/reducer_parity_discrete_test.goindex 63d9824246..388a13d707 100644--- a/internal/alerts/reducer_parity_discrete_test.go+++ b/internal/alerts/reducer_parity_discrete_test.go@@ -101,8 +101,6 @@ func (e *managerDiscreteParityEngine) observe(t *testing.T, step discreteParitySObserved: observed,},},- Tracking: e.manager.offlineConfirmations,- TrackingKey: "parity:" + discreteParityResourceID,AlertID: canonicalDiscreteStateStateID(discreteParityResourceID, discreteParityStateKey),AlertType: "parity-state",ResourceID: discreteParityResourceID,diff --git a/internal/alerts/reducer_parity_intent_test.go b/internal/alerts/reducer_parity_intent_test.goindex 984f8456d2..fd3edecaee 100644--- a/internal/alerts/reducer_parity_intent_test.go+++ b/internal/alerts/reducer_parity_intent_test.go@@ -138,8 +138,6 @@ func TestReducerParityWithManagerIntentGate(t *testing.T) {ObservedAt: simClock,Connectivity: &alertspecs.ConnectivityEvidence{Signal: "status", Connected: !step.matched},},- Tracking: manager.offlineConfirmations,- TrackingKey: "parity:" + intentParityResourceID,AlertID: alertID,AlertType: "offline",ResourceID: intentParityResourceID,diff --git a/internal/alerts/reducer_parity_recovery_test.go b/internal/alerts/reducer_parity_recovery_test.goindex 21a7846606..31c591b391 100644--- a/internal/alerts/reducer_parity_recovery_test.go+++ b/internal/alerts/reducer_parity_recovery_test.go@@ -55,7 +55,6 @@ func (e *managerRecoveryParityEngine) observe(t *testing.T, step recoveryParityS}e.manager.mu.Lock()- delete(e.manager.offlineRecoveryConfirmations, canonicalConnectivityStateID(recoveryParityResourceID))e.manager.mu.Unlock()spec, err := buildCanonicalConnectivitySpec(@@ -71,8 +70,6 @@ func (e *managerRecoveryParityEngine) observe(t *testing.T, step recoveryParitySObservedAt: e.clock,Connectivity: &alertspecs.ConnectivityEvidence{Signal: "status", Connected: false},},- Tracking: e.manager.offlineConfirmations,- TrackingKey: recoveryParityResourceID,AlertID: fmt.Sprintf("pbs-offline-%s", recoveryParityResourceID),AlertType: "offline",ResourceID: recoveryParityResourceID,diff --git a/internal/alerts/reducer_parity_refire_test.go b/internal/alerts/reducer_parity_refire_test.goindex a713263136..fc91e80a20 100644--- a/internal/alerts/reducer_parity_refire_test.go+++ b/internal/alerts/reducer_parity_refire_test.go@@ -75,8 +75,6 @@ func (e *managerRefireParityEngine) observe(t *testing.T, step refireParityStep)ObservedAt: e.clock,DiscreteState: &alertspecs.DiscreteStateEvidence{StateKey: "parity-state", Observed: observed},},- Tracking: e.manager.offlineConfirmations,- TrackingKey: "parity:" + refireParityResourceID,AlertID: canonicalDiscreteStateStateID(refireParityResourceID, "parity-state"),AlertType: "parity-state",ResourceID: refireParityResourceID,diff --git a/internal/alerts/reducer_parity_test.go b/internal/alerts/reducer_parity_test.goindex ce5a03b418..af28496de8 100644--- a/internal/alerts/reducer_parity_test.go+++ b/internal/alerts/reducer_parity_test.go@@ -15,9 +15,9 @@ import (// a reducer bug by definition (docs/ALERT_ENGINE_EVOLUTION.md, Phase 1).//// Time is simulated. The reducer takes it via ObservedAt; the manager's-// delay tracking uses the wall clock, so the harness backdates-// m.pendingAlerts between steps — the same trick the existing-// time-threshold tests use.+// delay tracking uses the wall clock, so the harness backdates the core's+// pending-run start times between steps (m.core.ShiftPending) — the same+// trick the existing time-threshold tests use.type parityStep struct {value float64diff --git a/internal/alerts/resolved_lock_discipline_test.go b/internal/alerts/resolved_lock_discipline_test.goindex a862028c3c..311338a8e0 100644--- a/internal/alerts/resolved_lock_discipline_test.go+++ b/internal/alerts/resolved_lock_discipline_test.go@@ -44,11 +44,8 @@ func TestRecentlyResolvedProductionPathsAreRaceAndDeadlockFree(t *testing.T) {if err != nil {t.Fatal(err)}- lifecycleTracking := make(map[string]int)lifecycleParams := canonicalLifecycleAlertParams{Spec: lifecycleSpec,- Tracking: lifecycleTracking,- TrackingKey: lifecycleResourceID,AlertID: "host-offline-issue-1590-lifecycle",AlertType: "connectivity",ResourceID: lifecycleResourceID,diff --git a/internal/alerts/shadow_feed_test.go b/internal/alerts/shadow_feed_test.goindex 3a4324ff30..e404d6d203 100644--- a/internal/alerts/shadow_feed_test.go+++ b/internal/alerts/shadow_feed_test.go@@ -44,8 +44,6 @@ func shadowObserveConnectivity(t *testing.T, manager *Manager, resourceID stringObservedAt: at,Connectivity: &alertspecs.ConnectivityEvidence{Signal: "status", Connected: connected},},- Tracking: manager.offlineConfirmations,- TrackingKey: resourceID,AlertID: canonicalConnectivityStateID(resourceID),AlertType: "offline",ResourceID: resourceID,diff --git a/internal/alerts/storage.go b/internal/alerts/storage.goindex 6b4b0bef99..3800585208 100644--- a/internal/alerts/storage.go+++ b/internal/alerts/storage.go@@ -5,6 +5,7 @@ import ("strings""time"+ "github.com/rcourtman/pulse-go-rewrite/internal/alerts/reducer"alertspecs "github.com/rcourtman/pulse-go-rewrite/internal/alerts/specs""github.com/rcourtman/pulse-go-rewrite/internal/models""github.com/rcourtman/pulse-go-rewrite/internal/storagehealth"@@ -50,7 +51,9 @@ func (m *Manager) CheckStorage(storage models.Storage) {if thresholds.Disabled {m.mu.Lock()for _, resourceID := range resourceIDs {- delete(m.offlineConfirmations, resourceID)+ // Clear any pending core runs alongside the alerts.+ m.core.ApplyDiscrete(reducer.DiscreteSignal{ResourceID: resourceID, Key: canonicalConnectivitySpecID(resourceID), Matched: false, ObservedAt: m.policyNow()}, reducer.DiscreteRule{})+ m.core.ApplyMetric(reducer.MetricSignal{ResourceID: resourceID, Key: canonicalMetricSpecID(resourceID, "usage"), Metric: "usage", ObservedAt: m.policyNow()}, reducer.MetricRule{})}m.mu.Unlock()for _, resourceID := range resourceIDs {@@ -67,7 +70,7 @@ func (m *Manager) CheckStorage(storage models.Storage) {if thresholds.DisableConnectivity {m.mu.Lock()for _, resourceID := range resourceIDs {- delete(m.offlineConfirmations, resourceID)+ m.core.ApplyDiscrete(reducer.DiscreteSignal{ResourceID: resourceID, Key: canonicalConnectivitySpecID(resourceID), Matched: false, ObservedAt: m.policyNow()}, reducer.DiscreteRule{})}m.mu.Unlock()for _, resourceID := range resourceIDs {@@ -403,7 +406,6 @@ func (m *Manager) checkStorageOffline(storage models.Storage) {alertID := fmt.Sprintf("storage-offline-%s", storage.ID)m.mu.Lock()- delete(m.offlineRecoveryConfirmations, canonicalConnectivityStateID(storage.ID))m.mu.Unlock()m.mu.RLock()@@ -422,8 +424,6 @@ func (m *Manager) checkStorageOffline(storage models.Storage) {_, _ = m.evaluateCanonicalLifecycleAlert(canonicalLifecycleAlertParams{Spec: spec,Evidence: alertspecs.AlertEvidence{ObservedAt: time.Now(), Connectivity: &alertspecs.ConnectivityEvidence{Signal: "status", Connected: false}},- Tracking: m.offlineConfirmations,- TrackingKey: storage.ID,AlertID: alertID,AlertType: "offline",ResourceID: storage.ID,diff --git a/internal/alerts/test_helpers_test.go b/internal/alerts/test_helpers_test.goindex 57fec80ce7..79b569ad0b 100644--- a/internal/alerts/test_helpers_test.go+++ b/internal/alerts/test_helpers_test.go@@ -218,6 +218,13 @@ func testCoreHasIncident(m *Manager, resourceID, specID string) bool {return ok}+// testCoreIsPending reports whether the reducer core tracks a pending (not+// yet activated) incident for the key.+func testCoreIsPending(m *Manager, resourceID, specID string) bool {+ incident, ok := m.core.Incident(resourceID, specID)+ return ok && incident.State == reducer.StatePending+}+// testSeedCoreConfirmations fast-forwards a confirmation run in the// reducer core — the post-cutover replacement for pre-seeding the legacy// count maps. It applies matched observations directly to the core so thediff --git a/internal/alerts/threshold_resolution_shared_test.go b/internal/alerts/threshold_resolution_shared_test.goindex 08d0a73feb..c4c9608658 100644--- a/internal/alerts/threshold_resolution_shared_test.go+++ b/internal/alerts/threshold_resolution_shared_test.go@@ -108,7 +108,7 @@ func TestCheckGuestStoppedUsesResolvedThresholdsForPoweredOff(t *testing.T) {m.mu.RLock()_, alertExists := m.activeAlerts["guest-powered-off-"+guestID]- _, confirmationExists := m.offlineConfirmations[guestID]+ confirmationExists := testCoreHasIncident(m, guestID, canonicalPoweredStateSpecID(guestID))m.mu.RUnlock()if alertExists {@@ -202,7 +202,6 @@ func TestCheckNodeDisabledOverrideClearsExistingAlerts(t *testing.T) {offlineState, offlineAlert := testNewCanonicalAlert(node.ID, canonicalConnectivitySpecID(node.ID), string(alertspecs.AlertSpecKindConnectivity), "offline")m.setActiveAlertNoLock(cpuState, cpuAlert)m.setActiveAlertNoLock(offlineState, offlineAlert)- m.nodeOfflineCount[node.ID] = 3m.mu.Unlock()m.CheckNode(node)@@ -210,7 +209,7 @@ func TestCheckNodeDisabledOverrideClearsExistingAlerts(t *testing.T) {m.mu.RLock()_, cpuExists := m.activeAlerts[cpuState]_, offlineExists := m.activeAlerts[offlineState]- _, countExists := m.nodeOfflineCount[node.ID]+ countExists := testCoreHasIncident(m, node.ID, canonicalConnectivitySpecID(node.ID))m.mu.RUnlock()if cpuExists {@@ -361,14 +360,13 @@ func TestCheckStorageOfflineUsesSharedThresholdResolution(t *testing.T) {},}m.activeAlerts["storage-offline-"+storage.ID] = &Alert{ID: "storage-offline-" + storage.ID}- m.offlineConfirmations[storage.ID] = 1m.mu.Unlock()m.checkStorageOffline(storage)m.mu.RLock()_, alertExists := m.activeAlerts["storage-offline-"+storage.ID]- _, confirmExists := m.offlineConfirmations[storage.ID]+ confirmExists := testCoreHasIncident(m, storage.ID, canonicalConnectivitySpecID(storage.ID))m.mu.RUnlock()if alertExists {diff --git a/internal/alerts/tracking_cleanup.go b/internal/alerts/tracking_cleanup.goindex ec77ca3bc6..f21ef5332b 100644--- a/internal/alerts/tracking_cleanup.go+++ b/internal/alerts/tracking_cleanup.go@@ -1,7 +1,6 @@package alertsimport (- "strings""time""github.com/rs/zerolog/log"@@ -34,6 +33,8 @@ func (m *Manager) cleanupStaleMaps() {staleThreshold := StaleTrackingThresholdcleaned := 0+ cleaned += m.core.PruneStalePending(now.Add(-staleThreshold))+for alertID, history := range m.flappingHistory {if !m.hasActiveAlertNoLock(alertID) {if len(history) == 0 || now.Sub(history[len(history)-1]) > staleThreshold {@@ -51,15 +52,6 @@ func (m *Manager) cleanupStaleMaps() {}}- for alertID, pendingTime := range m.pendingAlerts {- if !m.hasActiveAlertNoLock(alertID) {- if now.Sub(pendingTime) > staleThreshold {- delete(m.pendingAlerts, alertID)- cleaned++- }- }- }-for trackingKey, pending := range m.intentPending {if m.hasActiveAlertNoLock(trackingKey) {continue@@ -70,73 +62,6 @@ func (m *Manager) cleanupStaleMaps() {}}- for resourceID := range m.offlineConfirmations {- hasRelatedAlert := false- for storageKey, alert := range m.activeAlerts {- alertID := effectiveAlertID(alert, storageKey)- if strings.Contains(alertID, resourceID) {- hasRelatedAlert = true- break- }- }- if !hasRelatedAlert {- delete(m.offlineConfirmations, resourceID)- cleaned++- }- }-- for alertID := range m.offlineRecoveryConfirmations {- if !m.hasActiveAlertNoLock(alertID) {- delete(m.offlineRecoveryConfirmations, alertID)- cleaned++- }- }-- for nodeID := range m.nodeOfflineCount {- hasRelatedAlert := false- for storageKey, alert := range m.activeAlerts {- alertID := effectiveAlertID(alert, storageKey)- if strings.Contains(alertID, nodeID) {- hasRelatedAlert = true- break- }- }- if !hasRelatedAlert {- delete(m.nodeOfflineCount, nodeID)- cleaned++- }- }-- for containerID := range m.dockerStateConfirm {- hasRelatedAlert := false- for storageKey, alert := range m.activeAlerts {- alertID := effectiveAlertID(alert, storageKey)- if strings.Contains(alertID, containerID) {- hasRelatedAlert = true- break- }- }- if !hasRelatedAlert {- delete(m.dockerStateConfirm, containerID)- cleaned++- }- }-- for hostID := range m.dockerOfflineCount {- hasRelatedAlert := false- for storageKey, alert := range m.activeAlerts {- alertID := effectiveAlertID(alert, storageKey)- if strings.Contains(alertID, hostID) {- hasRelatedAlert = true- break- }- }- if !hasRelatedAlert {- delete(m.dockerOfflineCount, hostID)- cleaned++- }- }-for containerID, record := range m.dockerRestartTracking {if record != nil && now.Sub(record.lastChecked) > staleThreshold {delete(m.dockerRestartTracking, containerID)diff --git a/internal/alerts/unified_incident_confirmation_test.go b/internal/alerts/unified_incident_confirmation_test.goindex aae80fedb4..caccc38ae2 100644--- a/internal/alerts/unified_incident_confirmation_test.go+++ b/internal/alerts/unified_incident_confirmation_test.go@@ -170,8 +170,6 @@ func TestLifecycleAlertStartTimeIsFirstMatchedObservation(t *testing.T) {ObservedAt: at,DiscreteState: &alertspecs.DiscreteStateEvidence{StateKey: "connectivity", Observed: observed},},- Tracking: manager.offlineConfirmations,- TrackingKey: "conn:node-9",AlertID: canonicalDiscreteStateStateID("node-9", "connectivity"),AlertType: "connectivity",ResourceID: "node-9",@@ -255,8 +253,6 @@ func TestLifecycleRunImmuneToLegacyCountResets(t *testing.T) {ObservedAt: at,DiscreteState: &alertspecs.DiscreteStateEvidence{StateKey: "connectivity", Observed: observed},},- Tracking: manager.offlineConfirmations,- TrackingKey: "conn:node-9",AlertID: canonicalDiscreteStateStateID("node-9", "connectivity"),AlertType: "connectivity",ResourceID: "node-9",@@ -272,9 +268,6 @@ func TestLifecycleRunImmuneToLegacyCountResets(t *testing.T) {// run's true first observation as the start.observe("offline", epoch)observe("offline", epoch.Add(30*time.Second))- manager.mu.Lock()- delete(manager.offlineConfirmations, "conn:node-9")- manager.mu.Unlock()observe("offline", epoch.Add(time.Minute))manager.mu.Lock()