Skip to content

armgit / Pulse

Public Imported from GitHub
0

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

Wake operator-state-suppressed findings when the suppression lifts

rcourtmaneae8ca2a6891
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index f73eaa33d6..2f46510707 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -604,6 +604,18 @@ rather than a separate runtime check; the contract test in
either branch cannot silently waste investigation budget on
operator-suppressed findings.
+The operator-state suppression is also reversible. When a finding
+auto-dismissed under `operator_state_cause` re-detects after the
+underlying suppression has lifted (maintenance window passed,
+`IntentionallyOffline` cleared), `FindingsStore.Add` wakes it with
+a `suppression_lifted` lifecycle event. The wake gates on the most
+recent lifecycle dismiss event carrying `operator_state_cause`
+metadata via `findOperatorStateDismissCause`, so a manual operator
+dismissal that supersedes an earlier auto-dismiss is not
+falsely re-awakened — the helper stops at the first `dismissed`
+event when scanning from newest backwards, treating that as the
+authoritative state.
+
When the projection carries an active maintenance window, the
new-finding path auto-dismisses with reason `expected_behavior`,
attributes the suppression on the lifecycle timeline
diff --git a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md b/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
index 893780d8c3..c271d7001b 100644
--- a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
+++ b/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
@@ -1216,3 +1216,15 @@ expected_behavior` and write a `UserNote` naming the cause so the
operator can audit why future findings stayed quiet without
expanding each row. Default deployments without a provider behave
identically to before — operator-state suppression is opt-in.
+
+The auto-dismiss is reversible. When a finding previously
+auto-dismissed under `operator_state_cause` re-detects after the
+suppression has lifted (maintenance window passed,
+`IntentionallyOffline` cleared, or provider unwired), the
+new-finding path wakes it with a `suppression_lifted` lifecycle
+event carrying the previous cause. Time-bounded operator
+commitments do not silently turn into permanent dismissals; manual
+operator dismissals (no `operator_state_cause` metadata) are
+unaffected by this wake path because the helper that detects the
+cause stops at the first `dismissed` event when scanning newest
+first, treating that as the authoritative state.
diff --git a/internal/ai/findings.go b/internal/ai/findings.go
index dcdda88370..c91b9eb012 100644
--- a/internal/ai/findings.go
+++ b/internal/ai/findings.go
@@ -994,6 +994,34 @@ func normalizeLoadedFinding(f *Finding) bool {
return false
}
+// findOperatorStateDismissCause returns the most recent
+// `operator_state_cause` metadata value from the finding's lifecycle, or
+// "" if the finding has not been auto-dismissed by operator-state
+// suppression. Used by the dismissed-branch wake logic in Add to
+// distinguish operator-state-driven dismissals (which should wake when
+// suppression lifts) from manual operator dismissals (which stay quiet
+// until severity escalates).
+func findOperatorStateDismissCause(f *Finding) string {
+ if f == nil {
+ return ""
+ }
+ for i := len(f.Lifecycle) - 1; i >= 0; i-- {
+ ev := f.Lifecycle[i]
+ if ev.Type != "dismissed" {
+ continue
+ }
+ if cause, ok := ev.Metadata["operator_state_cause"]; ok && cause != "" {
+ return cause
+ }
+ // First "dismissed" event without operator_state_cause is a
+ // manual operator dismissal that supersedes any earlier
+ // auto-dismiss; stop scanning so a stale earlier cause does
+ // not falsely trigger a wake.
+ return ""
+ }
+ return ""
+}
+
// syncLoopStateLocked recomputes loop state and records a lifecycle event if it changed.
// Caller must hold s.mu.
func (s *FindingsStore) syncLoopStateLocked(f *Finding) {
@@ -1052,7 +1080,9 @@ func (s *FindingsStore) Add(f *Finding) bool {
}
// Check if dismissed or suppressed - only update if severity has escalated,
- // or if a "will_fix_later" remind-at deadline has passed.
+ // or if a "will_fix_later" remind-at deadline has passed, or if the
+ // operator-state suppression that auto-dismissed the finding is no
+ // longer active.
if existing.DismissedReason != "" || existing.Suppressed {
severityOrder := map[FindingSeverity]int{
FindingSeverityInfo: 0,
@@ -1069,8 +1099,33 @@ func (s *FindingsStore) Add(f *Finding) bool {
existing.RemindAt != nil &&
time.Now().After(*existing.RemindAt) &&
!existing.Suppressed
- if !willFixReminderDue && severityOrder[f.Severity] <= severityOrder[existing.Severity] {
- // New severity is same or lower and there's no reminder due — don't reactivate.
+
+ // Operator-state-driven auto-dismiss should be reversible when the
+ // underlying suppression ends. A maintenance window has a defined
+ // end; an IntentionallyOffline flag can be cleared. Findings
+ // auto-dismissed under either signal must wake at re-detection
+ // once the suppression no longer applies, otherwise the
+ // time-bounded suppression silently becomes permanent.
+ operatorStateLifted := false
+ if !willFixReminderDue && existing.DismissedReason == "expected_behavior" && !existing.Suppressed {
+ if cause := findOperatorStateDismissCause(existing); cause != "" {
+ if provider := s.resourceOperatorStateProvider; provider != nil && existing.ResourceID != "" {
+ projection, ok := provider.OperatorStateProjection(existing.ResourceID, time.Now())
+ currentlySuppressing := ok &&
+ (projection.MaintenanceWindow != nil || projection.IntentionallyOffline)
+ operatorStateLifted = !currentlySuppressing
+ } else {
+ // No provider currently wired but the finding was
+ // previously auto-dismissed by one — treat as lifted
+ // rather than keeping the suppression alive forever.
+ operatorStateLifted = true
+ }
+ }
+ }
+
+ if !willFixReminderDue && !operatorStateLifted &&
+ severityOrder[f.Severity] <= severityOrder[existing.Severity] {
+ // New severity is same or lower and no wake condition fired — don't reactivate.
existing.LastSeenAt = time.Now()
existing.TimesRaised++
s.appendLifecycleLocked(existing, "seen_while_suppressed", "Re-detected while dismissed/suppressed with non-escalated severity", existing.LoopState, existing.LoopState, nil)
@@ -1086,13 +1141,22 @@ func (s *FindingsStore) Add(f *Finding) bool {
}
s.appendLifecycleLocked(existing, "reminded", "will_fix_later remind-at deadline passed; re-surfacing finding", string(FindingLoopStateDismissed), string(FindingLoopStateDetected), meta)
}
- // Severity escalated or remind-at fired - clear dismissal/suppression and reactivate.
+ if operatorStateLifted {
+ meta := map[string]string{}
+ if cause := findOperatorStateDismissCause(existing); cause != "" {
+ meta["previous_cause"] = cause
+ }
+ s.appendLifecycleLocked(existing, "suppression_lifted", "Operator-state suppression no longer applies; re-surfacing finding", string(FindingLoopStateDismissed), string(FindingLoopStateDetected), meta)
+ }
+ // Severity escalated, remind-at fired, or operator-state lifted — clear dismissal and reactivate.
existing.DismissedReason = ""
existing.Suppressed = false
existing.RemindAt = nil
if !willFixReminderDue {
- // On severity escalation we drop the operator's note (situation changed);
- // on a remind-at wake we keep it because the operator's promise is still relevant context.
+ // On severity escalation or operator-state-lift we drop the
+ // operator's note (the suppression that justified it is gone);
+ // on a remind-at wake we keep it because the operator's
+ // promise is still relevant context.
existing.UserNote = ""
}
existing.AcknowledgedAt = nil
diff --git a/internal/ai/findings_test.go b/internal/ai/findings_test.go
index 6e578ec3ee..f66140109a 100644
--- a/internal/ai/findings_test.go
+++ b/internal/ai/findings_test.go
@@ -1818,6 +1818,208 @@ func TestFindingsStore_Add_OperatorStateSuppressionIsOptIn(t *testing.T) {
}
}
+func TestFindingsStore_Add_WakesAfterMaintenanceWindowExpires(t *testing.T) {
+ // Maintenance windows are time-bounded. A finding auto-dismissed
+ // while a window covered `now` must wake at re-detection once the
+ // window has passed and the underlying condition still trips —
+ // otherwise the time-bounded suppression silently becomes
+ // permanent. Pin the wake path with a "suppression_lifted"
+ // lifecycle event so the timeline shows why it came back.
+ store := NewFindingsStore()
+
+ // Phase 1: window covers now, finding auto-dismisses.
+ startInWindow := time.Now().Add(-time.Hour)
+ endInWindow := time.Now().Add(time.Hour)
+ store.SetResourceOperatorStateProvider(
+ ResourceOperatorStateProviderFunc(func(_ string, _ time.Time) (ResourceOperatorStateProjection, bool) {
+ return ResourceOperatorStateProjection{
+ MaintenanceWindow: &ResourceOperatorStateMaintenanceWindow{
+ StartAt: startInWindow,
+ EndAt: endInWindow,
+ },
+ }, true
+ }),
+ )
+ store.Add(&Finding{
+ ID: "f-window-wake",
+ ResourceID: "vm:101",
+ Severity: FindingSeverityWarning,
+ Title: "CPU saturated",
+ })
+ if got := store.Get("f-window-wake"); got == nil || got.DismissedReason != "expected_behavior" {
+ t.Fatalf("setup: expected auto-dismiss; got %+v", got)
+ }
+
+ // Phase 2: window has now passed (provider reports no suppression).
+ // Re-detect at same severity. Existing logic would keep it dismissed
+ // forever; the new wake condition should clear the dismissal.
+ store.SetResourceOperatorStateProvider(
+ ResourceOperatorStateProviderFunc(func(_ string, _ time.Time) (ResourceOperatorStateProjection, bool) {
+ return ResourceOperatorStateProjection{}, false
+ }),
+ )
+ store.Add(&Finding{
+ ID: "f-window-wake",
+ ResourceID: "vm:101",
+ Severity: FindingSeverityWarning,
+ Title: "CPU saturated",
+ })
+
+ got := store.Get("f-window-wake")
+ if got == nil {
+ t.Fatal("finding must still exist after wake")
+ }
+ if got.DismissedReason != "" {
+ t.Errorf("expected dismissal cleared after window expired; got DismissedReason=%q", got.DismissedReason)
+ }
+ if got.AcknowledgedAt != nil {
+ t.Errorf("AcknowledgedAt must be cleared on wake; got %v", got.AcknowledgedAt)
+ }
+ foundWake := false
+ for _, ev := range got.Lifecycle {
+ if ev.Type == "suppression_lifted" && ev.Metadata["previous_cause"] == "maintenance_window" {
+ foundWake = true
+ break
+ }
+ }
+ if !foundWake {
+ t.Error("expected a 'suppression_lifted' lifecycle event with previous_cause=maintenance_window")
+ }
+}
+
+func TestFindingsStore_Add_WakesAfterIntentionallyOfflineCleared(t *testing.T) {
+ // Same shape as the maintenance-window wake, but for the
+ // IntentionallyOffline flag. When the operator clears that flag
+ // (or the provider stops returning it as active), an
+ // auto-dismissed finding must wake at next re-detection.
+ store := NewFindingsStore()
+
+ // Phase 1: IntentionallyOffline=true → auto-dismiss.
+ store.SetResourceOperatorStateProvider(
+ ResourceOperatorStateProviderFunc(func(_ string, _ time.Time) (ResourceOperatorStateProjection, bool) {
+ return ResourceOperatorStateProjection{IntentionallyOffline: true}, true
+ }),
+ )
+ store.Add(&Finding{
+ ID: "f-offline-wake",
+ ResourceID: "vm:archived",
+ Severity: FindingSeverityWarning,
+ Title: "Resource is offline",
+ })
+ if got := store.Get("f-offline-wake"); got == nil || got.DismissedReason != "expected_behavior" {
+ t.Fatalf("setup: expected auto-dismiss; got %+v", got)
+ }
+
+ // Phase 2: operator cleared the flag.
+ store.SetResourceOperatorStateProvider(
+ ResourceOperatorStateProviderFunc(func(_ string, _ time.Time) (ResourceOperatorStateProjection, bool) {
+ return ResourceOperatorStateProjection{IntentionallyOffline: false}, true
+ }),
+ )
+ store.Add(&Finding{
+ ID: "f-offline-wake",
+ ResourceID: "vm:archived",
+ Severity: FindingSeverityWarning,
+ Title: "Resource is offline",
+ })
+ got := store.Get("f-offline-wake")
+ if got == nil {
+ t.Fatal("finding must still exist after wake")
+ }
+ if got.DismissedReason != "" {
+ t.Errorf("expected dismissal cleared after IntentionallyOffline cleared; got DismissedReason=%q", got.DismissedReason)
+ }
+ foundWake := false
+ for _, ev := range got.Lifecycle {
+ if ev.Type == "suppression_lifted" && ev.Metadata["previous_cause"] == "intentionally_offline" {
+ foundWake = true
+ break
+ }
+ }
+ if !foundWake {
+ t.Error("expected a 'suppression_lifted' lifecycle event with previous_cause=intentionally_offline")
+ }
+}
+
+func TestFindingsStore_Add_DoesNotWakeManualOperatorDismissalWhenStateClears(t *testing.T) {
+ // A finding the operator manually dismissed (clicked "Dismiss:
+ // Expected") must NOT wake just because operator-state happens to
+ // have changed for the resource. The manual dismiss is its own
+ // commitment and should not be undone by a parallel state change.
+ // This isolates the wake path to operator-state-driven dismissals
+ // only.
+ store := NewFindingsStore()
+
+ // Operator manually dismisses — no operator_state_cause metadata.
+ store.Add(&Finding{
+ ID: "f-manual",
+ ResourceID: "vm:101",
+ Severity: FindingSeverityWarning,
+ Title: "Disk pressure",
+ })
+ store.Dismiss("f-manual", "expected_behavior", "team flagged this")
+
+ // Provider reports no current suppression — but this dismissal
+ // was never operator-state-driven.
+ store.SetResourceOperatorStateProvider(
+ ResourceOperatorStateProviderFunc(func(_ string, _ time.Time) (ResourceOperatorStateProjection, bool) {
+ return ResourceOperatorStateProjection{}, false
+ }),
+ )
+
+ store.Add(&Finding{
+ ID: "f-manual",
+ ResourceID: "vm:101",
+ Severity: FindingSeverityWarning,
+ Title: "Disk pressure",
+ })
+
+ got := store.Get("f-manual")
+ if got == nil {
+ t.Fatal("finding must still exist")
+ }
+ if got.DismissedReason != "expected_behavior" {
+ t.Errorf("manual dismissal must persist; got DismissedReason=%q", got.DismissedReason)
+ }
+ for _, ev := range got.Lifecycle {
+ if ev.Type == "suppression_lifted" {
+ t.Error("manual dismissal must not emit suppression_lifted")
+ }
+ }
+}
+
+func TestFindOperatorStateDismissCause_PrefersMostRecentDismissEvent(t *testing.T) {
+ // The helper must scan the lifecycle from newest backwards and
+ // stop at the first "dismissed" event. A manual dismiss that
+ // supersedes an earlier auto-dismiss must NOT report the stale
+ // auto-dismiss cause — that would falsely trigger a wake on the
+ // manual dismissal.
+ f := &Finding{
+ Lifecycle: []FindingLifecycleEvent{
+ // Older auto-dismiss with operator_state_cause.
+ {Type: "dismissed", Metadata: map[string]string{"operator_state_cause": "maintenance_window"}},
+ // Operator clears it, then manually dismisses.
+ {Type: "undismissed"},
+ {Type: "dismissed", Metadata: map[string]string{"reason": "expected_behavior"}},
+ },
+ }
+ if got := findOperatorStateDismissCause(f); got != "" {
+ t.Errorf("most recent dismiss is manual; got cause %q want empty", got)
+ }
+
+ // And the opposite: operator-state cause is the most recent → return it.
+ g := &Finding{
+ Lifecycle: []FindingLifecycleEvent{
+ {Type: "dismissed", Metadata: map[string]string{"reason": "expected_behavior"}},
+ {Type: "undismissed"},
+ {Type: "dismissed", Metadata: map[string]string{"operator_state_cause": "intentionally_offline"}},
+ },
+ }
+ if got := findOperatorStateDismissCause(g); got != "intentionally_offline" {
+ t.Errorf("expected most recent operator_state_cause; got %q", got)
+ }
+}
+
func TestFindingsStore_OperatorStateSuppressedFindingsDoNotTriggerInvestigation(t *testing.T) {
// Cross-slice contract: when slice 31/32's operator-state suppression
// fires (maintenance window or intentionally offline), the resulting