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.

Preserve canonical Patrol objective scopes

rcourtmand218b012d158
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 9b7c57bc82..8907ff6007 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -7257,6 +7257,16 @@ objectives expand to current canonical resource IDs before the run. This wakes
the model once to design coverage rather than waiting for the next scheduled
Patrol cycle.
+Scoped Patrol identity resolution includes exact canonical unified resources
+that have no legacy `StateSnapshot` projection, including standalone
+availability `network-endpoint` resources. The scoped runtime rebuild retains
+only provider resources matched by the resolved ID/type set, preserves their
+canonical availability evidence, and counts them as real scoped work. It does
+not fall back to an unfiltered provider or relax exact/unique identity rules.
+An objective attached to an availability endpoint can therefore reach the
+model-authored observer planner without exposing unrelated estate resources or
+failing before the already-supported availability observer ABI is evaluated.
+
Accepted observers transition through proposed, validated, and installed under
core authority. Resource observers evaluate Pulse's canonical `ReadState`
status locally, falling back to the existing Patrol snapshot only where
diff --git a/internal/ai/patrol_run.go b/internal/ai/patrol_run.go
index 45ec208e4c..e7e68cc09b 100644
--- a/internal/ai/patrol_run.go
+++ b/internal/ai/patrol_run.go
@@ -1035,6 +1035,10 @@ func (p *PatrolService) runScopedPatrolWithStart(ctx context.Context, scope Patr
if cfg.AnalyzePMG {
resourceCount += resourceCounts.pmg
}
+ // Canonical resource kinds without a legacy snapshot projection are still
+ // real scoped work. They are admitted only through exact unified-resource
+ // matching and remain available to the objective seed and governed tools.
+ resourceCount += resourceCounts.unified
if resourceCount == 0 {
log.Debug().
@@ -1752,6 +1756,36 @@ func collectPatrolScopedKubernetesClusters(clusters []models.KubernetesCluster,
return filtered, ids
}
+func patrolUnifiedResourceIdentity(resource unifiedresources.Resource) ([]string, []string) {
+ ids := []string{resource.ID}
+ aliases := []string{resource.Name}
+ if resource.Canonical != nil {
+ ids = append(ids, resource.Canonical.PrimaryID)
+ ids = append(ids, resource.Canonical.SupersededIDs...)
+ aliases = append(aliases, resource.Canonical.DisplayName, resource.Canonical.Hostname)
+ aliases = append(aliases, resource.Canonical.Aliases...)
+ }
+ ids = append(ids, resource.SupersededCanonicalIDs...)
+ return ids, aliases
+}
+
+func collectPatrolScopedUnifiedResources(provider UnifiedResourceProvider, matcher patrolScopeMatcher) ([]unifiedresources.Resource, []string) {
+ if provider == nil {
+ return nil, nil
+ }
+ filtered := make([]unifiedresources.Resource, 0)
+ ids := make([]string, 0)
+ for _, resource := range provider.GetAll() {
+ resourceIDs, aliases := patrolUnifiedResourceIdentity(resource)
+ if !matcher.matchesType(string(resource.Type)) || !matcher.matchesResource(resourceIDs, aliases...) {
+ continue
+ }
+ filtered = append(filtered, resource)
+ ids = append(ids, resourceIDs...)
+ }
+ return filtered, ids
+}
+
func patrolKubernetesScopeName(k models.KubernetesCluster) string {
clusterName := k.CustomDisplayName
if clusterName == "" {
@@ -1904,9 +1938,18 @@ func filterPatrolStateByScopeState(snap patrolRuntimeState, scope PatrolScope) p
filterState.filtered.KubernetesClusters = filteredK8sClusters
filterState.includeResourceID(k8sClusterIDs...)
+ // Preserve exact canonical resources that have no StateSnapshot projection
+ // (notably availability network endpoints). Rebuilding the provider only
+ // from snapshot fields made valid objective scopes disappear before the
+ // model could propose a local observer. The scoped provider is still built
+ // from the exact matcher result, so unrelated resources cannot enter model
+ // context.
+ filteredUnified, unifiedIDs := collectPatrolScopedUnifiedResources(snap.unifiedResourceProvider, matcher)
+ filterState.includeResourceID(unifiedIDs...)
+
copyScopedPatrolMetadata(&filterState.filtered, snap, filterState.includedResourceIDs, filterState.includedGuestVMIDs)
- return filterState.filtered.withDerivedProviders()
+ return filterState.filtered.withDerivedProvidersAndResources(filteredUnified)
}
func (p *PatrolService) filterStateByScopeState(snap patrolRuntimeState, scope PatrolScope) patrolRuntimeState {
diff --git a/internal/ai/patrol_run_test.go b/internal/ai/patrol_run_test.go
index 0a90715834..7b5c1f3036 100644
--- a/internal/ai/patrol_run_test.go
+++ b/internal/ai/patrol_run_test.go
@@ -54,6 +54,62 @@ func TestResolvePatrolScopeExpandsCanonicalUnifiedIDToSourceResource(t *testing.
}
}
+func TestResolvePatrolScopePreservesCanonicalAvailabilityEndpoint(t *testing.T) {
+ now := time.Now().UTC()
+ endpoint := unifiedresources.Resource{
+ ID: "network-endpoint-jellyfin",
+ Name: "Jellyfin",
+ Type: unifiedresources.ResourceTypeNetworkEndpoint,
+ Status: unifiedresources.StatusOnline,
+ LastSeen: now,
+ Sources: []unifiedresources.DataSource{unifiedresources.SourceAvailability},
+ Availability: &unifiedresources.AvailabilityData{
+ TargetID: "jellyfin-check", Enabled: true, ProbeOutcome: "reachable",
+ },
+ Canonical: &unifiedresources.CanonicalIdentity{
+ DisplayName: "Jellyfin playback endpoint",
+ Aliases: []string{"jellyfin.local"},
+ },
+ }
+ unrelated := unifiedresources.Resource{
+ ID: "network-endpoint-unrelated", Name: "Unrelated", Type: unifiedresources.ResourceTypeNetworkEndpoint,
+ Status: unifiedresources.StatusOnline, LastSeen: now,
+ }
+ registry := unifiedresources.NewRegistry(nil)
+ registry.IngestResources([]unifiedresources.Resource{endpoint, unrelated})
+ state := newPatrolRuntimeStateWithProviders(
+ models.EmptyStateSnapshot(), registry, unifiedresources.NewUnifiedAIAdapter(registry),
+ )
+
+ resolved, resolution := resolvePatrolScopeState(state, PatrolScope{ResourceIDs: []string{endpoint.ID}})
+ if len(resolution.UnmatchedResourceIDs) != 0 || len(resolution.AmbiguousResourceIDs) != 0 {
+ t.Fatalf("canonical availability endpoint did not resolve exactly: %+v", resolution)
+ }
+ filtered := filterPatrolStateByScopeState(state, resolved)
+ resources := filtered.unifiedResourceProvider.GetAll()
+ if len(resources) != 1 || resources[0].ID != endpoint.ID {
+ t.Fatalf("scoped provider resources = %+v, want only %q", resources, endpoint.ID)
+ }
+ checks := unifiedresources.AvailabilityChecksForResource(resources[0])
+ if len(checks) != 1 || checks[0].TargetID != "jellyfin-check" || checks[0].ProbeOutcome != "reachable" {
+ t.Fatalf("availability evidence was not preserved: %+v", checks)
+ }
+ effectiveContainsEndpoint := false
+ for _, id := range resolution.EffectiveResourceIDs {
+ if id == endpoint.ID {
+ effectiveContainsEndpoint = true
+ break
+ }
+ }
+ if !effectiveContainsEndpoint {
+ t.Fatalf("effective scope = %v, want canonical endpoint %q", resolution.EffectiveResourceIDs, endpoint.ID)
+ }
+ counts := patrolRuntimeCountResources(filtered)
+ if counts.unified != 1 || counts.total() != 1 {
+ t.Fatalf("canonical endpoint counts = %#v, want one unified resource", counts)
+ }
+}
+
func TestResolvePatrolScopeRejectsUnmatchedAndAmbiguousAliases(t *testing.T) {
state := newPatrolRuntimeState(models.StateSnapshot{VMs: []models.VM{
{ID: "vm-1", Name: "duplicate", VMID: 1},
diff --git a/internal/ai/patrol_state.go b/internal/ai/patrol_state.go
index 660eef8f93..964030b45a 100644
--- a/internal/ai/patrol_state.go
+++ b/internal/ai/patrol_state.go
@@ -36,6 +36,11 @@ const (
patrolRuntimeResourcePMG patrolRuntimeResourceKind = "pmg"
patrolRuntimeResourceK8sCluster patrolRuntimeResourceKind = "k8s-cluster"
patrolRuntimeResourcePhysicalDisk patrolRuntimeResourceKind = "physical-disk"
+ // patrolRuntimeResourceUnified covers canonical resource kinds that do not
+ // yet have a legacy StateSnapshot projection (for example availability
+ // network endpoints). These resources remain exact-ID scoped and are
+ // supplied to Patrol through the unified-resource provider only.
+ patrolRuntimeResourceUnified patrolRuntimeResourceKind = "unified-resource"
)
type patrolRuntimeResourceRecord struct {
@@ -125,8 +130,15 @@ func (s patrolRuntimeState) resourceSnapshot() models.StateSnapshot {
}
func (s patrolRuntimeState) withDerivedProviders() patrolRuntimeState {
+ return s.withDerivedProvidersAndResources(nil)
+}
+
+func (s patrolRuntimeState) withDerivedProvidersAndResources(resources []unifiedresources.Resource) patrolRuntimeState {
registry := unifiedresources.NewRegistry(nil)
registry.IngestSnapshot(s.resourceSnapshot())
+ if len(resources) > 0 {
+ registry.IngestResources(resources)
+ }
s.readState = registry
s.unifiedResourceProvider = unifiedresources.NewUnifiedAIAdapter(registry)
return s
@@ -168,8 +180,17 @@ func (p *PatrolService) patrolRuntimeStateForSnapshot(snapshot models.StateSnaps
}
func patrolVisitRuntimeResources(s patrolRuntimeState, visit func(patrolRuntimeResourceRecord) bool) {
+ emittedIDs := make(map[string]struct{})
emit := func(kind patrolRuntimeResourceKind, ids []string, aliases ...string) bool {
- return visit(patrolRuntimeResourceRecord{kind: kind, ids: ids, aliases: aliases})
+ if !visit(patrolRuntimeResourceRecord{kind: kind, ids: ids, aliases: aliases}) {
+ return false
+ }
+ for _, id := range ids {
+ if token := canonicalPatrolScopeToken(id); token != "" {
+ emittedIDs[token] = struct{}{}
+ }
+ }
+ return true
}
hostResourceKind := func(platform string) patrolRuntimeResourceKind {
if strings.EqualFold(strings.TrimSpace(platform), "truenas") {
@@ -296,6 +317,15 @@ func patrolVisitRuntimeResources(s patrolRuntimeState, visit func(patrolRuntimeR
return
}
}
+ for _, resource := range s.unifiedResourceProvider.GetAll() {
+ if _, alreadyEmitted := emittedIDs[canonicalPatrolScopeToken(resource.ID)]; alreadyEmitted {
+ continue
+ }
+ ids, aliases := patrolUnifiedResourceIdentity(resource)
+ if !emit(patrolRuntimeResourceUnified, ids, aliases...) {
+ return
+ }
+ }
return
}
@@ -559,10 +589,11 @@ type patrolRuntimeResourceCounts struct {
pbs int
pmg int
kubernetes int
+ unified int
}
func (c patrolRuntimeResourceCounts) total() int {
- return c.nodes + c.guests + c.docker + c.storage + c.hosts + c.truenas + c.pbs + c.pmg + c.kubernetes
+ return c.nodes + c.guests + c.docker + c.storage + c.hosts + c.truenas + c.pbs + c.pmg + c.kubernetes + c.unified
}
func patrolRuntimeCountResources(s patrolRuntimeState) patrolRuntimeResourceCounts {
@@ -587,6 +618,8 @@ func patrolRuntimeCountResources(s patrolRuntimeState) patrolRuntimeResourceCoun
counts.pmg++
case patrolRuntimeResourceK8sCluster:
counts.kubernetes++
+ case patrolRuntimeResourceUnified:
+ counts.unified++
}
return true
})