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.

Keep scoped Patrol all-clears coherent

rcourtman34cfc70329e3
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 91f3e0230f..bce0537d98 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -227,6 +227,13 @@ Persisted Patrol run analysis is a display-safe summary, not an unchecked raw
model transcript. Infrastructure status and actions-taken text in run history
must be reconciled from the accepted structured Patrol result: accepted
findings, resolved finding IDs, run errors, and user-visible finding counts.
+For a scoped run, the persisted status and findings summary count only active
+findings reported or explicitly assessed by that run. Related hosts, agents,
+and other supporting resources may remain in the effective diagnostic context,
+but their unrelated findings cannot make an exact-target all-clear appear
+unhealthy. A tool-free Watch negative control is valid only when its persisted
+status, canonical summary, finding counts, and finding IDs all agree that the
+run was healthy.
Rejected, failed, or attempted tool calls must not appear as actions taken, and
healthy/no-finding runs must not claim that an unaccepted
`patrol_report_finding` action occurred. Backup/PBS seed context must preserve
diff --git a/internal/ai/patrol_run.go b/internal/ai/patrol_run.go
index 87cb41a68c..45ec208e4c 100644
--- a/internal/ai/patrol_run.go
+++ b/internal/ai/patrol_run.go
@@ -838,13 +838,19 @@ func (p *PatrolService) runPatrolWithTriggerStart(ctx context.Context, trigger T
p.dispatchPatrolInvestigations(runStats.aiAnalysis)
}
-func patrolFindingSummaryForState(findings []*Finding, state patrolRuntimeState) FindingsSummary {
- known := patrolRuntimeKnownResources(state)
+func patrolFindingSummaryForRun(findings []*Finding, findingIDs []string) FindingsSummary {
+ owned := make(map[string]bool, len(findingIDs))
+ for _, findingID := range findingIDs {
+ if findingID = strings.TrimSpace(findingID); findingID != "" {
+ owned[findingID] = true
+ }
+ }
var summary FindingsSummary
for _, finding := range findings {
- if finding == nil || (len(known) > 0 && !known[finding.ResourceID] && !known[finding.ResourceName]) {
+ if finding == nil || !owned[finding.ID] {
continue
}
+ summary.Total++
switch finding.Severity {
case FindingSeverityCritical:
summary.Critical++
@@ -1150,10 +1156,11 @@ func (p *PatrolService) runScopedPatrolWithStart(ctx context.Context, scope Patr
duration := time.Since(start)
completedAt := time.Now()
- // Build a scope-owned findings summary. Findings on unrelated fleet
- // resources must never make this targeted run appear unhealthy, nor may
- // their absence make the scoped result look complete.
- summary := patrolFindingSummaryForState(p.findings.GetActive(FindingSeverityWarning), filteredState)
+ // Build a run-owned findings summary. Supporting resources included in the
+ // effective scope provide diagnostic context, but an unrelated finding on
+ // one of those resources must not make this targeted run appear unhealthy.
+ runFindingIDs := patrolRunFindingIDs(runStats.findingIDs, assessmentsForRun(runStats.aiAnalysis))
+ summary := patrolFindingSummaryForRun(p.findings.GetActive(FindingSeverityWarning), runFindingIDs)
var findingsSummaryStr string
var status string
totalActive := summary.Critical + summary.Warning
@@ -1219,7 +1226,7 @@ func (p *PatrolService) runScopedPatrolWithStart(ctx context.Context, scope Patr
RejectedFindings: runStats.rejectedFindings,
ResolvedFindings: resolvedFindings,
FindingsSummary: findingsSummaryStr,
- FindingIDs: patrolRunFindingIDs(runStats.findingIDs, assessmentsForRun(runStats.aiAnalysis)),
+ FindingIDs: runFindingIDs,
ErrorCount: runStats.errors,
Status: status,
ErrorSummary: runStats.errorSummary,
diff --git a/internal/ai/patrol_run_test.go b/internal/ai/patrol_run_test.go
index 5eae156aa6..0a90715834 100644
--- a/internal/ai/patrol_run_test.go
+++ b/internal/ai/patrol_run_test.go
@@ -134,14 +134,13 @@ func TestRunScopedPatrolPersistsZeroMatchFailure(t *testing.T) {
}
}
-func TestPatrolFindingSummaryForStateExcludesOutOfScopeFindings(t *testing.T) {
- state := newPatrolRuntimeState(models.StateSnapshot{VMs: []models.VM{{ID: "vm-in", Name: "inside", VMID: 1}}})
- summary := patrolFindingSummaryForState([]*Finding{
- {ID: "in", ResourceID: "vm-in", Severity: FindingSeverityWarning},
- {ID: "out", ResourceID: "vm-out", Severity: FindingSeverityCritical},
- }, state)
- if summary.Warning != 1 || summary.Critical != 0 {
- t.Fatalf("scoped summary = %+v, want one warning and no critical findings", summary)
+func TestPatrolFindingSummaryForRunExcludesSupportingResourceFindings(t *testing.T) {
+ summary := patrolFindingSummaryForRun([]*Finding{
+ {ID: "run-owned", ResourceID: "container-target", Severity: FindingSeverityWarning},
+ {ID: "supporting-context", ResourceID: "agent-host", Severity: FindingSeverityCritical},
+ }, []string{"run-owned"})
+ if summary.Warning != 1 || summary.Critical != 0 || summary.Total != 1 {
+ t.Fatalf("run summary = %+v, want one run-owned warning and no supporting-resource finding", summary)
}
}
diff --git a/internal/ai/qualification/runner.go b/internal/ai/qualification/runner.go
index 943db4fb6f..dc40cad02f 100644
--- a/internal/ai/qualification/runner.go
+++ b/internal/ai/qualification/runner.go
@@ -429,6 +429,16 @@ func validatePatrolRunModelEvidence(manifest Manifest, run PatrolRun) error {
if run.InputTokens <= 0 || run.OutputTokens <= 0 || strings.TrimSpace(run.AIAnalysis) == "" {
return errors.New("tool-free Patrol all-clear has no persisted real-model analysis evidence")
}
+ if !strings.EqualFold(strings.TrimSpace(run.Status), "healthy") ||
+ !strings.EqualFold(strings.TrimSpace(run.FindingsSummary), "All healthy") ||
+ run.NewFindings != 0 || run.ExistingFindings != 0 || run.RejectedFindings != 0 ||
+ run.ResolvedFindings != 0 || len(run.FindingIDs) != 0 {
+ return fmt.Errorf(
+ "tool-free Patrol all-clear contradicts persisted run outcome: status=%s summary=%q new=%d existing=%d rejected=%d resolved=%d finding_ids=%d",
+ run.Status, run.FindingsSummary, run.NewFindings, run.ExistingFindings,
+ run.RejectedFindings, run.ResolvedFindings, len(run.FindingIDs),
+ )
+ }
return nil
}
diff --git a/internal/ai/qualification/runner_helpers_test.go b/internal/ai/qualification/runner_helpers_test.go
index b77ac3aab3..4bddfb122d 100644
--- a/internal/ai/qualification/runner_helpers_test.go
+++ b/internal/ai/qualification/runner_helpers_test.go
@@ -22,7 +22,7 @@ func TestValidatePatrolRunModelEvidence(t *testing.T) {
{
name: "healthy real-model all-clear needs no artificial tool call",
manifest: healthy,
- run: PatrolRun{InputTokens: 100, OutputTokens: 20, AIAnalysis: "No findings reported — all clear."},
+ run: PatrolRun{InputTokens: 100, OutputTokens: 20, AIAnalysis: "No findings reported — all clear.", Status: "healthy", FindingsSummary: "All healthy"},
},
{
name: "tool-free all-clear still needs persisted model evidence",
@@ -30,6 +30,18 @@ func TestValidatePatrolRunModelEvidence(t *testing.T) {
run: PatrolRun{AIAnalysis: "No findings reported — all clear."},
wantErr: "no persisted real-model analysis evidence",
},
+ {
+ name: "tool-free all-clear rejects contradictory issue status",
+ manifest: healthy,
+ run: PatrolRun{InputTokens: 100, OutputTokens: 20, AIAnalysis: "No findings reported — all clear.", Status: "issues_found", FindingsSummary: "1 warning"},
+ wantErr: "contradicts persisted run outcome",
+ },
+ {
+ name: "tool-free all-clear rejects hidden run-owned finding",
+ manifest: healthy,
+ run: PatrolRun{InputTokens: 100, OutputTokens: 20, AIAnalysis: "No findings reported — all clear.", Status: "healthy", FindingsSummary: "All healthy", FindingIDs: []string{"finding-1"}},
+ wantErr: "contradicts persisted run outcome",
+ },
{
name: "fault scenario still requires a tool-backed outcome",
manifest: validTestManifest(),