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.

Simplify incident projection state

rcourtman81cddc10f875
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 96729d084f..4a2d295fe3 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -199,6 +199,13 @@ timeline instead of reading those durable facts only from AI memory. AI memory
may retain annotation-only entries such as notes and analysis, but the live
incident timeline shown to handlers, prompts, and operators should read as one
projection over canonical resource history plus investigation-local annotations.
+That read-side projection must also discard incident-local derived lifecycle
+state when canonical history is present: acknowledgement, resolution, and
+command or runbook entries in `internal/ai/memory/incidents.go` may still
+exist as compatibility-era shell state for segmentation and fallback, but the
+projected incident returned to runtime consumers must rebuild those fields from
+canonical resource changes and preserve only annotation-local entries such as
+analysis and notes.
The AI correlation root-cause engine also consumes the canonical unified-
resource relationship model directly, so cross-resource reasoning stays aligned
with the same relationship edges that back the resource API instead of
diff --git a/internal/ai/memory/incidents.go b/internal/ai/memory/incidents.go
index 1aa8a0d1f7..47c765838a 100644
--- a/internal/ai/memory/incidents.go
+++ b/internal/ai/memory/incidents.go
@@ -238,7 +238,7 @@ func (s *IncidentStore) RecordAlertFired(alert *alerts.Alert) {
incident := s.findOpenIncidentByAlertIdentifierLocked(alert.ID)
if incident == nil {
- incident = newIncidentFromAlert(alert)
+ incident = newIncidentShellFromAlert(alert)
s.incidents = append(s.incidents, incident)
if !s.projectsFromCanonicalLocked() {
s.addEventLocked(incident, IncidentEventAlertFired, formatAlertSummary(alert), map[string]interface{}{
@@ -249,7 +249,7 @@ func (s *IncidentStore) RecordAlertFired(alert *alerts.Alert) {
})
}
} else {
- updateIncidentFromAlert(incident, alert)
+ updateIncidentShellFromAlert(incident, alert)
incident.Status = IncidentStatusOpen
incident.ClosedAt = nil
}
@@ -324,7 +324,7 @@ func (s *IncidentStore) RecordAlertResolved(alert *alerts.Alert, resolvedAt time
incident := s.findOpenIncidentByAlertIdentifierLocked(alert.ID)
if incident == nil {
- incident = newIncidentFromAlert(alert)
+ incident = newIncidentShellFromAlert(alert)
s.incidents = append(s.incidents, incident)
}
@@ -720,14 +720,10 @@ func (s *IncidentStore) projectIncident(incident *Incident, timelineStore Incide
}
projected := cloneIncident(incident)
- projectedKinds := make(map[IncidentEventType]bool, len(projectedEvents))
- for _, event := range projectedEvents {
- projectedKinds[event.Type] = true
- }
-
+ resetDerivedIncidentState(projected)
filtered := make([]IncidentEvent, 0, len(projected.Events)+len(projectedEvents))
for _, event := range projected.Events {
- if isCanonicalProjectedIncidentEventType(event.Type) && projectedKinds[event.Type] {
+ if isCanonicalProjectedIncidentEventType(event.Type) {
continue
}
filtered = append(filtered, cloneIncidentEvent(event))
@@ -1063,7 +1059,7 @@ func cloneIncidentEventDetails(details map[string]any) map[string]interface{} {
return cloned
}
-func newIncidentFromAlert(alert *alerts.Alert) *Incident {
+func newIncidentShellFromAlert(alert *alerts.Alert) *Incident {
openedAt := alert.StartTime
if openedAt.IsZero() {
openedAt = time.Now()
@@ -1088,7 +1084,7 @@ func newIncidentFromAlert(alert *alerts.Alert) *Incident {
}
}
-func updateIncidentFromAlert(incident *Incident, alert *alerts.Alert) {
+func updateIncidentShellFromAlert(incident *Incident, alert *alerts.Alert) {
if incident == nil || alert == nil {
return
}
@@ -1107,13 +1103,24 @@ func updateIncidentFromAlert(incident *Incident, alert *alerts.Alert) {
func (s *IncidentStore) ensureIncidentForAlertLocked(alert *alerts.Alert) *Incident {
incident := s.findLatestIncidentByAlertIdentifierLocked(alert.ID)
if incident == nil {
- incident = newIncidentFromAlert(alert)
+ incident = newIncidentShellFromAlert(alert)
s.incidents = append(s.incidents, incident)
}
- updateIncidentFromAlert(incident, alert)
+ updateIncidentShellFromAlert(incident, alert)
return incident
}
+func resetDerivedIncidentState(incident *Incident) {
+ if incident == nil {
+ return
+ }
+ incident.Status = IncidentStatusOpen
+ incident.ClosedAt = nil
+ incident.Acknowledged = false
+ incident.AckUser = ""
+ incident.AckTime = nil
+}
+
func (s *IncidentStore) addEventLocked(incident *Incident, eventType IncidentEventType, summary string, details map[string]interface{}) {
if incident == nil {
return
diff --git a/internal/ai/memory/incidents_test.go b/internal/ai/memory/incidents_test.go
index 49aa71cb5e..51eb43e3ed 100644
--- a/internal/ai/memory/incidents_test.go
+++ b/internal/ai/memory/incidents_test.go
@@ -176,6 +176,73 @@ func TestIncidentStore_ProjectsCanonicalTimelineWhenAttached(t *testing.T) {
}
}
+func TestIncidentStore_CanonicalProjectionOverridesLegacyLifecycleState(t *testing.T) {
+ store := NewIncidentStore(IncidentStoreConfig{
+ MaxIncidents: 10,
+ MaxEventsPerIncident: 20,
+ MaxAgeDays: 30,
+ })
+
+ alertStartedAt := time.Now().UTC().Add(-20 * time.Minute).Truncate(time.Second)
+ alert := &alerts.Alert{
+ ID: "alert-projected-legacy-1",
+ Type: "cpu",
+ Level: alerts.AlertLevelCritical,
+ ResourceID: "res-projected-legacy-1",
+ ResourceName: "vm-projected-legacy-1",
+ StartTime: alertStartedAt,
+ Value: 96,
+ Threshold: 80,
+ }
+
+ store.RecordAlertFired(alert)
+ store.RecordAlertAcknowledged(alert, "legacy-user")
+ store.RecordRunbook(alert.ID, "rb-legacy", "Restart service", "resolved", true, "Recovered")
+ store.RecordAlertResolved(alert, alertStartedAt.Add(2*time.Minute))
+ store.RecordAnalysis(alert.ID, "Canonical projection should keep this annotation", nil)
+
+ canonicalStore := unifiedresources.NewMemoryStore()
+ store.SetResourceTimelineStore(canonicalStore)
+
+ fired := unifiedresources.BuildAlertTimelineChange(alert.ResourceID, unifiedresources.ChangeAlertFired, alert.StartTime, "", unifiedresources.AlertTimelineChange{
+ AlertIdentifier: alert.ID,
+ AlertType: alert.Type,
+ AlertLevel: string(alert.Level),
+ AlertValue: alert.Value,
+ AlertThreshold: alert.Threshold,
+ })
+ if err := canonicalStore.RecordChange(*fired); err != nil {
+ t.Fatalf("RecordChange(%s): %v", fired.ID, err)
+ }
+
+ timeline := store.GetTimelineByAlertIdentifier(alert.ID)
+ if timeline == nil {
+ t.Fatal("expected projected timeline")
+ }
+ if timeline.Status != IncidentStatusOpen {
+ t.Fatalf("Status = %q, want %q", timeline.Status, IncidentStatusOpen)
+ }
+ if timeline.Acknowledged {
+ t.Fatal("expected canonical projection to clear legacy acknowledgement state")
+ }
+ if timeline.ClosedAt != nil {
+ t.Fatal("expected canonical projection to clear legacy resolved state")
+ }
+
+ foundAnalysis := false
+ for _, event := range timeline.Events {
+ switch event.Type {
+ case IncidentEventAnalysis:
+ foundAnalysis = true
+ case IncidentEventAlertAcknowledged, IncidentEventAlertResolved, IncidentEventRunbook:
+ t.Fatalf("unexpected legacy projected event type %q in canonical timeline", event.Type)
+ }
+ }
+ if !foundAnalysis {
+ t.Fatal("expected annotation events to remain in projected timeline")
+ }
+}
+
func TestIncidentStore_GetTimelineByAlertAt(t *testing.T) {
store := NewIncidentStore(IncidentStoreConfig{
MaxIncidents: 10,
diff --git a/internal/ai/memory/memory_coverage_test.go b/internal/ai/memory/memory_coverage_test.go
index 9092e53dd4..a3f15a137e 100644
--- a/internal/ai/memory/memory_coverage_test.go
+++ b/internal/ai/memory/memory_coverage_test.go
@@ -500,8 +500,8 @@ func TestIncidentStore_HelperPaths(t *testing.T) {
t.Fatalf("expected same incident to be reused")
}
- updateIncidentFromAlert(nil, alert)
- updateIncidentFromAlert(incident, nil)
+ updateIncidentShellFromAlert(nil, alert)
+ updateIncidentShellFromAlert(incident, nil)
store.addEventLocked(nil, IncidentEventAnalysis, "", nil)
store.addEventLocked(incident, IncidentEventAnalysis, "", nil)