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
Preserve scoped Patrol finding decisions
rcourtmanf39e7d1d0f4d
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.mdindex 2ee1ee04f9..7e2f762834 100644--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md@@ -3381,7 +3381,16 @@ friction to each safe investigative step. Scoped Patrol must stillresolve canonical/source IDs and unique aliases before collection, rejectambiguous or unmatched API identities synchronously, persist an error runfor runtime zero-match races, record requested and effective identities,- and summarize only findings within the effective scope. Watch may mutate+ and summarize only findings within the effective scope. A scoped run keeps+ two deliberately different boundaries: its effective evidence scope may+ include related hosts, parents, and dependencies for model reasoning, while+ its finding-lifecycle scope is the exact resolved caller-requested identity+ set. `patrol_get_findings`, report, assess, and resolve must not refresh or+ create a finding on a context-only dependency; the model may cite that+ dependency as evidence for the requested resource and Pro investigation may+ expand causally after Watch is durable. This prevents a targeted workload+ check from surfacing an unrelated host finding merely because the host was+ included as supporting context. Watch may mutateonly finding lifecycle state; Pro investigation remains structurallyread-only. A Watch model-reported finding must not dispatch Proinvestigation from inside the finding tool call: Pulse first persists the@@ -6396,6 +6405,18 @@ Docker-service, or other root-cause tool calls after the repeated-restartsymptom is established; causal analysis belongs to the separate Proinvestigation track. Quiet triage is not a deterministic replacement formodel-owned assessment.+High-confidence deterministic lifecycle flags must nevertheless retain a+model-owned decision opportunity before Watch completes. Health, backup,+connectivity, and learned-anomaly candidates join the existing unmatched signal+evaluation floor after the main agentic pass; ordinary CPU, memory, and disk+threshold crossings stay with Pulse alerting and do not trigger a duplicate+Patrol decision pass. Candidates already covered by a model-authored finding+are skipped, while at most twenty remaining candidates, prioritized with direct+lifecycle failures before learned anomalies, receive one bounded evidence-only+model pass. Pulse must not translate a flag directly into a finding or choose+remediation; this floor exists only so unrelated existing-finding lifecycle+work or a provider's sequential tool calls cannot silently consume the sole+decision opportunity for a confirmed scoped symptom.Model-authored structured findings remain concise for continuous operation:description uses at most three short sentences, impact one sentence, evidencethree concrete facts, and recommendation two short sentences, without@@ -6411,8 +6432,9 @@ receive a tool error and no partial finding may be persisted.During a first-party Patrol run, the general model-facing`pulse_alerts(action=findings)` spelling is a scoped alias for the same activefinding snapshot as `patrol_get_findings` and satisfies the duplicate-check-precondition. The adapter may return only findings inside the run's effective-resource scope, never dismissed history or out-of-scope records. This keeps+precondition. The adapter may return only findings inside the run's resolved+caller-requested finding scope, never dismissed history or context-only+dependency records from the broader effective evidence scope. This keepsordinary model tool choice composable without weakening the lifecycle gate.The provider schema is also the source of truth for the required-argumentchecklist rendered into Patrol's normal and bounded final-decision prompts.diff --git a/internal/ai/patrol_ai.go b/internal/ai/patrol_ai.goindex 02db70e029..3ea05c9dbd 100644--- a/internal/ai/patrol_ai.go+++ b/internal/ai/patrol_ai.go@@ -569,6 +569,9 @@ func (p *PatrolService) runAIAnalysisState(ctx context.Context, snap patrolRuntiobjectiveContext = clonePatrolObjectiveContext(scope.ObjectiveContext)}adapter := newPatrolFindingCreatorAdapterState(p, snap, objectiveContext)+ if scope != nil {+ adapter.setFindingScope(scope.ResourceIDs)+ }// Get chat service and set the finding creator on the executorcs := p.aiService.GetChatService()@@ -903,6 +906,13 @@ func (p *PatrolService) runAIAnalysisState(ctx context.Context, snap patrolRuntisigThresholds := SignalThresholdsFromPatrol(p.thresholds)p.mu.RUnlock()detectedSignals := DetectSignals(signalToolCalls, sigThresholds)+ // The seed's deterministic triage flags are model evidence, not Pulse-owned+ // findings. Include them in the existing unmatched-signal evaluation floor+ // so a provider that spends its main lifecycle turns assessing an unrelated+ // existing finding cannot silently drop a confirmed scoped symptom. The+ // bounded follow-up still asks the model to accept or reject each candidate;+ // Pulse does not manufacture the finding or choose remediation.+ detectedSignals = append(detectedSignals, triageFlagsToDetectedSignals(triageFlagsForDecisionFloor(triageResult.Flags))...)// Merge reachability signals from pre-patrol guest probingreachabilitySignals := DetectReachabilitySignals(guestIntel)@@ -974,6 +984,82 @@ func (p *PatrolService) runAIAnalysisState(ctx context.Context, snap patrolRuntireturn buildAnalysisResult(finalContent, collectedToolCalls, inputTokens, outputTokens), nil}+const patrolTriageDecisionFloorMaxCandidates = 20++func triageFlagsForDecisionFloor(flags []TriageFlag) []TriageFlag {+ if len(flags) == 0 {+ return nil+ }++ // Direct lifecycle failures are more urgent than learned anomalies. Metric+ // threshold flags are intentionally excluded: Pulse's normal alerting owns+ // those simple crossings, and forcing a second model pass would create the+ // duplicate-alert noise Patrol is designed to avoid.+ selected := make([]TriageFlag, 0, min(len(flags), patrolTriageDecisionFloorMaxCandidates))+ appendCategory := func(category string) {+ for _, flag := range flags {+ if len(selected) == patrolTriageDecisionFloorMaxCandidates {+ return+ }+ if strings.EqualFold(strings.TrimSpace(flag.Category), category) {+ selected = append(selected, flag)+ }+ }+ }+ for _, category := range []string{"health", "backup", "connectivity", "anomaly"} {+ appendCategory(category)+ }+ return selected+}++func triageFlagsToDetectedSignals(flags []TriageFlag) []DetectedSignal {+ if len(flags) == 0 {+ return nil+ }++ signals := make([]DetectedSignal, 0, len(flags))+ for _, flag := range flags {+ resourceID := strings.TrimSpace(flag.ResourceID)+ resourceName := strings.TrimSpace(flag.ResourceName)+ if resourceID == "" && resourceName == "" {+ continue+ }++ category := strings.ToLower(strings.TrimSpace(flag.Category))+ switch category {+ case "performance", "capacity", "backup":+ // Already canonical finding categories.+ case "health", "connectivity":+ category = string(FindingCategoryReliability)+ case "anomaly":+ switch strings.ToLower(strings.TrimSpace(flag.Metric)) {+ case "cpu", "memory":+ category = string(FindingCategoryPerformance)+ case "disk", "usage", "storage":+ category = string(FindingCategoryCapacity)+ default:+ category = string(FindingCategoryGeneral)+ }+ default:+ category = string(FindingCategoryGeneral)+ }++ reason := strings.TrimSpace(flag.Reason)+ signals = append(signals, DetectedSignal{+ SignalType: SignalType("triage_" + strings.ToLower(strings.TrimSpace(flag.Category))),+ ResourceID: resourceID,+ ResourceName: resourceName,+ ResourceType: strings.TrimSpace(flag.ResourceType),+ SuggestedSeverity: strings.ToLower(strings.TrimSpace(flag.Severity)),+ Category: category,+ Summary: reason,+ Evidence: reason,+ ToolCallID: "deterministic-triage",+ })+ }+ return signals+}+// runAssessmentSweep runs a bounded follow-up model pass that files the// patrol_assess_finding verdicts the main pass left missing. Uncertain is an// accepted verdict, so the pass asks for an honest call on the presenteddiff --git a/internal/ai/patrol_ai_eval_additional_test.go b/internal/ai/patrol_ai_eval_additional_test.goindex a529ee35ad..11ca045ba8 100644--- a/internal/ai/patrol_ai_eval_additional_test.go+++ b/internal/ai/patrol_ai_eval_additional_test.go@@ -3,6 +3,7 @@ package aiimport ("context""errors"+ "fmt""strings""testing"@@ -38,6 +39,63 @@ func TestEvalPromptBuilders(t *testing.T) {}}+func TestTriageFlagsToDetectedSignalsPreservesModelOwnedCandidates(t *testing.T) {+ flags := []TriageFlag{+ {ResourceID: "app-1", ResourceName: "api", ResourceType: "app-container", Category: "health", Severity: "warning", Reason: "health check is unhealthy"},+ {ResourceID: "node-1", ResourceName: "node", ResourceType: "node", Category: "connectivity", Severity: "critical", Reason: "node is unreachable"},+ {ResourceID: "vm-1", ResourceName: "db", ResourceType: "vm", Category: "anomaly", Metric: "memory", Severity: "watch", Reason: "memory differs from baseline"},+ {ResourceID: "storage-1", ResourceName: "pool", ResourceType: "storage", Category: "anomaly", Metric: "usage", Severity: "warning", Reason: "usage growth differs from baseline"},+ {ResourceID: "misc-1", ResourceName: "misc", ResourceType: "agent", Category: "custom", Severity: "watch", Reason: "custom triage evidence"},+ {Category: "health", Severity: "warning", Reason: "identity-free evidence must be ignored"},+ }++ signals := triageFlagsToDetectedSignals(flags)+ if len(signals) != 5 {+ t.Fatalf("signal count = %d, want 5: %+v", len(signals), signals)+ }+ wantCategories := []string{"reliability", "reliability", "performance", "capacity", "general"}+ for i, wantCategory := range wantCategories {+ if signals[i].Category != wantCategory {+ t.Fatalf("signal %d category = %q, want %q", i, signals[i].Category, wantCategory)+ }+ if signals[i].Summary != flags[i].Reason || signals[i].Evidence != flags[i].Reason {+ t.Fatalf("signal %d lost deterministic evidence: %+v", i, signals[i])+ }+ if signals[i].ToolCallID != "deterministic-triage" {+ t.Fatalf("signal %d source = %q, want deterministic-triage", i, signals[i].ToolCallID)+ }+ }+}++func TestTriageFlagsForDecisionFloorPrioritizesLifecycleEvidence(t *testing.T) {+ flags := []TriageFlag{+ {ResourceID: "metric", Category: "performance", Reason: "ordinary threshold crossing"},+ {ResourceID: "anomaly", Category: "anomaly", Reason: "learned anomaly"},+ {ResourceID: "health", Category: "health", Reason: "failed health check"},+ {ResourceID: "backup", Category: "backup", Reason: "backup failed"},+ {ResourceID: "network", Category: "connectivity", Reason: "endpoint unreachable"},+ }++ selected := triageFlagsForDecisionFloor(flags)+ if len(selected) != 4 {+ t.Fatalf("selected = %+v, want four lifecycle/anomaly candidates", selected)+ }+ wantIDs := []string{"health", "backup", "network", "anomaly"}+ for i, wantID := range wantIDs {+ if selected[i].ResourceID != wantID {+ t.Fatalf("selected[%d] = %q, want %q", i, selected[i].ResourceID, wantID)+ }+ }++ many := make([]TriageFlag, patrolTriageDecisionFloorMaxCandidates+5)+ for i := range many {+ many[i] = TriageFlag{ResourceID: fmt.Sprintf("health-%d", i), Category: "health"}+ }+ if got := len(triageFlagsForDecisionFloor(many)); got != patrolTriageDecisionFloorMaxCandidates {+ t.Fatalf("bounded candidate count = %d, want %d", got, patrolTriageDecisionFloorMaxCandidates)+ }+}+func TestRunEvaluationPass(t *testing.T) {ps := NewPatrolService(&Service{}, nil)_, err := ps.runEvaluationPass(context.Background(), nil, []DetectedSignal{{SignalType: SignalHighCPU}}, "patrol-run-eval")diff --git a/internal/ai/patrol_ai_more_test.go b/internal/ai/patrol_ai_more_test.goindex b8696e8d52..fcdcc5d91f 100644--- a/internal/ai/patrol_ai_more_test.go+++ b/internal/ai/patrol_ai_more_test.go@@ -442,6 +442,9 @@ func TestRunAIAnalysis_RetriesWithProviderDerivedSeedBudget(t *testing.T) {mockCS := &mockChatService{executor: executor,executePatrolStreamFunc: func(ctx context.Context, req PatrolExecuteRequest, callback ChatStreamCallback) (*PatrolStreamResponse, error) {+ if req.SessionID == "patrol-eval" {+ return &PatrolStreamResponse{Content: "no additional findings"}, nil+ }promptTokens = append(promptTokens, chat.EstimateTokens(req.Prompt))executionIDs = append(executionIDs, req.ExecutionID)if len(promptTokens) == 1 {diff --git a/internal/ai/patrol_findings.go b/internal/ai/patrol_findings.goindex fe9f729fc6..964aa80a0d 100644--- a/internal/ai/patrol_findings.go+++ b/internal/ai/patrol_findings.go@@ -502,9 +502,16 @@ type chatServiceExecutorAccessor interface {// patrolFindingCreatorAdapter implements tools.PatrolFindingCreator by wrapping// the PatrolService's existing FindingsStore and recordFinding method.type patrolFindingCreatorAdapter struct {- patrol *PatrolService- snap patrolRuntimeState- objectiveContext *aicontracts.PatrolObjectiveContext+ patrol *PatrolService+ snap patrolRuntimeState+ objectiveContext *aicontracts.PatrolObjectiveContext+ // findingScope is the resolved caller-requested resource identity set for a+ // scoped run. The runtime snapshot may also contain related parent/host+ // resources so the model can reason across dependencies, but those context+ // resources must not silently join the finding lifecycle. A targeted Watch+ // of one workload should not refresh an unrelated host finding merely+ // because Pulse supplied the host as supporting evidence.+ findingScope map[string]boolfindingsMu sync.Mutexfindings []*Findingassessments []PatrolFindingAssessment@@ -514,6 +521,19 @@ type patrolFindingCreatorAdapter struct {checkedFindings bool}+func (a *patrolFindingCreatorAdapter) setFindingScope(resourceIDs []string) {+ if a == nil {+ return+ }+ scope := make(map[string]bool, len(resourceIDs))+ for _, resourceID := range resourceIDs {+ if resourceID = strings.TrimSpace(resourceID); resourceID != "" {+ scope[resourceID] = true+ }+ }+ a.findingScope = scope+}+func newPatrolFindingCreatorAdapterState(p *PatrolService, snap patrolRuntimeState, objectiveContexts ...*aicontracts.PatrolObjectiveContext) *patrolFindingCreatorAdapter {var objectiveContext *aicontracts.PatrolObjectiveContextif len(objectiveContexts) > 0 {@@ -527,6 +547,10 @@ func newPatrolFindingCreatorAdapterState(p *PatrolService, snap patrolRuntimeSta}func (a *patrolFindingCreatorAdapter) CreateFinding(input tools.PatrolFindingInput) (string, bool, error) {+ if !a.findingInCurrentScope(&Finding{ResourceID: input.ResourceID, ResourceName: input.ResourceName}) {+ return "", false, fmt.Errorf("resource %s is outside the requested patrol finding scope", input.ResourceID)+ }+// Map severityvar sev FindingSeverityswitch strings.ToLower(input.Severity) {@@ -633,6 +657,9 @@ func (a *patrolFindingCreatorAdapter) findingInCurrentScope(finding *Finding) boif finding == nil {return false}+ if len(a.findingScope) > 0 {+ return a.findingScope[finding.ResourceID] || a.findingScope[finding.ResourceName]+ }scopedResources := patrolRuntimeKnownResources(a.snap)return len(scopedResources) == 0 || scopedResources[finding.ResourceID] || scopedResources[finding.ResourceName]}@@ -922,11 +949,8 @@ func (a *patrolFindingCreatorAdapter) ResolveFinding(findingID, reason string) ereturn fmt.Errorf("finding %s not found or already resolved", findingID)}- scopedResources := patrolRuntimeKnownResources(a.snap)- if len(scopedResources) > 0 {- if !scopedResources[finding.ResourceID] && !scopedResources[finding.ResourceName] {- return fmt.Errorf("finding %s is outside the current patrol scope", findingID)- }+ if !a.findingInCurrentScope(finding) {+ return fmt.Errorf("finding %s is outside the current patrol scope", findingID)}// Event/persistent categories (backup, reliability, security, general)@@ -1022,13 +1046,12 @@ func (a *patrolFindingCreatorAdapter) GetActiveFindings(resourceID, minSeverity}active := a.patrol.findings.GetActive(minSev)- scopedResources := patrolRuntimeKnownResources(a.snap)var result []tools.PatrolFindingInfofor _, f := range active {if resourceID != "" && f.ResourceID != resourceID && f.ResourceName != resourceID {continue}- if len(scopedResources) > 0 && !scopedResources[f.ResourceID] && !scopedResources[f.ResourceName] {+ if !a.findingInCurrentScope(f) {continue}result = append(result, tools.PatrolFindingInfo{diff --git a/internal/ai/patrol_findings_additional_test.go b/internal/ai/patrol_findings_additional_test.goindex 0d4281aa99..4597d7e9b7 100644--- a/internal/ai/patrol_findings_additional_test.go+++ b/internal/ai/patrol_findings_additional_test.go@@ -1518,3 +1518,34 @@ func TestPatrolFindingAssessmentAmbiguousFragmentDoesNotResolve(t *testing.T) {t.Fatal("ambiguous fragment matching two findings must not resolve")}}++func TestPatrolFindingAdapterSeparatesRequestedLifecycleScopeFromEvidenceScope(t *testing.T) {+ state := newPatrolRuntimeState(models.StateSnapshot{+ VMs: []models.VM{+ {ID: "vm-requested", Name: "requested", VMID: 501},+ {ID: "vm-context", Name: "context-only", VMID: 502},+ },+ })+ ps := NewPatrolService(nil, nil)+ for _, finding := range []*Finding{+ {ID: "requested-finding", Key: "service-unhealthy", Severity: FindingSeverityWarning, Category: FindingCategoryReliability, ResourceID: "vm-requested", ResourceName: "requested", ResourceType: "vm", Title: "Requested workload unhealthy"},+ {ID: "context-finding", Key: "updates-pending", Severity: FindingSeverityWarning, Category: FindingCategoryReliability, ResourceID: "vm-context", ResourceName: "context-only", ResourceType: "vm", Title: "Context host updates pending"},+ } {+ ps.findings.Add(finding)+ }++ adapter := newPatrolFindingCreatorAdapterState(ps, state)+ adapter.setFindingScope([]string{"vm-requested"})+ active := adapter.GetActiveFindings("", "")+ if len(active) != 1 || active[0].ID != "requested-finding" {+ t.Fatalf("active findings = %+v, want only requested-finding", active)+ }++ if _, _, err := adapter.CreateFinding(tools.PatrolFindingInput{+ ResourceID: "vm-context", ResourceName: "context-only", ResourceType: "vm",+ Key: "context-new", Severity: "warning", Category: "reliability", Title: "Context-only issue",+ Description: "context-only evidence", Evidence: "context-only evidence", Recommendation: "review context-only issue",+ }); err == nil || !strings.Contains(err.Error(), "outside the requested patrol finding scope") {+ t.Fatalf("context-only finding must be rejected by lifecycle scope, got %v", err)+ }+}