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
fix: route patrol update safety through read state
rcourtman427b7ff5c628
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.mdindex da23e2c57b..9570112853 100644--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md@@ -147,6 +147,11 @@ runtime cost control, and shared AI transport surfaces.browser state owner and `internal/api/ai_handlers.go` must clear stalefull-mode unlock state while clamping autonomy back to `monitor`, so paidremediation permission cannot survive through a free runtime save.+ Patrol update-safety observation is part of the same read-state runtime+ boundary: Docker host/container snapshots used to detect image-digest+ divergence must be sourced from canonical `ReadState.DockerHosts()` views,+ with model-shaped data limited to the watcher adapter input rather than+ direct `StateSnapshot.DockerHosts` reads in the Patrol run loop.4. Keep discovery scheduling authoritative through `internal/config/ai.go`: `discovery_enabled` and `discovery_interval_hours` must govern both lightweight infrastructure discovery and deep service-discovery background loops5. Preserve auditability for outbound model-bound context exports and keep the export record aligned with the prompt boundary that actually reaches the providerExternal provider-bound unified-resource context must enforce the samediff --git a/internal/ai/patrol_run.go b/internal/ai/patrol_run.goindex ff779b8e01..c5d97708de 100644--- a/internal/ai/patrol_run.go+++ b/internal/ai/patrol_run.go@@ -412,7 +412,7 @@ func (p *PatrolService) runPatrolWithTrigger(ctx context.Context, trigger Trigge// Run update-safety watcher on every patrol cycle regardless of LLM availability.// Direct FindingsStore.Add bypasses push-notification (MVP: not an emergency).if cfg.AnalyzeDocker && p.updateSafetyWatcher != nil {- updateEmit, updateResolve := p.updateSafetyWatcher.Observe(state.DockerHosts, time.Now())+ updateEmit, updateResolve := p.updateSafetyWatcher.Observe(patrolUpdateSafetyDockerHosts(state), time.Now())for _, f := range updateEmit {if !p.findings.Add(f) {log.Debug().Str("finding_id", f.ID).Msg("AI Patrol: update-safety finding already in store")@@ -1200,6 +1200,50 @@ func scopePatrolDockerHost(d models.DockerHost, matcher patrolScopeMatcher) (modreturn models.DockerHost{}, nil, false}+func patrolUpdateSafetyDockerHosts(s patrolRuntimeState) []models.DockerHost {+ rs := s.readState+ if rs == nil {+ derived := s.withDerivedProviders()+ rs = derived.readState+ }+ if rs == nil {+ return nil+ }++ hostViews := rs.DockerHosts()+ hosts := make([]models.DockerHost, 0, len(hostViews))+ for _, hostView := range hostViews {+ if hostView == nil {+ continue+ }++ hostID := strings.TrimSpace(hostView.HostSourceID())+ if hostID == "" {+ hostID = strings.TrimSpace(hostView.ID())+ }+ name := strings.TrimSpace(hostView.Name())+ displayName := strings.TrimSpace(hostView.DisplayName())+ if displayName == "" {+ displayName = name+ }+ hostname := strings.TrimSpace(hostView.Hostname())+ if hostname == "" {+ hostname = name+ }++ hosts = append(hosts, models.DockerHost{+ ID: hostID,+ AgentID: strings.TrimSpace(hostView.AgentID()),+ Hostname: hostname,+ DisplayName: displayName,+ CustomDisplayName: strings.TrimSpace(hostView.CustomDisplayName()),+ Status: string(hostView.Status()),+ Containers: hostView.Containers(),+ })+ }+ return hosts+}+func collectPatrolScopedDockerHosts(hosts []models.DockerHost, matcher patrolScopeMatcher) ([]models.DockerHost, []string) {filtered := make([]models.DockerHost, 0, len(hosts))ids := make([]string, 0, len(hosts))diff --git a/internal/ai/patrol_run_test.go b/internal/ai/patrol_run_test.goindex 4794ada8cc..f9c5be6bc3 100644--- a/internal/ai/patrol_run_test.go+++ b/internal/ai/patrol_run_test.go@@ -700,6 +700,58 @@ func TestPatrolRuntimeResourceHelpers_PrepareCanonicalInventory(t *testing.T) {}}+func TestPatrolUpdateSafetyDockerHosts_UsesReadStateDockerHosts(t *testing.T) {+ readStateForDigest := func(digest string) unifiedresources.ReadState {+ registry := unifiedresources.NewRegistry(nil)+ registry.IngestSnapshot(models.StateSnapshot{+ DockerHosts: []models.DockerHost{+ {+ ID: "canonical-host",+ Hostname: "canonical.local",+ Containers: []models.DockerContainer{+ {ID: "app-1", Name: "web", ImageDigest: digest},+ },+ },+ },+ })+ return registry+ }++ legacyUnchangedHost := []models.DockerHost{+ {+ ID: "legacy-host",+ Hostname: "legacy.local",+ Containers: []models.DockerContainer{+ {ID: "legacy-app", Name: "legacy-web", ImageDigest: "sha256:aaa"},+ },+ },+ }++ watcher := newUpdateSafetyWatcher()+ state := patrolRuntimeState{+ readState: readStateForDigest("sha256:aaa"),+ DockerHosts: legacyUnchangedHost,+ }+ if emit, resolve := watcher.Observe(patrolUpdateSafetyDockerHosts(state), time.Unix(1, 0)); len(emit) != 0 || len(resolve) != 0 {+ t.Fatalf("expected first read-state observation to establish baseline, got emit=%d resolve=%d", len(emit), len(resolve))+ }++ state.readState = readStateForDigest("sha256:bbb")+ emit, resolve := watcher.Observe(patrolUpdateSafetyDockerHosts(state), time.Unix(2, 0))+ if len(resolve) != 0 {+ t.Fatalf("expected no resolve on digest change, got %d", len(resolve))+ }+ if len(emit) != 1 {+ t.Fatalf("expected read-state digest change to emit one finding, got %d", len(emit))+ }+ if emit[0].Key != UpdateSafetyFindingPrefix+":canonical-host/app-1" {+ t.Fatalf("expected canonical read-state host/container key, got %q", emit[0].Key)+ }+ if emit[0].Node != "canonical.local" {+ t.Fatalf("expected canonical read-state host name, got %q", emit[0].Node)+ }+}+func TestPatrolRuntimeState_WithDerivedProviders_UsesResourceInventoryOnly(t *testing.T) {state := patrolRuntimeState{Nodes: []models.Node{