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
Require collected fault convergence before Patrol
rcourtmanaa0f9ea5a797
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.mdindex 158d2351a8..c3d3bc56b4 100644--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md@@ -5680,6 +5680,14 @@ baseline before fault injection. The Watch correlation and Pro investigationfixtures use Alpine's `nc` applet for the disposable HTTP dependency; a missingoptional daemon must fail baseline convergence and never be scored as a modelmiss.+Live qualification collection convergence must require both exact scenario+resource names and the scenario-owned Docker oracle state projected by Pulse's+canonical resources API. A direct lab oracle may prove the fault exists, but+Patrol must not run until the normal agent/API path independently exposes the+relevant health, running-state, or restart-count condition; a stale healthy+projection is a collection failure, never a model miss. These expectations are+derived from manifest oracles before execution and never from Patrol tool+selection, preserving non-circular scoring.Persisted Patrol tool inputs must retain complete structured finding calls upto the bounded 16 KiB record limit so normal evidence-rich findings remaindeterministically replayable. If any captured input is nevertheless incompletediff --git a/internal/ai/qualification/client.go b/internal/ai/qualification/client.goindex 2365562165..edf7a0fb20 100644--- a/internal/ai/qualification/client.go+++ b/internal/ai/qualification/client.go@@ -97,13 +97,20 @@ func (a PatrolAutonomy) Effective() string {}type Resource struct {- ID string `json:"id"`- Type string `json:"type"`- Technology string `json:"technology"`- Name string `json:"name"`- Status string `json:"status"`- LastSeen any `json:"lastSeen,omitempty"`- Labels map[string]any `json:"labels,omitempty"`+ ID string `json:"id"`+ Type string `json:"type"`+ Technology string `json:"technology"`+ Name string `json:"name"`+ Status string `json:"status"`+ LastSeen any `json:"lastSeen,omitempty"`+ Labels map[string]any `json:"labels,omitempty"`+ Docker *DockerResource `json:"docker,omitempty"`+}++type DockerResource struct {+ ContainerState string `json:"containerState,omitempty"`+ Health string `json:"health,omitempty"`+ RestartCount int `json:"restartCount,omitempty"`}type Finding struct {@@ -273,6 +280,10 @@ func (c *PulseClient) Resources(ctx context.Context) ([]Resource, error) {}func (c *PulseClient) WaitForResources(ctx context.Context, names map[string]string, timeout, poll time.Duration) (map[string]Resource, error) {+ return c.WaitForResourcesMatching(ctx, names, timeout, poll, nil)+}++func (c *PulseClient) WaitForResourcesMatching(ctx context.Context, names map[string]string, timeout, poll time.Duration, validate func(map[string]Resource) error) (map[string]Resource, error) {if timeout <= 0 {timeout = 5 * time.Minute}@@ -280,6 +291,7 @@ func (c *PulseClient) WaitForResources(ctx context.Context, names map[string]strpoll = 5 * time.Second}deadline := time.Now().Add(timeout)+ var lastValidationErr errorfor {resources, err := c.Resources(ctx)if err == nil {@@ -293,10 +305,20 @@ func (c *PulseClient) WaitForResources(ctx context.Context, names map[string]str}}if len(matched) == len(names) {- return matched, nil+ if validate == nil {+ return matched, nil+ }+ if validationErr := validate(matched); validationErr == nil {+ return matched, nil+ } else {+ lastValidationErr = validationErr+ }}}if time.Now().After(deadline) {+ if lastValidationErr != nil {+ return nil, fmt.Errorf("collection exposed exact resources but did not converge to scenario-owned fault state before %s: %w", deadline.UTC().Format(time.RFC3339), lastValidationErr)+ }return nil, fmt.Errorf("collection did not expose all %d exact resource names before %s", len(names), deadline.UTC().Format(time.RFC3339))}select {diff --git a/internal/ai/qualification/client_test.go b/internal/ai/qualification/client_test.goindex 1c46502abb..5e7f6a87b4 100644--- a/internal/ai/qualification/client_test.go+++ b/internal/ai/qualification/client_test.go@@ -3,6 +3,7 @@ package qualificationimport ("context""encoding/json"+ "errors""io""net/http""net/http/httptest"@@ -46,6 +47,61 @@ func TestTriggerAndWaitAssociatesExactNewScopedRun(t *testing.T) {}}+func TestValidateCollectedFaultProjectionUsesScenarioOracle(t *testing.T) {+ manifest := validTestManifest()+ manifest.Faults = []FaultSpec{+ {ID: "stopped", Target: "dependency", Oracle: []Predicate{{Probe: "docker.running", Target: "dependency", Operator: "eq", Value: json.RawMessage("false")}}},+ {ID: "unhealthy", Target: "client", Oracle: []Predicate{{Probe: "docker.health", Target: "client", Operator: "eq", Value: json.RawMessage(`"unhealthy"`)}}},+ {ID: "restart-loop", Target: "worker", Oracle: []Predicate{{Probe: "docker.restart_count", Target: "worker", Operator: "gte", Value: json.RawMessage("2")}}},+ }+ resources := map[string]Resource{+ "dependency": {Docker: &DockerResource{ContainerState: "running"}},+ "client": {Docker: &DockerResource{Health: "healthy"}},+ "worker": {Docker: &DockerResource{RestartCount: 1}},+ }+ if err := validateCollectedFaultProjection(manifest, resources); err == nil {+ t.Fatal("expected pre-fault collected projection to be rejected")+ }+ resources["dependency"] = Resource{Docker: &DockerResource{ContainerState: "exited"}}+ resources["client"] = Resource{Docker: &DockerResource{Health: "unhealthy"}}+ resources["worker"] = Resource{Docker: &DockerResource{RestartCount: 2}}+ if err := validateCollectedFaultProjection(manifest, resources); err != nil {+ t.Fatalf("expected collected projection to satisfy scenario-owned oracles: %v", err)+ }+}++func TestWaitForResourcesMatchingPollsPastStaleState(t *testing.T) {+ var calls atomic.Int32+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ w.Header().Set("Content-Type", "application/json")+ call := calls.Add(1)+ health := "healthy"+ if call >= 2 {+ health = "unhealthy"+ }+ _ = json.NewEncoder(w).Encode(map[string]any{"data": []map[string]any{{+ "id": "r1", "type": "app-container", "name": "fixture", "docker": map[string]any{"health": health},+ }}})+ }))+ defer server.Close()+ client, err := NewPulseClient(ClientConfig{BaseURL: server.URL})+ if err != nil {+ t.Fatal(err)+ }+ resources, err := client.WaitForResourcesMatching(context.Background(), map[string]string{"target": "fixture"}, time.Second, time.Millisecond, func(resources map[string]Resource) error {+ if resources["target"].Docker == nil || resources["target"].Docker.Health != "unhealthy" {+ return errors.New("fault state is not collected yet")+ }+ return nil+ })+ if err != nil {+ t.Fatal(err)+ }+ if calls.Load() < 2 || resources["target"].Docker.Health != "unhealthy" {+ t.Fatalf("collection returned before fault projection converged: calls=%d resources=%+v", calls.Load(), resources)+ }+}+func TestNewPulseClientRejectsCredentialsInReportableBaseURL(t *testing.T) {if _, err := NewPulseClient(ClientConfig{BaseURL: "https://admin:[email protected]"}); err == nil {t.Fatal("base URL credentials must be rejected rather than persisted in reports")diff --git a/internal/ai/qualification/runner.go b/internal/ai/qualification/runner.goindex d78c5653d1..0c4912a1f7 100644--- a/internal/ai/qualification/runner.go+++ b/internal/ai/qualification/runner.go@@ -4,6 +4,7 @@ import ("context""crypto/rand""encoding/hex"+ "encoding/json""errors""fmt""os"@@ -230,7 +231,9 @@ func (r *QualificationRunner) Run(ctx context.Context) (report RunReport, termintimeout, _ := positiveDuration(manifest.Collection.ConvergenceTimeout)poll, _ := positiveDuration(manifest.Collection.PollInterval)var collectionErr error- collected, collectionErr = r.config.Client.WaitForResources(ctx, prepared.ResourceNames, timeout, poll)+ collected, collectionErr = r.config.Client.WaitForResourcesMatching(ctx, prepared.ResourceNames, timeout, poll, func(resources map[string]Resource) error {+ return validateCollectedFaultProjection(manifest, resources)+ })if collectionErr != nil {return collectionErr}@@ -417,6 +420,50 @@ func (r *QualificationRunner) Run(ctx context.Context) (report RunReport, terminreturn report, terminalErr}+func validateCollectedFaultProjection(manifest Manifest, resources map[string]Resource) error {+ for _, fault := range manifest.Faults {+ for _, predicate := range fault.Oracle {+ resource, ok := resources[predicate.Target]+ if !ok {+ return fmt.Errorf("fault %s target %s is absent from collected resources", fault.ID, predicate.Target)+ }+ if resource.Docker == nil {+ return fmt.Errorf("fault %s target %s has no collected Docker projection", fault.ID, predicate.Target)+ }+ switch predicate.Probe {+ case "docker.health":+ var expected string+ if err := json.Unmarshal(predicate.Value, &expected); err != nil {+ return fmt.Errorf("fault %s has invalid collected health expectation: %w", fault.ID, err)+ }+ if !strings.EqualFold(strings.TrimSpace(resource.Docker.Health), strings.TrimSpace(expected)) {+ return fmt.Errorf("fault %s target %s collected health=%q want %q", fault.ID, predicate.Target, resource.Docker.Health, expected)+ }+ case "docker.running":+ var expected bool+ if err := json.Unmarshal(predicate.Value, &expected); err != nil {+ return fmt.Errorf("fault %s has invalid collected running expectation: %w", fault.ID, err)+ }+ running := strings.EqualFold(strings.TrimSpace(resource.Docker.ContainerState), "running")+ if running != expected {+ return fmt.Errorf("fault %s target %s collected running=%t state=%q want %t", fault.ID, predicate.Target, running, resource.Docker.ContainerState, expected)+ }+ case "docker.restart_count":+ var expected int+ if err := json.Unmarshal(predicate.Value, &expected); err != nil {+ return fmt.Errorf("fault %s has invalid collected restart-count expectation: %w", fault.ID, err)+ }+ observed := resource.Docker.RestartCount+ satisfied := predicate.Operator == "eq" && observed == expected || predicate.Operator == "gte" && observed >= expected+ if !satisfied {+ return fmt.Errorf("fault %s target %s collected restart_count=%d does not satisfy %s %d", fault.ID, predicate.Target, observed, predicate.Operator, expected)+ }+ }+ }+ }+ return nil+}+func phaseDuration(phases []PhaseTiming, name string) time.Duration {for _, phase := range phases {if phase.Name == name {