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.

Author detection-time Impact for threshold alerts and propagate through stores

rcourtman1cc20d576835
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 2fdf9bd104..02d465d3be 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -254,7 +254,18 @@ runtime cost control, and shared AI transport surfaces.
binaries) and through the Finding to UnifiedFinding conversion in
`internal/api/router.go` so the operator-facing
`unified.UnifiedFinding` surface receives the same impact string the
- durable investigation record carries. When `/api/ai/chat` receives `finding_id`, the
+ durable investigation record carries. Threshold-alert findings author
+ impact through a parallel hand-curated catalog in
+ `internal/ai/unified/alerts.go` (`generateImpact`), keyed on alert
+ type rather than severity or category, so threshold findings carry
+ consequence-if-ignored copy at detection time without depending on an
+ AI investigation. The unified-store update paths
+ (`UnifiedStore.AddFromAlert` and `UnifiedStore.AddFromAI`) must
+ propagate Impact on re-detected findings the same way they propagate
+ Description and Recommendation: AddFromAlert backfills empty Impact
+ on existing findings; AddFromAI overwrites existing Impact when the
+ incoming finding carries one. Unknown alert types must return an
+ empty impact rather than synthesizing generic copy. When `/api/ai/chat` receives `finding_id`, the
runtime must enrich the provider turn from that durable record while
preserving the user's authored prompt as the persisted conversation
message; the model-only handoff may persist as session metadata so
diff --git a/internal/ai/unified/alerts.go b/internal/ai/unified/alerts.go
index afcac29add..5d9e56decb 100644
--- a/internal/ai/unified/alerts.go
+++ b/internal/ai/unified/alerts.go
@@ -498,6 +498,12 @@ func (s *UnifiedStore) ConvertAlert(alert AlertAdapter) *UnifiedFinding {
finding.Recommendation = generateRecommendation(alertType, alert.GetValue(), alert.GetThreshold())
}
+ // Author detection-time impact text per alert type. The text describes the
+ // operational consequence of operator inaction; it does not vary with
+ // severity or threshold value because the consequence shape is intrinsic
+ // to the alert type.
+ finding.Impact = generateImpact(alertType)
+
return finding
}
@@ -515,6 +521,17 @@ func (s *UnifiedStore) AddFromAlert(alert AlertAdapter) (*UnifiedFinding, bool)
existing.Value = alert.GetValue()
existing.TimesRaised++
+ // Backfill detection-time impact for findings that pre-date the
+ // Impact contract: if the persisted finding has no impact and the
+ // alert type has a curated impact line, adopt it on re-fire.
+ // Description and Recommendation intentionally remain non-refreshed
+ // so this addition does not change historical alert wording.
+ if existing.Impact == "" {
+ if impact := generateImpact(alert.GetAlertType()); impact != "" {
+ existing.Impact = impact
+ }
+ }
+
// Re-open if the finding was resolved (alert fired again)
if existing.ResolvedAt != nil {
existing.ResolvedAt = nil
@@ -606,6 +623,9 @@ func (s *UnifiedStore) AddFromAI(finding *UnifiedFinding) (*UnifiedFinding, bool
if finding.Recommendation != "" {
existing.Recommendation = finding.Recommendation
}
+ if finding.Impact != "" {
+ existing.Impact = finding.Impact
+ }
if finding.Evidence != "" {
existing.Evidence = finding.Evidence
}
@@ -1211,6 +1231,31 @@ func generateTitle(alertType, resourceName string, value, threshold float64) str
}
}
+// generateImpact returns the operator-facing consequence-if-ignored statement
+// for a threshold alert, keyed on alert type. The text is hand-authored per
+// alert kind so the operator sees the same operational consequence regardless
+// of which AI runtime (or none) is active.
+func generateImpact(alertType string) string {
+ switch alertType {
+ case "cpu":
+ return "Workloads on this resource slow down or queue requests; sustained pressure can stall services and propagate latency to dependent workloads."
+ case "memory":
+ return "Memory pressure can trigger OOM kills or swap thrashing, terminating processes or stalling the host until pressure clears."
+ case "disk":
+ return "Writes will start failing when the disk fills, which can corrupt running workloads and stop logging, monitoring, and backup jobs."
+ case "usage", "storage":
+ return "Storage writes will start failing when capacity is exhausted, blocking new data, snapshots, and backup retention."
+ case "temperature":
+ return "Sustained heat throttles performance and shortens hardware life; in critical ranges the system can shut down or fail unexpectedly."
+ case "offline", "nodeOffline":
+ return "Workloads on this resource are unreachable; backups, scheduled jobs, and dependent services on this host stop until it returns."
+ case "poweredOff":
+ return "Nothing on this resource is running, so any workload, backup, or dependent service it provides is unavailable."
+ default:
+ return ""
+ }
+}
+
func generateRecommendation(alertType string, value, threshold float64) string {
switch alertType {
case "cpu":
diff --git a/internal/ai/unified/alerts_test.go b/internal/ai/unified/alerts_test.go
index 21bb1bc752..e8dc6e6b2e 100644
--- a/internal/ai/unified/alerts_test.go
+++ b/internal/ai/unified/alerts_test.go
@@ -1,6 +1,7 @@
package unified
import (
+ "strings"
"testing"
"time"
@@ -53,6 +54,51 @@ func TestUnifiedStore_AddFromAlert(t *testing.T) {
if finding.ResourceID != "vm-101" {
t.Errorf("Expected resource ID vm-101, got %s", finding.ResourceID)
}
+
+ // Impact text is authored per alert type at detection time so the operator
+ // sees consequence-if-ignored copy regardless of whether an AI investigation
+ // has run.
+ if finding.Impact == "" {
+ t.Error("Expected detection-time impact text on cpu alert finding, got empty string")
+ }
+}
+
+func TestGenerateImpact_AuthorsConsequenceForKnownAlertTypes(t *testing.T) {
+ cases := []struct {
+ alertType string
+ mustContain string
+ }{
+ {"cpu", "slow down"},
+ {"memory", "OOM"},
+ {"disk", "fail"},
+ {"usage", "writes will start failing"},
+ {"storage", "writes will start failing"},
+ {"temperature", "throttles"},
+ {"offline", "unreachable"},
+ {"nodeOffline", "unreachable"},
+ {"poweredOff", "unavailable"},
+ }
+ for _, tc := range cases {
+ t.Run(tc.alertType, func(t *testing.T) {
+ impact := generateImpact(tc.alertType)
+ if impact == "" {
+ t.Fatalf("expected non-empty impact for %q", tc.alertType)
+ }
+ if !strings.Contains(strings.ToLower(impact), strings.ToLower(tc.mustContain)) {
+ t.Fatalf("impact for %q missing expected token %q: %s", tc.alertType, tc.mustContain, impact)
+ }
+ })
+ }
+}
+
+func TestGenerateImpact_ReturnsEmptyForUnknownAlertType(t *testing.T) {
+ // Unknown alert types return an empty string rather than synthesizing
+ // generic impact copy. The contract is that impact is hand-authored per
+ // finding source; if the source has no curated text, the operator sees
+ // nothing rather than fabricated analysis.
+ if got := generateImpact("totally-unknown-alert-kind"); got != "" {
+ t.Fatalf("expected empty impact for unknown alert type, got %q", got)
+ }
}
func TestUnifiedStore_AddFromAlert_Update(t *testing.T) {
diff --git a/internal/ai/unified/store_additional_test.go b/internal/ai/unified/store_additional_test.go
index 691622a726..0419901499 100644
--- a/internal/ai/unified/store_additional_test.go
+++ b/internal/ai/unified/store_additional_test.go
@@ -160,6 +160,40 @@ func TestUnifiedStore_AddFromAI_Existing(t *testing.T) {
}
}
+// TestUnifiedStore_AddFromAI_PropagatesImpactOnUpdate covers the path where
+// a re-detected AI patrol finding carries newly-authored Impact text. The
+// update branch must overwrite existing.Impact alongside Description and
+// Recommendation rather than dropping it, so findings persisted by older
+// binaries adopt the freshly-classified impact line on next propagation.
+func TestUnifiedStore_AddFromAI_PropagatesImpactOnUpdate(t *testing.T) {
+ store := NewUnifiedStore(DefaultAlertToFindingConfig())
+ initial := &UnifiedFinding{
+ ID: "ai-impact",
+ Source: SourceAIPatrol,
+ Severity: SeverityWarning,
+ ResourceID: "res-1",
+ Title: "Pulse Patrol: Provider issue",
+ // Impact intentionally empty (older binary persisted this finding)
+ }
+ store.AddFromAI(initial)
+
+ update := &UnifiedFinding{
+ ID: "ai-impact",
+ Source: SourceAIPatrol,
+ Severity: SeverityWarning,
+ ResourceID: "res-1",
+ Title: "Pulse Patrol: Provider issue",
+ Impact: "While Patrol cannot analyze, alerts continue to fire without evidence or recommended actions.",
+ }
+ updated, isNew := store.AddFromAI(update)
+ if isNew {
+ t.Fatalf("expected existing update")
+ }
+ if updated.Impact != update.Impact {
+ t.Fatalf("expected Impact to overwrite on update, got %q", updated.Impact)
+ }
+}
+
func TestUnifiedStore_BasicMutations(t *testing.T) {
store := NewUnifiedStore(DefaultAlertToFindingConfig())
alert := &SimpleAlertAdapter{