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
Broaden regression-counter reset to include LLM-driven cycles
rcourtmanc6a786a36d6d
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.mdindex 05b6c768ee..0a3d241246 100644--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md@@ -601,14 +601,20 @@ auto-resolves any active finding matching the legacy signature`general`) with a clear retirement reason; the pass is idempotentand self-cleaning. The same load pass also resets the`RegressionCount` and clears `LastRegressionAt` on any active-finding whose lifecycle contains an `auto_resolved` event with one-of the two known bogus-signature reasons ("No longer detected by-patrol", "Resource no longer exists in infrastructure"), because-the counter was inflated by the absence-based auto-resolve paths-that have since been gated or removed. The reset appends a-`regression_counter_reset` lifecycle event so the migration only-fires once per finding; genuine recurrences from then on accrue-cleanly.+finding whose lifecycle contains an `auto_resolved` event **when+the finding's category is not eligible for stale-auto-resolve**+(i.e. anything other than `performance` or `capacity`). For+event/persistent categories there is no legitimate absence-driven+resolution path: an `auto_resolved` event there came either from+one of the now-gated absence paths (legacy reason strings still+recognized) or from the LLM `patrol_resolve_finding` tool+(empty-message via `Resolve(_, true)`) which has repeatedly+misjudged findings backed by still-active conditions and reverted+through a regression on the next run. The reset appends a+`regression_counter_reset` lifecycle event so the migration is+idempotent; genuine recurrences from then on accrue cleanly.+Performance/capacity findings retain their counter because the+metric-cleared resolution model is sound there.The overall health score (`calculateOverallHealth` in`internal/ai/intelligence.go`) tiers the "recent Patrol errors" coveragediff --git a/internal/ai/findings.go b/internal/ai/findings.goindex 80cffb639b..04cfded787 100644--- a/internal/ai/findings.go+++ b/internal/ai/findings.go@@ -926,20 +926,33 @@ func (s *FindingsStore) SetPersistence(p FindingsPersistence) error {return nil}-// findingHasBogusAutoResolveCycle reports whether the finding's lifecycle-// contains evidence of the absence-based auto_resolve pattern that was-// removed in the b44d5892f category gate and the alert-mirror rip. The-// signature is an `auto_resolved` lifecycle event whose message matches-// one of the two reasons the legacy absence paths stamped:+// findingHasBogusAutoResolveCycle reports whether the finding's+// RegressionCount was inflated by an unreliable auto_resolve cycle.//-// - "No longer detected by patrol" — emitted by reconcileStaleFindings-// when the LLM didn't re-mention a seeded finding in a successful run-// - "Resource no longer exists in infrastructure" — emitted when a-// finding's resource was missing from the current inventory snapshot+// For event/persistent categories (reliability, backup, security,+// general) there is no legitimate absence-driven resolution path — the+// underlying condition is a discrete event or persistent state that+// only clears on manual operator action or on a verified fix+// (lifecycle event type "verification_passed"). Any `auto_resolved`+// event on such a finding came from either://-// Either reason on an active finding means at least one prior regression-// was driven by the system fighting itself, not by a genuine recurrence,-// so the cumulative counter is no longer trustworthy.+// - One of the two now-gated absence paths (message+// "No longer detected by patrol" or "Resource no longer exists+// in infrastructure"), or+// - An LLM `patrol_resolve_finding` tool call (empty message,+// produced by Resolve(_, true)), which the LLM has repeatedly+// misjudged for findings backed by still-active conditions.+//+// In every observed instance, those auto_resolutions were reverted by+// a regressed event within hours when the underlying condition was+// re-detected — the system fighting itself. So once the lifecycle+// shows any auto_resolved on a non-eligible category and the finding+// is currently active again with a regression count, the counter is+// no longer a trustworthy signal and should be reset.+//+// For performance/capacity findings (eligible-category) we don't+// touch the counter: those categories have a legitimate+// metric-cleared resolution path and the absence model is sound.func findingHasBogusAutoResolveCycle(f *Finding) bool {if f == nil {return false@@ -947,25 +960,22 @@ func findingHasBogusAutoResolveCycle(f *Finding) bool {if f.RegressionCount == 0 {return false}- bogus := false+ if CategorySupportsStaleAutoResolve(f.Category) {+ return false+ }+ hasAutoResolve := falsefor _, e := range f.Lifecycle {if e.Type == "regression_counter_reset" {- // Already migrated — must not be re-applied even if other- // auto_resolved events in the same lifecycle match the bogus- // signature. Genuine regressions accrued after the reset- // stand on their own and the counter is now trustworthy.+ // Already migrated — must not be re-applied. Genuine+ // regressions that accrued after the reset stand on their+ // own and the counter is now trustworthy.return false}- if e.Type != "auto_resolved" {- continue- }- switch e.Message {- case "No longer detected by patrol",- "Resource no longer exists in infrastructure":- bogus = true+ if e.Type == "auto_resolved" {+ hasAutoResolve = true}}- return bogus+ return hasAutoResolve}// isLegacyAlertMirrorFinding reports whether the finding looks like andiff --git a/internal/ai/findings_coverage_test.go b/internal/ai/findings_coverage_test.goindex 02ca70388f..12be7a59b1 100644--- a/internal/ai/findings_coverage_test.go+++ b/internal/ai/findings_coverage_test.go@@ -232,43 +232,83 @@ func TestFindingsStore_SetPersistence_ResetsRegressionCounterPollutedByBogusCycllastRegress := now.Add(-30 * time.Minute)saved := make(chan map[string]*Finding, 1)- withBogusCycle := &Finding{- ID: "with-bogus",+ // Non-eligible category (backup) + auto_resolved on lifecycle + active+ // + regression count > 0 → reset. The auto_resolved messages cover+ // both the empty-message LLM-tool path and the legacy bogus-signature+ // reasons.+ withLLMCycle := &Finding{+ ID: "with-llm-cycle",Severity: FindingSeverityWarning,- ResourceID: "vm-bogus",+ ResourceID: "vm-llm",Title: "Backup failed",Source: "ai-analysis",Category: FindingCategoryBackup,LastSeenAt: now,RegressionCount: 6,LastRegressionAt: &lastRegress,+ Lifecycle: []FindingLifecycleEvent{+ {At: now.Add(-3 * time.Hour), Type: "detected"},+ // Empty message → Resolve(_, true), the LLM patrol_resolve_finding tool.+ {At: now.Add(-2 * time.Hour), Type: "auto_resolved"},+ {At: now.Add(-90 * time.Minute), Type: "regressed"},+ {At: now.Add(-60 * time.Minute), Type: "auto_resolved"},+ {At: lastRegress, Type: "regressed"},+ },+ }++ withLegacyReasonCycle := &Finding{+ ID: "with-legacy-reason",+ Severity: FindingSeverityWarning,+ ResourceID: "vm-legacy",+ Title: "Service crashed",+ Source: "ai-analysis",+ Category: FindingCategoryReliability,+ LastSeenAt: now,+ RegressionCount: 3,+ LastRegressionAt: &lastRegress,Lifecycle: []FindingLifecycleEvent{{At: now.Add(-3 * time.Hour), Type: "detected"},{At: now.Add(-2 * time.Hour), Type: "auto_resolved", Message: "No longer detected by patrol"},- {At: now.Add(-90 * time.Minute), Type: "regressed", Message: "Finding re-detected after resolution"},- {At: now.Add(-60 * time.Minute), Type: "auto_resolved", Message: "Resource no longer exists in infrastructure"},- {At: lastRegress, Type: "regressed", Message: "Finding re-detected after resolution"},+ {At: lastRegress, Type: "regressed"},},}- withRealCycle := &Finding{- ID: "with-real",+ // Eligible category (capacity) — the absence-driven resolution model+ // is sound here, so the counter is trustworthy and must be preserved+ // even if auto_resolved events appear on the lifecycle.+ withEligibleCategory := &Finding{+ ID: "with-eligible",Severity: FindingSeverityWarning,- ResourceID: "vm-real",- Title: "High CPU usage",+ ResourceID: "vm-eligible",+ Title: "Disk nearly full",Source: "ai-analysis",- Category: FindingCategoryPerformance,+ Category: FindingCategoryCapacity,LastSeenAt: now,RegressionCount: 2,LastRegressionAt: &lastRegress,Lifecycle: []FindingLifecycleEvent{{At: now.Add(-2 * time.Hour), Type: "detected"},- // An LLM-driven explicit resolve (empty message via Resolve(_,true)- // is NOT one of the bogus-signature reasons) — the regression- // counter that follows reflects a legitimate recurrence and- // must be preserved.{At: now.Add(-90 * time.Minute), Type: "auto_resolved"},- {At: lastRegress, Type: "regressed", Message: "Finding re-detected after resolution"},+ {At: lastRegress, Type: "regressed"},+ },+ }++ // Active finding on a non-eligible category but no auto_resolved+ // event in lifecycle — counter is genuine, preserve it.+ withoutAutoResolve := &Finding{+ ID: "without-auto",+ Severity: FindingSeverityWarning,+ ResourceID: "vm-clean",+ Title: "Service crashed",+ Source: "ai-analysis",+ Category: FindingCategoryReliability,+ LastSeenAt: now,+ RegressionCount: 1,+ LastRegressionAt: &lastRegress,+ Lifecycle: []FindingLifecycleEvent{+ {At: now.Add(-2 * time.Hour), Type: "detected"},+ {At: now.Add(-90 * time.Minute), Type: "resolved"},+ {At: lastRegress, Type: "regressed"},},}@@ -283,18 +323,19 @@ func TestFindingsStore_SetPersistence_ResetsRegressionCounterPollutedByBogusCyclRegressionCount: 4,LastRegressionAt: &lastRegress,Lifecycle: []FindingLifecycleEvent{- {At: now.Add(-3 * time.Hour), Type: "auto_resolved", Message: "No longer detected by patrol"},+ {At: now.Add(-3 * time.Hour), Type: "auto_resolved"},{At: now.Add(-2 * time.Hour), Type: "regression_counter_reset"},- // Genuine regressions accrued after the migration must be kept.{At: now.Add(-90 * time.Minute), Type: "regressed"},},}p := &recordingPersistence{findings: map[string]*Finding{- withBogusCycle.ID: withBogusCycle,- withRealCycle.ID: withRealCycle,- alreadyMigrated.ID: alreadyMigrated,+ withLLMCycle.ID: withLLMCycle,+ withLegacyReasonCycle.ID: withLegacyReasonCycle,+ withEligibleCategory.ID: withEligibleCategory,+ withoutAutoResolve.ID: withoutAutoResolve,+ alreadyMigrated.ID: alreadyMigrated,},saved: saved,}@@ -303,31 +344,41 @@ func TestFindingsStore_SetPersistence_ResetsRegressionCounterPollutedByBogusCyclt.Fatalf("SetPersistence failed: %v", err)}- bogus := store.Get("with-bogus")- if bogus.RegressionCount != 0 {- t.Fatalf("expected polluted regression counter reset to 0, got %d", bogus.RegressionCount)- }- if bogus.LastRegressionAt != nil {- t.Fatal("expected LastRegressionAt cleared on reset")- }- foundResetEvent := false- for _, e := range bogus.Lifecycle {- if e.Type == "regression_counter_reset" {- foundResetEvent = true- break+ for _, id := range []string{"with-llm-cycle", "with-legacy-reason"} {+ f := store.Get(id)+ if f == nil {+ t.Fatalf("expected finding %s to load", id)+ }+ if f.RegressionCount != 0 {+ t.Fatalf("%s: expected counter reset to 0, got %d", id, f.RegressionCount)+ }+ if f.LastRegressionAt != nil {+ t.Fatalf("%s: expected LastRegressionAt cleared", id)+ }+ reset := false+ for _, e := range f.Lifecycle {+ if e.Type == "regression_counter_reset" {+ reset = true+ break+ }+ }+ if !reset {+ t.Fatalf("%s: expected regression_counter_reset lifecycle event", id)}- }- if !foundResetEvent {- t.Fatal("expected regression_counter_reset lifecycle event on the migrated finding")}- real := store.Get("with-real")- if real.RegressionCount != 2 {- t.Fatalf("finding without bogus signature must keep its regression counter; got %d", real.RegressionCount)- }- for _, e := range real.Lifecycle {- if e.Type == "regression_counter_reset" {- t.Fatal("finding without bogus signature must not gain a reset event")+ for _, id := range []string{"with-eligible", "without-auto"} {+ f := store.Get(id)+ if f == nil {+ t.Fatalf("expected finding %s to load", id)+ }+ if f.RegressionCount == 0 {+ t.Fatalf("%s: counter must not be reset; was reset to 0", id)+ }+ for _, e := range f.Lifecycle {+ if e.Type == "regression_counter_reset" {+ t.Fatalf("%s: must not gain a reset event", id)+ }}}