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
Gate LLM patrol_resolve_finding on deterministic verifier for event findings
rcourtman7a7b3c9d307f
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.mdindex 8da1a482c0..9f604d386c 100644--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md@@ -108,7 +108,7 @@ runtime cost control, and shared AI transport surfaces.## Completion Obligations-1. Update this contract when canonical AI runtime or transport entry points move, including transport-level provider request-shape changes such as DeepSeek `tool_choice` coercion, runtime-failure classification splits (for example separating forced tool selection rejection, no tool-capable endpoint, and generic model-level lack of tool support into distinct causes), Patrol-specific verification surfaces such as `POST /api/ai/patrol/preflight` that exercise the full chat-completions path with a minimal tool definition rather than only listing models, Patrol-preflight cache observability where the AI Service caches the most recent preflight outcome (success, soft warning, or classified failure) and the AI settings response surfaces it as `patrol_preflight` so the UI can hydrate a "last verified" indicator without forcing operators to re-run preflight on every page load, the auto-trigger contract on `HandleUpdateAISettings` where the save handler runs `TriggerPatrolPreflightAsync` only when the change actually moved Patrol transport (model swap, provider key for that model changed, or assistant just enabled with a Patrol model) so routine settings saves do not burn provider tokens, the startup-seed contract where the AI Service handler dispatches the same async preflight on Pulse boot when assistant is enabled and a Patrol model is configured so the cache is populated for the first `/api/settings/ai` poll after a restart instead of blanking back to "never verified", the readiness-integration contract where the `tools` check in the Patrol readiness payload consults the cached preflight and surfaces the classified evidence (success, soft warning, or failure with classified summary plus "last preflight <age>") for the configured provider+model when available (falling back to the static `PatrolToolReadinessForModel` classifier only when the cache is empty or holds a result for a different model), and the stateless-Patrol-input contract where `ExecutePatrolStream` must pass only the current run's user prompt into the agentic loop rather than reloading the persisted `patrol-main` session history (so a prior run that ended with orphan `tool_calls` cannot poison every subsequent run with malformed conversation structure)+1. Update this contract when canonical AI runtime or transport entry points move, including transport-level provider request-shape changes such as DeepSeek `tool_choice` coercion, runtime-failure classification splits (for example separating forced tool selection rejection, no tool-capable endpoint, and generic model-level lack of tool support into distinct causes), Patrol-specific verification surfaces such as `POST /api/ai/patrol/preflight` that exercise the full chat-completions path with a minimal tool definition rather than only listing models, Patrol-preflight cache observability where the AI Service caches the most recent preflight outcome (success, soft warning, or classified failure) and the AI settings response surfaces it as `patrol_preflight` so the UI can hydrate a "last verified" indicator without forcing operators to re-run preflight on every page load, the auto-trigger contract on `HandleUpdateAISettings` where the save handler runs `TriggerPatrolPreflightAsync` only when the change actually moved Patrol transport (model swap, provider key for that model changed, or assistant just enabled with a Patrol model) so routine settings saves do not burn provider tokens, the startup-seed contract where the AI Service handler dispatches the same async preflight on Pulse boot when assistant is enabled and a Patrol model is configured so the cache is populated for the first `/api/settings/ai` poll after a restart instead of blanking back to "never verified", the readiness-integration contract where the `tools` check in the Patrol readiness payload consults the cached preflight and surfaces the classified evidence (success, soft warning, or failure with classified summary plus "last preflight <age>") for the configured provider+model when available (falling back to the static `PatrolToolReadinessForModel` classifier only when the cache is empty or holds a result for a different model), the stateless-Patrol-input contract where `ExecutePatrolStream` must pass only the current run's user prompt into the agentic loop rather than reloading the persisted `patrol-main` session history (so a prior run that ended with orphan `tool_calls` cannot poison every subsequent run with malformed conversation structure), and the deterministic-resolve-gate contract where the `patrol_resolve_finding` tool adapter rejects LLM-driven resolves of event/persistent category findings (`backup`, `reliability`, `security`, `general`) when a deterministic verifier exists for the finding's key and that verifier still detects the failure signal — preventing the LLM from optimistically resolving a finding its current investigation simply didn't re-surface, which was the source of the "Backup failed" flap (detected → auto-resolved → re-detected ten times in a day before this gate)2. Keep AI runtime and shared API proof routing aligned in `registry.json`3. Preserve explicit coverage for chat, Patrol, remediation, and cost-control behavior when AI runtime changesPatrol runtime failures are part of that runtime contract: provider, model,diff --git a/internal/ai/patrol_findings.go b/internal/ai/patrol_findings.goindex 43a66dae32..876c260642 100644--- a/internal/ai/patrol_findings.go+++ b/internal/ai/patrol_findings.go@@ -971,17 +971,56 @@ func (a *patrolFindingCreatorAdapter) actionabilityResourceMetrics() (map[string}func (a *patrolFindingCreatorAdapter) ResolveFinding(findingID, reason string) error {+ finding := a.patrol.findings.Get(findingID)+ if finding == nil {+ return fmt.Errorf("finding %s not found or already resolved", findingID)+ }+scopedResources := patrolRuntimeKnownResources(a.snap)if len(scopedResources) > 0 {- finding := a.patrol.findings.Get(findingID)- if finding == nil {- return fmt.Errorf("finding %s not found or already resolved", findingID)- }if !scopedResources[finding.ResourceID] && !scopedResources[finding.ResourceName] {return fmt.Errorf("finding %s is outside the current patrol scope", findingID)}}+ // Event/persistent categories (backup, reliability, security, general)+ // must not be auto-resolved on absence — see the contract at+ // findings.go:CategorySupportsStaleAutoResolve. Before today's gate,+ // the LLM could call patrol_resolve_finding for a backup-failed finding+ // because its current investigation didn't surface a fresh failure+ // signal, and the next run's detector would re-detect the same+ // unresolved task. The "Backup failed" finding flapped 10x in a day+ // before this gate landed.+ //+ // For these categories, when a deterministic verifier exists for the+ // finding's key, run it before honoring the LLM's resolve. If the+ // verifier says the failure signal is still present, reject — the+ // underlying issue hasn't actually cleared. If the verifier confirms+ // the signal is gone, the LLM's resolve is grounded in real evidence.+ // Findings without a verifier fall through to the current trust-the-LLM+ // behavior to avoid regressing categories we haven't built verifiers+ // for yet.+ if !CategorySupportsStaleAutoResolve(finding.Category) && a.patrol.hasDeterministicVerifierForKey(finding.Key) {+ verifyCtx, verifyCancel := context.WithTimeout(context.Background(), 30*time.Second)+ defer verifyCancel()+ verified, verifyErr := a.patrol.VerifyFixResolved(verifyCtx, finding.ResourceID, finding.ResourceType, finding.Key, findingID)+ if verifyErr != nil {+ log.Warn().+ Err(verifyErr).+ Str("finding_id", findingID).+ Str("category", string(finding.Category)).+ Str("key", finding.Key).+ Msg("AI Patrol: deterministic verifier inconclusive on resolve attempt; allowing resolve")+ } else if !verified {+ log.Info().+ Str("finding_id", findingID).+ Str("category", string(finding.Category)).+ Str("key", finding.Key).+ Msg("AI Patrol: rejected LLM resolve — deterministic verifier still detects the failure signal")+ return fmt.Errorf("cannot resolve %s: the failure signal is still present according to deterministic verification. Fix the underlying issue and re-run, do not resolve based on absence in the current investigation", findingID)+ }+ }+resolved := a.patrol.findings.Resolve(findingID, true)if !resolved {return fmt.Errorf("finding %s not found or already resolved", findingID)@@ -1517,6 +1556,20 @@ func (p *PatrolService) verifyFixDeterministically(}}+// hasDeterministicVerifierForKey reports whether a deterministic+// verifier exists for the given finding key. Used by ResolveFinding to+// decide whether an LLM-driven resolve attempt on an event/persistent+// category finding can be grounded in deterministic evidence. Keep this+// list aligned with the switch in verifyFixDeterministically.+func (p *PatrolService) hasDeterministicVerifierForKey(key string) bool {+ switch key {+ case "smart-failure", "backup-failed":+ return true+ default:+ return false+ }+}+func (p *PatrolService) getExecutorForVerification() (*tools.PulseToolExecutor, error) {if p == nil || p.aiService == nil {return nil, fmt.Errorf("%w: AI service unavailable", aicontracts.ErrVerificationUnknown)diff --git a/internal/ai/patrol_findings_additional_test.go b/internal/ai/patrol_findings_additional_test.goindex ff6711fd48..1593365f29 100644--- a/internal/ai/patrol_findings_additional_test.go+++ b/internal/ai/patrol_findings_additional_test.go@@ -1122,3 +1122,81 @@ func TestPatrolFindingCreatorAdapter_ResolveFinding_RejectsOutOfScopeFinding(t *t.Fatalf("expected in-scope resolve to succeed, got %v", err)}}++func TestPatrolService_HasDeterministicVerifierForKey(t *testing.T) {+ ps := NewPatrolService(nil, nil)++ // Keys with deterministic verifiers (mirrors the switch in+ // verifyFixDeterministically). Keep this test in lockstep with that+ // switch — the gate in ResolveFinding depends on the two staying+ // aligned.+ for _, key := range []string{"smart-failure", "backup-failed"} {+ if !ps.hasDeterministicVerifierForKey(key) {+ t.Errorf("hasDeterministicVerifierForKey(%q) = false, want true", key)+ }+ }+ for _, key := range []string{"", "unknown-key", "cpu-high", "node-offline", "service-restart"} {+ if ps.hasDeterministicVerifierForKey(key) {+ t.Errorf("hasDeterministicVerifierForKey(%q) = true, want false", key)+ }+ }+}++func TestPatrolFindingCreatorAdapter_ResolveFinding_SkipsVerifierForCategoriesThatSupportStaleAutoResolve(t *testing.T) {+ // Performance category supports stale-auto-resolve by contract, so+ // the LLM can resolve it freely. The new gate must not engage for+ // these categories — even if a deterministic verifier existed for+ // the key, the contract permits resolve on absence.+ ps := NewPatrolService(nil, nil)+ finding := &Finding{+ ID: "perf-1",+ Key: "cpu-high", // no deterministic verifier anyway+ Severity: FindingSeverityWarning,+ Category: FindingCategoryPerformance,+ ResourceID: "node-1",+ ResourceName: "pve-1",+ ResourceType: "node",+ Title: "CPU sustained high",+ DetectedAt: time.Now().Add(-time.Hour),+ LastSeenAt: time.Now().Add(-time.Hour),+ }+ ps.findings.Add(finding)++ adapter := newPatrolFindingCreatorAdapterState(ps, newPatrolRuntimeState(models.StateSnapshot{}))+ if err := adapter.ResolveFinding(finding.ID, "no longer hot"); err != nil {+ t.Fatalf("expected resolve to succeed for performance category, got %v", err)+ }+ if stored := ps.findings.Get(finding.ID); stored == nil || stored.ResolvedAt == nil {+ t.Fatalf("expected finding to be resolved, got %+v", stored)+ }+}++func TestPatrolFindingCreatorAdapter_ResolveFinding_FallsThroughWhenNoVerifierAvailable(t *testing.T) {+ // Reliability category does NOT support stale-auto-resolve, but+ // "node-offline" has no deterministic verifier. The gate must fall+ // through to current trust-the-LLM behavior rather than blocking+ // resolves for every event/persistent category we haven't built a+ // verifier for yet.+ ps := NewPatrolService(nil, nil)+ finding := &Finding{+ ID: "rel-1",+ Key: "node-offline",+ Severity: FindingSeverityWarning,+ Category: FindingCategoryReliability,+ ResourceID: "node-1",+ ResourceName: "pve-1",+ ResourceType: "node",+ Title: "Node offline",+ DetectedAt: time.Now().Add(-time.Hour),+ LastSeenAt: time.Now().Add(-time.Hour),+ }+ ps.findings.Add(finding)++ adapter := newPatrolFindingCreatorAdapterState(ps, newPatrolRuntimeState(models.StateSnapshot{}))+ if err := adapter.ResolveFinding(finding.ID, "node is back online"); err != nil {+ t.Fatalf("expected resolve to succeed when no verifier is registered, got %v", err)+ }+ if stored := ps.findings.Get(finding.ID); stored == nil || stored.ResolvedAt == nil {+ t.Fatalf("expected finding to be resolved, got %+v", stored)+ }+}