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.

Reject invalid Patrol reconfirmation prerequisites

rcourtmanc527405f16f2
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 85e3618bca..fb21525574 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -5854,6 +5854,12 @@ the exact `Root Cause` and `Affected Resources` response sections using the
collected canonical name or ID. The expected diagnosis therefore remains
independent of the read-only tools Patrol chose, and merely repeating the
downstream symptom cannot pass causal grounding.
+An existing-finding reconfirmation scenario may seed its scored run only from
+a successful prerequisite Patrol run that created a run-owned finding on every
+scenario-owned expected resource. An incidental provider, readiness, or other
+unrelated finding cannot satisfy setup, and the failed prerequisite remains in
+the report as diagnostic evidence rather than being converted into a model
+reconfirmation miss.
Scenario-owned `required_summary_term_groups` may declare reviewed semantic
alternatives for one independently known fact, such as Docker's injected
`stopped` action and its normally collected `exited` state. Every group still
diff --git a/internal/ai/qualification/runner.go b/internal/ai/qualification/runner.go
index 102e690d69..dd08ab0e9f 100644
--- a/internal/ai/qualification/runner.go
+++ b/internal/ai/qualification/runner.go
@@ -272,15 +272,15 @@ func (r *QualificationRunner) Run(ctx context.Context) (report RunReport, termin
if warmupErr != nil {
return fmt.Errorf("existing-finding prerequisite Patrol run: %w", warmupErr)
}
+ report.PrerequisitePatrolRun = &warmup
afterWarmup, findingsErr := r.config.Client.Findings(ctx)
if findingsErr != nil {
return findingsErr
}
warmupFindings := filterRunFindings(beforeFindings, afterWarmup, warmup, collected, warmupTriggeredAt)
- if len(warmupFindings) == 0 {
- return errors.New("existing-finding prerequisite run did not create a run-owned finding")
+ if err := validateExistingFindingPrerequisite(manifest, collected, warmup, warmupFindings); err != nil {
+ return err
}
- report.PrerequisitePatrolRun = &warmup
beforeFindings = afterWarmup
}
triggeredAt = time.Now().UTC()
@@ -410,6 +410,42 @@ func (r *QualificationRunner) Run(ctx context.Context) (report RunReport, termin
return report, terminalErr
}
+func validateExistingFindingPrerequisite(manifest Manifest, collected map[string]Resource, warmup PatrolRun, findings []Finding) error {
+ if strings.EqualFold(strings.TrimSpace(warmup.Status), "error") || warmup.ErrorCount > 0 {
+ return fmt.Errorf("existing-finding prerequisite Patrol run failed: status=%s errors=%d", warmup.Status, warmup.ErrorCount)
+ }
+ if len(findings) == 0 {
+ return errors.New("existing-finding prerequisite run did not create a run-owned finding")
+ }
+
+ foundResources := make(map[string]struct{}, len(findings))
+ for _, finding := range findings {
+ foundResources[finding.ResourceID] = struct{}{}
+ }
+ checkedAliases := make(map[string]struct{})
+ for _, fault := range manifest.Faults {
+ if !fault.Required {
+ continue
+ }
+ alias := strings.TrimSpace(fault.Expected.Resource)
+ if alias == "" {
+ alias = strings.TrimSpace(fault.Target)
+ }
+ if _, seen := checkedAliases[alias]; seen {
+ continue
+ }
+ checkedAliases[alias] = struct{}{}
+ resource, ok := collected[alias]
+ if !ok || strings.TrimSpace(resource.ID) == "" {
+ return fmt.Errorf("existing-finding prerequisite expected resource %q was not collected", alias)
+ }
+ if _, ok := foundResources[resource.ID]; !ok {
+ return fmt.Errorf("existing-finding prerequisite run created no finding for expected resource %q", alias)
+ }
+ }
+ return nil
+}
+
func patrolScopeResourceIDs(manifest Manifest, collected map[string]Resource) []string {
if !manifest.Patrol.Scoped {
return nil
diff --git a/internal/ai/qualification/runner_helpers_test.go b/internal/ai/qualification/runner_helpers_test.go
index 3b9553695e..8782c030c7 100644
--- a/internal/ai/qualification/runner_helpers_test.go
+++ b/internal/ai/qualification/runner_helpers_test.go
@@ -1,6 +1,7 @@
package qualification
import (
+ "strings"
"testing"
"time"
)
@@ -103,6 +104,45 @@ func TestPhaseDurationLinearScan(t *testing.T) {
}
}
+func TestValidateExistingFindingPrerequisiteRejectsUnrelatedOrFailedWarmup(t *testing.T) {
+ manifest := Manifest{
+ Patrol: PatrolSpec{RequireExistingReconfirmation: true},
+ Faults: []FaultSpec{{
+ ID: "container-health",
+ Target: "target",
+ Required: true,
+ Expected: ExpectedFinding{Resource: "target"},
+ }},
+ }
+ collected := map[string]Resource{"target": {ID: "resource-target", Name: "target"}}
+
+ tests := []struct {
+ name string
+ warmup PatrolRun
+ findings []Finding
+ wantErr string
+ }{
+ {name: "failed warmup cannot seed reconfirmation", warmup: PatrolRun{Status: "error", ErrorCount: 1}, findings: []Finding{{ResourceID: "resource-target"}}, wantErr: "prerequisite Patrol run failed"},
+ {name: "unrelated finding cannot satisfy target prerequisite", warmup: PatrolRun{Status: "issues_found"}, findings: []Finding{{ResourceID: "ai-service"}}, wantErr: "no finding for expected resource"},
+ {name: "successful target finding is accepted", warmup: PatrolRun{Status: "issues_found"}, findings: []Finding{{ResourceID: "resource-target"}}},
+ }
+
+ for _, test := range tests {
+ t.Run(test.name, func(t *testing.T) {
+ err := validateExistingFindingPrerequisite(manifest, collected, test.warmup, test.findings)
+ if test.wantErr == "" {
+ if err != nil {
+ t.Fatalf("expected valid prerequisite, got %v", err)
+ }
+ return
+ }
+ if err == nil || !strings.Contains(err.Error(), test.wantErr) {
+ t.Fatalf("expected error containing %q, got %v", test.wantErr, err)
+ }
+ })
+ }
+}
+
func TestDockerTargetLabelBranches(t *testing.T) {
cases := []struct {
name string