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
Hydrate Assistant finding lifecycle context
rcourtman2e8507926354
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.mdindex 9de0684127..95023bd512 100644--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md@@ -366,7 +366,9 @@ profile and assignment columns, but embedded table framing must route throughAI/runtime context selector and still cannot become agent enrollment,lifecycle, or command-websocket authority. Clearing that stored handoff whenthe finding no longer resolves is also AI/runtime invalidation, not an agent- lifecycle transition. Structured Assistant handoff action+ lifecycle transition. Unified finding lifecycle facts included in Assistant+ handoff context remain Patrol/AI review metadata and must not become agent+ lifecycle state or fleet-control authority. Structured Assistant handoff actionreferences from the same Patrol finding remain AI/runtime review metadataonly; lifecycle code must not treat approval IDs, fix IDs, risk, ortarget-resource labels from that handoff as agent command grants, enrollmentdiff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.mdindex f8cde71dc3..83f351410b 100644--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md@@ -192,8 +192,12 @@ runtime cost control, and shared AI transport surfaces.lifecycle authority. If the referenced finding no longer resolves throughthe current unified finding store, Assistant must invalidate the storedmodel-only handoff and unpinned handoff-seeded resource scope instead of- falling back to stale investigation context. Assistant runtime may also- hydrate canonical+ falling back to stale investigation context. The refreshed finding context+ must include unified finding lifecycle and recency facts such as active,+ resolved, snoozed, dismissed or suppressed state, detection/last-seen/+ resolved timestamps, recurrence, regression, and recent lifecycle events so+ Assistant explains the current Patrol record rather than only the original+ investigation narrative. Assistant runtime may also hydrate canonicalresource-policy context for those handoff resources, using the sameunified-resource resolution and policy presentation helpers that governmention prefetch and provider-bound redaction; that context remainsdiff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.mdindex c332da73e4..115df59d30 100644--- a/docs/release-control/v6/internal/subsystems/api-contracts.md+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md@@ -763,7 +763,12 @@ the canonical monitored-system blocked payload.be persisted as user text. If that reference no longer resolves through thecurrent unified finding store, the API/chat boundary must clear the storedhandoff context and unpinned handoff-seeded resource scope rather than- replaying stale investigation state. Chat execution may also hydrate canonical+ replaying stale investigation state. The chat handoff payload must carry the+ unified finding's lifecycle and recency state, including active/resolved/+ snoozed/dismissed/suppressed status, detection/last-seen/resolution+ timestamps, recurrence/regression facts, and recent lifecycle events, so API+ consumers do not reduce Assistant context to an outdated investigation+ summary. Chat execution may also hydrate canonicalresource-policy context for those resources through unified-resourceresolution and shared policy presentation helpers, but the resulting handlingguidance is read-only, model-only context and must not become saved user text,diff --git a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md b/docs/release-control/v6/internal/subsystems/patrol-intelligence.mdindex 69622bf43b..e64fe7f711 100644--- a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md+++ b/docs/release-control/v6/internal/subsystems/patrol-intelligence.md@@ -115,9 +115,14 @@ Patrol-specific presentation helpers.timeline lookups through the current canonical unified-resource model beforefalling back to handoff IDs. If the referenced finding is no longer current,Assistant must drop the stored handoff instead of continuing from stale- Patrol context. Patrol must keep the visible finding and drawer briefing tied- to the shared investigation payload rather than forking a Patrol-local- lifecycle, policy, topology, or timeline summary.+ Patrol context. Assistant handoff context must also carry the unified+ finding's current lifecycle and recency facts, including active/resolved/+ snoozed/dismissed/suppressed state, detection/last-seen/resolution+ timestamps, recurrence/regression, and recent lifecycle events, rather than+ treating the investigation conclusion as the whole current record. Patrol+ must keep the visible finding and drawer briefing tied to the shared+ investigation payload rather than forking a Patrol-local lifecycle, policy,+ topology, or timeline summary.## Current Statediff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.mdindex 47696c13d7..351767fa54 100644--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md@@ -424,7 +424,9 @@ bypass the API fail-closed execution gate.finding no longer resolves is adjacent AI/runtime invalidation, not arecovery freshness or restore-support decision. Structured action orapproval references carried by that handoff are also adjacent AI/runtime- review metadata only;+ review metadata only. Unified finding lifecycle facts carried by the same+ handoff remain Patrol/AI review metadata and must not become backup recency,+ restore support, or storage-local lifecycle state.storage and recovery surfaces must not reinterpret approval IDs, fix IDs,risk, or target labels as restore support, backup freshness, recoveryexecution authority, or a storage-local approval bypass. Any refresheddiff --git a/internal/api/ai_handler.go b/internal/api/ai_handler.goindex 55f27e0886..97671b42e6 100644--- a/internal/api/ai_handler.go+++ b/internal/api/ai_handler.go@@ -794,24 +794,127 @@ func buildUnifiedFindingChatContext(f *unified.UnifiedFinding) string {appendChatContextLine(&b, "[Finding Context]", "")appendChatContextLine(&b, "ID", f.ID)appendChatContextLine(&b, "Title", f.Title)+ appendChatContextLine(&b, "Finding Status", unifiedFindingChatStatus(f, time.Now()))+ appendChatContextLine(&b, "Source", string(f.Source))appendChatContextLine(&b, "Severity", string(f.Severity))appendChatContextLine(&b, "Category", string(f.Category))appendChatContextLine(&b, "Resource", formatChatResource(f.ResourceName, f.ResourceType))appendChatContextLine(&b, "Resource ID", f.ResourceID)+ if !f.DetectedAt.IsZero() {+ appendChatContextLine(&b, "Finding Detected At", f.DetectedAt.Format(time.RFC3339))+ }+ if !f.LastSeenAt.IsZero() {+ appendChatContextLine(&b, "Finding Last Seen At", f.LastSeenAt.Format(time.RFC3339))+ }+ if f.ResolvedAt != nil {+ appendChatContextLine(&b, "Finding Resolved At", f.ResolvedAt.Format(time.RFC3339))+ }+ if f.SnoozedUntil != nil {+ appendChatContextLine(&b, "Finding Snoozed Until", f.SnoozedUntil.Format(time.RFC3339))+ }+ if strings.TrimSpace(f.DismissedReason) != "" {+ appendChatContextLine(&b, "Finding Dismissed Reason", f.DismissedReason)+ }+ if f.Suppressed {+ appendChatContextLine(&b, "Finding Suppressed", "true")+ }+ if f.TimesRaised > 0 {+ appendChatContextLine(&b, "Finding Times Raised", strconv.Itoa(f.TimesRaised))+ }appendChatContextLine(&b, "Description", f.Description)appendChatContextLine(&b, "Recommendation", f.Recommendation)appendChatContextLine(&b, "Evidence", f.Evidence)+ appendChatContextLine(&b, "AI Context", f.AIContext)+ if f.AIConfidence > 0 {+ appendChatContextLine(&b, "AI Confidence", fmt.Sprintf("%.2f", f.AIConfidence))+ }+ if f.AIEnhancedAt != nil {+ appendChatContextLine(&b, "AI Enhanced At", f.AIEnhancedAt.Format(time.RFC3339))+ }+ appendChatContextLine(&b, "Root Cause ID", f.RootCauseID)+ appendStringListChatContext(&b, "Correlated Finding", f.CorrelatedIDs)+ appendChatContextLine(&b, "Remediation ID", f.RemediationID)appendChatContextLine(&b, "Investigation Status", f.InvestigationStatus)appendChatContextLine(&b, "Investigation Outcome", f.InvestigationOutcome)+ if f.LastInvestigatedAt != nil {+ appendChatContextLine(&b, "Last Investigated At", f.LastInvestigatedAt.Format(time.RFC3339))+ }+ if f.InvestigationAttempts > 0 {+ appendChatContextLine(&b, "Investigation Attempts", strconv.Itoa(f.InvestigationAttempts))+ }+ appendChatContextLine(&b, "Loop State", f.LoopState)+ if f.RegressionCount > 0 {+ appendChatContextLine(&b, "Regression Count", strconv.Itoa(f.RegressionCount))+ }+ if f.LastRegressionAt != nil {+ appendChatContextLine(&b, "Last Regression At", f.LastRegressionAt.Format(time.RFC3339))+ }appendChatContextLine(&b, "User Note", f.UserNote)if f.AcknowledgedAt != nil {- appendChatContextLine(&b, "Acknowledged At", f.AcknowledgedAt.Format(time.RFC3339))+ appendChatContextLine(&b, "Finding Acknowledged At", f.AcknowledgedAt.Format(time.RFC3339))}appendChatContextLine(&b, "Node", f.Node)+ appendUnifiedFindingLifecycleEventContext(&b, f.Lifecycle)appendInvestigationRecordChatContext(&b, f.InvestigationRecord)return b.String()}+func unifiedFindingChatStatus(f *unified.UnifiedFinding, now time.Time) string {+ if f == nil {+ return ""+ }+ if f.ResolvedAt != nil {+ return "resolved"+ }+ if f.SnoozedUntil != nil && (now.IsZero() || now.Before(*f.SnoozedUntil)) {+ return "snoozed"+ }+ if f.Suppressed {+ return "suppressed"+ }+ if strings.TrimSpace(f.DismissedReason) != "" {+ return "dismissed"+ }+ return "active"+}++func appendUnifiedFindingLifecycleEventContext(b *strings.Builder, events []unified.UnifiedFindingLifecycleEvent) {+ if len(events) == 0 {+ return+ }++ start := 0+ if len(events) > findingChatContextListLimit {+ start = len(events) - findingChatContextListLimit+ }+ for idx, event := range events[start:] {+ parts := make([]string, 0, 4)+ if !event.At.IsZero() {+ parts = append(parts, event.At.Format(time.RFC3339))+ }+ eventType := strings.TrimSpace(event.Type)+ if eventType != "" {+ parts = append(parts, eventType)+ }+ message := strings.TrimSpace(event.Message)+ if message != "" {+ parts = append(parts, message)+ }+ from := strings.TrimSpace(event.From)+ to := strings.TrimSpace(event.To)+ if from != "" || to != "" {+ parts = append(parts, from+" -> "+to)+ }+ if len(parts) == 0 {+ continue+ }+ appendChatContextLine(b, fmt.Sprintf("Lifecycle Event %d", idx+1), strings.Join(parts, " | "))+ }+ if start > 0 {+ appendChatContextLine(b, "Lifecycle Additional Count", strconv.Itoa(start))+ }+}+func appendInvestigationRecordChatContext(b *strings.Builder, rec *aicontracts.InvestigationRecord) {if rec == nil {returndiff --git a/internal/api/ai_handler_test.go b/internal/api/ai_handler_test.goindex c5d607058e..8aa8bf7cea 100644--- a/internal/api/ai_handler_test.go+++ b/internal/api/ai_handler_test.go@@ -576,7 +576,11 @@ func TestHandleChat_IncludesInvestigationRecordContext(t *testing.T) {h.defaultService = mockSvcdetectedAt := time.Date(2026, 5, 6, 12, 0, 0, 0, time.UTC)+ lastSeenAt := detectedAt.Add(2 * time.Minute)completedAt := detectedAt.Add(3 * time.Minute)+ lastInvestigatedAt := detectedAt.Add(4 * time.Minute)+ aiEnhancedAt := detectedAt.Add(5 * time.Minute)+ lastRegressionAt := detectedAt.Add(6 * time.Minute)store := unified.NewUnifiedStore(unified.DefaultAlertToFindingConfig())store.AddFromAI(&unified.UnifiedFinding{ID: "finding-123",@@ -592,10 +596,32 @@ func TestHandleChat_IncludesInvestigationRecordContext(t *testing.T) {Recommendation: "Review the backup job.",Evidence: "cpu=96%",DetectedAt: detectedAt,- LastSeenAt: detectedAt,+ LastSeenAt: lastSeenAt,+ AIContext: "The spike overlaps the nightly backup job.",+ RootCauseID: "finding-root",+ CorrelatedIDs: []string{"finding-storage"},+ RemediationID: "remediation-123",+ AIConfidence: 0.87,+ AIEnhancedAt: &aiEnhancedAt,InvestigationStatus: "completed",InvestigationOutcome: "fix_queued",+ LastInvestigatedAt: &lastInvestigatedAt,InvestigationAttempts: 1,+ LoopState: "awaiting_approval",+ Lifecycle: []unified.UnifiedFindingLifecycleEvent{{+ At: detectedAt,+ Type: "created",+ Message: "Patrol opened the finding",+ }, {+ At: completedAt,+ Type: "investigation_completed",+ Message: "Fix queued for approval",+ From: "investigating",+ To: "fix_queued",+ }},+ RegressionCount: 2,+ LastRegressionAt: &lastRegressionAt,+ TimesRaised: 3,InvestigationRecord: &aicontracts.InvestigationRecord{ID: "investigation-123",FindingID: "finding-123",@@ -649,6 +675,22 @@ func TestHandleChat_IncludesInvestigationRecordContext(t *testing.T) {assert.Equal(t, "What happened?", reqArg.Prompt)assert.Contains(t, reqArg.HandoffContext, "[Finding Context]")assert.Contains(t, reqArg.HandoffContext, "[Investigation Record]")+ assert.Contains(t, reqArg.HandoffContext, "Finding Status: active")+ assert.Contains(t, reqArg.HandoffContext, "Source: ai-patrol")+ assert.Contains(t, reqArg.HandoffContext, "Finding Detected At: 2026-05-06T12:00:00Z")+ assert.Contains(t, reqArg.HandoffContext, "Finding Last Seen At: 2026-05-06T12:02:00Z")+ assert.Contains(t, reqArg.HandoffContext, "Finding Times Raised: 3")+ assert.Contains(t, reqArg.HandoffContext, "AI Context: The spike overlaps the nightly backup job.")+ assert.Contains(t, reqArg.HandoffContext, "AI Confidence: 0.87")+ assert.Contains(t, reqArg.HandoffContext, "Root Cause ID: finding-root")+ assert.Contains(t, reqArg.HandoffContext, "Correlated Finding 1: finding-storage")+ assert.Contains(t, reqArg.HandoffContext, "Remediation ID: remediation-123")+ assert.Contains(t, reqArg.HandoffContext, "Last Investigated At: 2026-05-06T12:04:00Z")+ assert.Contains(t, reqArg.HandoffContext, "Investigation Attempts: 1")+ assert.Contains(t, reqArg.HandoffContext, "Loop State: awaiting_approval")+ assert.Contains(t, reqArg.HandoffContext, "Regression Count: 2")+ assert.Contains(t, reqArg.HandoffContext, "Last Regression At: 2026-05-06T12:06:00Z")+ assert.Contains(t, reqArg.HandoffContext, "Lifecycle Event 2: 2026-05-06T12:03:00Z | investigation_completed | Fix queued for approval | investigating -> fix_queued")assert.Contains(t, reqArg.HandoffContext, "Resource ID: vm-100")assert.Contains(t, reqArg.HandoffContext, "Subject Resource ID: vm-100")assert.Contains(t, reqArg.HandoffContext, "Conclusion: Backup job saturated CPU.")@@ -732,6 +774,10 @@ func TestHandleChat_RefreshesStoredFindingContextForFollowUp(t *testing.T) {assert.Equal(t, "finding-123", reqArg.FindingID)assert.Equal(t, "What changed?", reqArg.Prompt)assert.Contains(t, reqArg.HandoffContext, "[Finding Context]")+ assert.Contains(t, reqArg.HandoffContext, "Finding Status: resolved")+ assert.Contains(t, reqArg.HandoffContext, "Finding Detected At: 2026-05-06T12:30:00Z")+ assert.Contains(t, reqArg.HandoffContext, "Finding Last Seen At: 2026-05-06T13:00:00Z")+ assert.Contains(t, reqArg.HandoffContext, "Finding Resolved At: 2026-05-06T13:00:00Z")assert.Contains(t, reqArg.HandoffContext, "Title: Backup pressure resolved")assert.Contains(t, reqArg.HandoffContext, "Investigation Outcome: resolved")assert.Contains(t, reqArg.HandoffContext, "User Note: Operator confirmed the maintenance window completed.")@@ -785,6 +831,19 @@ func TestHandleChat_ClearsStoredFindingContextWhenFollowUpFindingMissing(t *testmockSvc.AssertExpectations(t)}+func TestUnifiedFindingChatStatusLifecycleStates(t *testing.T) {+ now := time.Date(2026, 5, 6, 12, 0, 0, 0, time.UTC)+ resolvedAt := now.Add(-time.Minute)+ snoozedUntil := now.Add(time.Hour)++ assert.Equal(t, "active", unifiedFindingChatStatus(&unified.UnifiedFinding{}, now))+ assert.Equal(t, "resolved", unifiedFindingChatStatus(&unified.UnifiedFinding{ResolvedAt: &resolvedAt}, now))+ assert.Equal(t, "snoozed", unifiedFindingChatStatus(&unified.UnifiedFinding{SnoozedUntil: &snoozedUntil}, now))+ assert.Equal(t, "dismissed", unifiedFindingChatStatus(&unified.UnifiedFinding{DismissedReason: "noise"}, now))+ assert.Equal(t, "suppressed", unifiedFindingChatStatus(&unified.UnifiedFinding{Suppressed: true}, now))+ assert.Equal(t, "suppressed", unifiedFindingChatStatus(&unified.UnifiedFinding{DismissedReason: "noise", Suppressed: true}, now))+}+func TestHandleChat_DropsLegacyMentionTypes(t *testing.T) {cfg := &config.Config{}h := newTestAIHandler(cfg, nil, nil)diff --git a/internal/api/contract_test.go b/internal/api/contract_test.goindex 37c161a484..5b462ab0ff 100644--- a/internal/api/contract_test.go+++ b/internal/api/contract_test.go@@ -145,6 +145,25 @@ func TestContract_AssistantFindingContextUsesModelOnlyHandoff(t *testing.T) {"handoffContext = buildUnifiedFindingChatContext(f)","handoffResources = buildUnifiedFindingHandoffResources(f)","handoffActions = buildUnifiedFindingHandoffActions(f)",+ `appendChatContextLine(&b, "Finding Status", unifiedFindingChatStatus(f, time.Now()))`,+ `appendChatContextLine(&b, "Finding Detected At", f.DetectedAt.Format(time.RFC3339))`,+ `appendChatContextLine(&b, "Finding Last Seen At", f.LastSeenAt.Format(time.RFC3339))`,+ `appendChatContextLine(&b, "Finding Resolved At", f.ResolvedAt.Format(time.RFC3339))`,+ `appendChatContextLine(&b, "Finding Snoozed Until", f.SnoozedUntil.Format(time.RFC3339))`,+ `appendChatContextLine(&b, "Finding Dismissed Reason", f.DismissedReason)`,+ `appendChatContextLine(&b, "Finding Suppressed", "true")`,+ `appendChatContextLine(&b, "Finding Times Raised", strconv.Itoa(f.TimesRaised))`,+ `appendChatContextLine(&b, "AI Context", f.AIContext)`,+ `appendChatContextLine(&b, "Root Cause ID", f.RootCauseID)`,+ `appendStringListChatContext(&b, "Correlated Finding", f.CorrelatedIDs)`,+ `appendChatContextLine(&b, "Remediation ID", f.RemediationID)`,+ `appendChatContextLine(&b, "Last Investigated At", f.LastInvestigatedAt.Format(time.RFC3339))`,+ `appendChatContextLine(&b, "Investigation Attempts", strconv.Itoa(f.InvestigationAttempts))`,+ `appendChatContextLine(&b, "Loop State", f.LoopState)`,+ `appendChatContextLine(&b, "Regression Count", strconv.Itoa(f.RegressionCount))`,+ `appendChatContextLine(&b, "Last Regression At", f.LastRegressionAt.Format(time.RFC3339))`,+ "appendUnifiedFindingLifecycleEventContext(&b, f.Lifecycle)",+ `return "suppressed"`,"Prompt:","HandoffContext:","HandoffResources: handoffResources",