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.

Centralize canonical resource metadata refresh

rcourtman071da2c18953
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index ffd9c56f12..29eace3604 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -103,6 +103,11 @@ Those same dedicated reads also accept governed timeline filters for change
kind, source type, and source adapter, and the underlying store owns the
filtered counts so agent lifecycle routing still stays on canonical
fleet-continuity ownership instead of re-deriving resource history locally.
+The same API serializer now also refreshes canonical identity and policy
+metadata through the shared unified-resource helper before it returns
+resource payloads, so lifecycle-adjacent links keep the same canonical
+metadata pass as the rest of the resource API instead of composing local
+attach wrappers.
Invalid `sourceAdapter` values are rejected at the API boundary, so the fleet
lane continues to consume only the canonical adapter set rather than
introducing a broader compatibility escape hatch.
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 0fbf3038e9..ffe655d038 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -190,6 +190,10 @@ AI-facing policy metadata must also be cloned through the shared unified-
resource policy helper so chat and tools consumers do not maintain their own
policy copy logic. Chat mention prefetch now calls that shared helper directly
at each resolved mention site rather than going through an AI-local wrapper.
+AI resource and intelligence consumers now also refresh canonical identity and
+policy through the shared unified-resource metadata helper, so the AI runtime
+no longer keeps its own slice-level normalization shim for the same
+composition.
Chat knowledge extraction and resource-context rendering now also consume the
shared unified-resource label helpers directly, so governed labels and
redacted values stay consistent without AI-local presentation shims.
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index 801610b406..807a621587 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -138,6 +138,10 @@ The same resource contract now also exposes dedicated facet endpoints for
`/api/resources/{id}/capabilities`, `/api/resources/{id}/relationships`, and
`/api/resources/{id}/timeline`, so operators can read the graph and change
history without depending on a monolithic resource payload.
+The `/api/resources` serializer now also refreshes canonical identity and
+policy metadata through the shared unified-resource helper before it writes
+the payload, so backend and frontend contract tests stay aligned on one
+canonical metadata pass instead of consumer-local attach wrappers.
Those history reads now also accept governed `kind`, `sourceType`, and
`sourceAdapter` query filters, and the backend store owns the corresponding
filtered counts, so the timeline contract can narrow by change class and
diff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.md
index eba77507c5..f2df83c242 100644
--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md
+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md
@@ -122,6 +122,10 @@ as adjacent governed API ownership rather than timeline-store ownership. The
storage and recovery lanes still own their own persistence and query
contracts, while the control-plane execution trail remains governed by the
unified-resource and audit contracts.
+The same API resource serializer also refreshes canonical identity and policy
+metadata through the shared unified-resource helper before it writes resource
+payloads, so storage and recovery links inherit the same canonical metadata
+pass instead of carrying local attach wrappers in adjacent transport code.
The shared unified-resource facet bundle that storage-adjacent detail views
consume now also carries grouped `recentChangeKinds` counts by canonical change
kind, so storage and recovery surfaces can show the distribution of restarts,
diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.md
index 9f9b9862ab..296500760c 100644
--- a/docs/release-control/v6/internal/subsystems/unified-resources.md
+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md
@@ -26,22 +26,23 @@ cross-source deduplication.
4. `internal/unifiedresources/adapters.go`
5. `internal/unifiedresources/monitor_adapter.go`
6. `internal/unifiedresources/canonical_identity.go`
-7. `internal/unifiedresources/metrics.go`
-8. `internal/unifiedresources/metrics_targets.go`
-9. `internal/unifiedresources/registry.go`
-10. `internal/unifiedresources/resolve.go`
-11. `internal/unifiedresources/resolve_context.go`
-12. `internal/unifiedresources/resolved_host_set.go`
-13. `internal/unifiedresources/snapshot_source_filter.go`
-14. `internal/unifiedresources/store.go`
-15. `internal/unifiedresources/kubernetes_capabilities.go`
-16. `internal/unifiedresources/pbs_rollups.go`
-17. `internal/unifiedresources/monitored_systems.go`
-18. `internal/unifiedresources/capabilities.go`
-19. `internal/unifiedresources/changes.go`
-20. `internal/unifiedresources/relationships.go`
-21. `internal/unifiedresources/privacy.go`
-22. `internal/unifiedresources/actions.go`
+7. `internal/unifiedresources/policy_metadata.go`
+8. `internal/unifiedresources/metrics.go`
+9. `internal/unifiedresources/metrics_targets.go`
+10. `internal/unifiedresources/registry.go`
+11. `internal/unifiedresources/resolve.go`
+12. `internal/unifiedresources/resolve_context.go`
+13. `internal/unifiedresources/resolved_host_set.go`
+14. `internal/unifiedresources/snapshot_source_filter.go`
+15. `internal/unifiedresources/store.go`
+16. `internal/unifiedresources/kubernetes_capabilities.go`
+17. `internal/unifiedresources/pbs_rollups.go`
+18. `internal/unifiedresources/monitored_systems.go`
+19. `internal/unifiedresources/capabilities.go`
+20. `internal/unifiedresources/changes.go`
+21. `internal/unifiedresources/relationships.go`
+22. `internal/unifiedresources/privacy.go`
+23. `internal/unifiedresources/actions.go`
## Shared Boundaries
@@ -159,6 +160,10 @@ reconstructed in the HTTP handler.
The canonical resource policy model also owns a shared clone helper, so AI
chat and tools consumers preserve policy metadata by copying through the same
unified-resource contract instead of maintaining their own deep-copy logic.
+That same contract now also owns `RefreshCanonicalMetadata` and
+`RefreshCanonicalMetadataSlice`, so API and AI consumers refresh identity and
+policy in one shared pass instead of composing the same metadata steps in
+consumer-local shims.
The change emitter now also classifies canonical restart changes for Docker
and Kubernetes resources when restart counters increase or uptime resets, so
the timeline can distinguish restarts from generic state transitions instead
diff --git a/internal/ai/intelligence.go b/internal/ai/intelligence.go
index 54d3ab1881..75d010f252 100644
--- a/internal/ai/intelligence.go
+++ b/internal/ai/intelligence.go
@@ -268,7 +268,7 @@ func (i *Intelligence) GetSummary() *IntelligenceSummary {
if unifiedResourceProvider != nil {
summary.PolicyPosture = unifiedresources.SummarizePolicyPosture(
- normalizeUnifiedResourceContextSlice(unifiedResourceProvider.GetAll()),
+ unifiedresources.RefreshCanonicalMetadataSlice(unifiedResourceProvider.GetAll()),
)
}
@@ -344,7 +344,7 @@ func (i *Intelligence) GetResourceIntelligence(resourceID string) *ResourceIntel
if unifiedResourceProvider != nil {
intel.PolicyPosture = unifiedresources.SummarizePolicyPosture(
- normalizeUnifiedResourceContextSlice(unifiedResourceProvider.GetAll()),
+ unifiedresources.RefreshCanonicalMetadataSlice(unifiedResourceProvider.GetAll()),
)
}
@@ -391,7 +391,7 @@ func (i *Intelligence) DescribeResource(resourceID string) (string, string) {
return "", ""
}
- for _, resource := range normalizeUnifiedResourceContextSlice(unifiedResourceProvider.GetAll()) {
+ for _, resource := range unifiedresources.RefreshCanonicalMetadataSlice(unifiedResourceProvider.GetAll()) {
if strings.TrimSpace(resource.ID) != resourceID {
continue
}
diff --git a/internal/ai/intelligence_coverage_test.go b/internal/ai/intelligence_coverage_test.go
index b6e99344be..4923f746fd 100644
--- a/internal/ai/intelligence_coverage_test.go
+++ b/internal/ai/intelligence_coverage_test.go
@@ -246,7 +246,7 @@ func TestIntelligence_SummarizePolicyPostureUsesSharedHelper(t *testing.T) {
},
}
- summary := ur.SummarizePolicyPosture(normalizeUnifiedResourceContextSlice(resources))
+ summary := ur.SummarizePolicyPosture(ur.RefreshCanonicalMetadataSlice(resources))
if summary == nil {
t.Fatal("expected posture summary")
}
diff --git a/internal/ai/resource_context.go b/internal/ai/resource_context.go
index 8b704403c6..f1244e080e 100644
--- a/internal/ai/resource_context.go
+++ b/internal/ai/resource_context.go
@@ -98,9 +98,9 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
return false
}
- infrastructure := normalizeUnifiedResourceContextSlice(urp.GetInfrastructure())
- workloads := normalizeUnifiedResourceContextSlice(urp.GetWorkloads())
- allResources := normalizeUnifiedResourceContextSlice(urp.GetAll())
+ infrastructure := unifiedresources.RefreshCanonicalMetadataSlice(urp.GetInfrastructure())
+ workloads := unifiedresources.RefreshCanonicalMetadataSlice(urp.GetWorkloads())
+ allResources := unifiedresources.RefreshCanonicalMetadataSlice(urp.GetAll())
policyPosture := unifiedresources.SummarizePolicyPosture(allResources)
sensitivityCounts := map[unifiedresources.ResourceSensitivity]int{}
routingCounts := map[unifiedresources.ResourceRoutingScope]int{}
@@ -472,7 +472,7 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
}
}
- topCPU := normalizeUnifiedResourceContextSlice(urp.GetTopByCPU(3, nil))
+ topCPU := unifiedresources.RefreshCanonicalMetadataSlice(urp.GetTopByCPU(3, nil))
if len(topCPU) > 0 {
sections = append(sections, "\n### Top CPU Consumers")
for i, resource := range topCPU {
@@ -485,7 +485,7 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
}
}
- topMem := normalizeUnifiedResourceContextSlice(urp.GetTopByMemory(3, nil))
+ topMem := unifiedresources.RefreshCanonicalMetadataSlice(urp.GetTopByMemory(3, nil))
if len(topMem) > 0 {
sections = append(sections, "\n### Top Memory Consumers")
for i, resource := range topMem {
@@ -498,7 +498,7 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
}
}
- topDisk := normalizeUnifiedResourceContextSlice(urp.GetTopByDisk(3, nil))
+ topDisk := unifiedresources.RefreshCanonicalMetadataSlice(urp.GetTopByDisk(3, nil))
if len(topDisk) > 0 {
sections = append(sections, "\n### Top Disk Usage")
for i, resource := range topDisk {
@@ -577,27 +577,6 @@ func unifiedResourceContextIPSummary(r unifiedresources.Resource, limit int) str
return " - IPs " + unifiedresources.ResourcePolicyRedactedValue(strings.Join(ips, ", "), r.Policy, unifiedresources.ResourceRedactionIPAddress)
}
-func normalizeUnifiedResourceContextSlice(resources []unifiedresources.Resource) []unifiedresources.Resource {
- if len(resources) == 0 {
- return resources
- }
- out := make([]unifiedresources.Resource, len(resources))
- for i, resource := range resources {
- out[i] = normalizeUnifiedResourceContextResource(resource)
- }
- return out
-}
-
-func normalizeUnifiedResourceContextResource(resource unifiedresources.Resource) unifiedresources.Resource {
- if resource.Canonical != nil && resource.Policy != nil && strings.TrimSpace(resource.AISafeSummary) != "" {
- return resource
- }
- resourceCopy := resource
- unifiedresources.RefreshCanonicalIdentity(&resourceCopy)
- unifiedresources.RefreshPolicyMetadata(&resourceCopy)
- return resourceCopy
-}
-
func unifiedMetricPercent(m *unifiedresources.MetricValue) float64 {
if m == nil {
return 0
diff --git a/internal/ai/resource_context_test.go b/internal/ai/resource_context_test.go
index f57cb2abbd..46edf4923b 100644
--- a/internal/ai/resource_context_test.go
+++ b/internal/ai/resource_context_test.go
@@ -279,8 +279,7 @@ func TestBuildUnifiedResourceContextUsesAISafeSummaryForLocalOnlyResources(t *te
Hostname: "mail-gateway.internal",
},
}
- unifiedresources.RefreshCanonicalIdentity(&restricted)
- unifiedresources.RefreshPolicyMetadata(&restricted)
+ unifiedresources.RefreshCanonicalMetadata(&restricted)
stats := unifiedresources.ResourceStats{
Total: 1,
@@ -329,8 +328,7 @@ func TestBuildUnifiedResourceContextUsesAISafeSummaryForSensitiveResources(t *te
VMID: 101,
},
}
- unifiedresources.RefreshCanonicalIdentity(&sensitiveVM)
- unifiedresources.RefreshPolicyMetadata(&sensitiveVM)
+ unifiedresources.RefreshCanonicalMetadata(&sensitiveVM)
stats := unifiedresources.ResourceStats{
Total: 1,
diff --git a/internal/api/contract_test.go b/internal/api/contract_test.go
index 3faa649e93..6ea3aa4571 100644
--- a/internal/api/contract_test.go
+++ b/internal/api/contract_test.go
@@ -3713,6 +3713,12 @@ func TestContract_ResourceListPolicyMetadata(t *testing.T) {
}
resource := resp.Data[0]
+ if resource.Canonical == nil {
+ t.Fatal("expected canonical identity metadata in resource contract")
+ }
+ if strings.TrimSpace(resource.Canonical.DisplayName) == "" {
+ t.Fatal("expected canonical display name in resource contract")
+ }
if resource.Policy == nil {
t.Fatal("expected policy metadata in resource contract")
}
diff --git a/internal/api/resources.go b/internal/api/resources.go
index 288be3a7a7..37d7c1f587 100644
--- a/internal/api/resources.go
+++ b/internal/api/resources.go
@@ -134,8 +134,7 @@ func (h *ResourceHandlers) HandleListResources(w http.ResponseWriter, r *http.Re
paged, meta := paginate(resources, filters.page, filters.limit)
attachDiscoveryTargets(paged)
attachMetricsTargets(paged, registry)
- attachCanonicalIdentities(paged)
- attachResourcePolicies(paged)
+ paged = unified.RefreshCanonicalMetadataSlice(paged)
pruneResourcesForListResponse(paged)
// Build aggregations: use registry.Stats() for Total/ByStatus/BySource (unfiltered,
@@ -269,8 +268,7 @@ func (h *ResourceHandlers) HandleGetResource(w http.ResponseWriter, r *http.Requ
resourceCopy := *resource
attachDiscoveryTarget(&resourceCopy)
attachMetricsTarget(&resourceCopy, registry)
- attachCanonicalIdentity(&resourceCopy)
- attachResourcePolicy(&resourceCopy)
+ unified.RefreshCanonicalMetadata(&resourceCopy)
resourceCopy.Type = resourceContractType(resourceCopy)
w.Header().Set("Content-Type", "application/json")
@@ -462,8 +460,7 @@ func (h *ResourceHandlers) HandleGetChildren(w http.ResponseWriter, r *http.Requ
}
children := registry.GetChildren(path)
- attachCanonicalIdentities(children)
- attachResourcePolicies(children)
+ children = unified.RefreshCanonicalMetadataSlice(children)
applyResourceContractTypes(children)
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(map[string]interface{}{
@@ -1879,32 +1876,6 @@ func attachMetricsTarget(resource *unified.Resource, registry *unified.ResourceR
resource.MetricsTarget = registry.MetricsTarget(resource.ID)
}
-func attachCanonicalIdentities(resources []unified.Resource) {
- for i := range resources {
- attachCanonicalIdentity(&resources[i])
- }
-}
-
-func attachCanonicalIdentity(resource *unified.Resource) {
- if resource == nil {
- return
- }
- unified.RefreshCanonicalIdentity(resource)
-}
-
-func attachResourcePolicies(resources []unified.Resource) {
- for i := range resources {
- attachResourcePolicy(&resources[i])
- }
-}
-
-func attachResourcePolicy(resource *unified.Resource) {
- if resource == nil {
- return
- }
- unified.RefreshPolicyMetadata(resource)
-}
-
// resourceContractType maps internal unified resource shapes onto the canonical
// REST resource-type contract without exposing legacy aliases.
func resourceContractType(r unified.Resource) unified.ResourceType {
diff --git a/internal/unifiedresources/clone.go b/internal/unifiedresources/clone.go
index f7e5160a49..86f5f851a4 100644
--- a/internal/unifiedresources/clone.go
+++ b/internal/unifiedresources/clone.go
@@ -41,8 +41,7 @@ func cloneResource(in *Resource) Resource {
out.Ceph = cloneCephMeta(in.Ceph)
out.TrueNAS = cloneTrueNASData(in.TrueNAS)
out.FacetCounts = resourceFacetCounts(out)
- RefreshCanonicalIdentity(&out)
- RefreshPolicyMetadata(&out)
+ RefreshCanonicalMetadata(&out)
return out
}
diff --git a/internal/unifiedresources/code_standards_test.go b/internal/unifiedresources/code_standards_test.go
index b6c4180fe7..513104f3b5 100644
--- a/internal/unifiedresources/code_standards_test.go
+++ b/internal/unifiedresources/code_standards_test.go
@@ -340,6 +340,43 @@ func TestResourcePolicyCloneHelperUsedByAIConsumers(t *testing.T) {
}
}
+func TestCanonicalMetadataRefreshHelperUsedByConsumers(t *testing.T) {
+ requiredSnippets := map[string][]string{
+ filepath.Join(".", "policy_metadata.go"): {
+ "func RefreshCanonicalMetadata(resource *Resource)",
+ "func RefreshCanonicalMetadataSlice(resources []Resource) []Resource",
+ },
+ filepath.Join(".", "clone.go"): {
+ "RefreshCanonicalMetadata(&out)",
+ },
+ filepath.Join("..", "api", "resources.go"): {
+ "unified.RefreshCanonicalMetadata(&resourceCopy)",
+ "unified.RefreshCanonicalMetadataSlice(paged)",
+ "unified.RefreshCanonicalMetadataSlice(children)",
+ },
+ filepath.Join("..", "ai", "resource_context.go"): {
+ "unifiedresources.RefreshCanonicalMetadataSlice(urp.GetInfrastructure())",
+ "unifiedresources.RefreshCanonicalMetadataSlice(urp.GetWorkloads())",
+ "unifiedresources.RefreshCanonicalMetadataSlice(urp.GetAll())",
+ },
+ filepath.Join("..", "ai", "intelligence.go"): {
+ "unifiedresources.RefreshCanonicalMetadataSlice(unifiedResourceProvider.GetAll())",
+ },
+ }
+
+ for name, snippets := range requiredSnippets {
+ data, err := os.ReadFile(name)
+ if err != nil {
+ t.Fatalf("failed to read %s: %v", name, err)
+ }
+ for _, snippet := range snippets {
+ if !strings.Contains(string(data), snippet) {
+ t.Fatalf("%s must contain %q", name, snippet)
+ }
+ }
+ }
+}
+
func TestResourcePolicyLabelHelpersUsedByAIConsumers(t *testing.T) {
requiredSnippets := map[string][]string{
filepath.Join("..", "ai", "intelligence.go"): {
diff --git a/internal/unifiedresources/policy_metadata.go b/internal/unifiedresources/policy_metadata.go
index 8cd46941d8..31f8ee6651 100644
--- a/internal/unifiedresources/policy_metadata.go
+++ b/internal/unifiedresources/policy_metadata.go
@@ -74,6 +74,32 @@ func RefreshPolicyMetadata(resource *Resource) {
resource.AISafeSummary = buildAISafeSummary(*resource, sensitivity)
}
+// RefreshCanonicalMetadata derives the canonical identity and policy metadata
+// for a resource in one pass.
+func RefreshCanonicalMetadata(resource *Resource) {
+ if resource == nil {
+ return
+ }
+
+ RefreshCanonicalIdentity(resource)
+ RefreshPolicyMetadata(resource)
+}
+
+// RefreshCanonicalMetadataSlice returns a cloned slice with canonical identity
+// and policy metadata refreshed for each resource.
+func RefreshCanonicalMetadataSlice(resources []Resource) []Resource {
+ if len(resources) == 0 {
+ return resources
+ }
+
+ out := make([]Resource, len(resources))
+ for i, resource := range resources {
+ out[i] = resource
+ RefreshCanonicalMetadata(&out[i])
+ }
+ return out
+}
+
func classifyResourceSensitivity(resource Resource) ResourceSensitivity {
tagSet := normalizedTagSet(resource.Tags)
diff --git a/internal/unifiedresources/policy_metadata_test.go b/internal/unifiedresources/policy_metadata_test.go
index c256e0f9a5..17b9f1149f 100644
--- a/internal/unifiedresources/policy_metadata_test.go
+++ b/internal/unifiedresources/policy_metadata_test.go
@@ -79,6 +79,62 @@ func TestRefreshPolicyMetadata_ClassifiesInfrastructureAsInternal(t *testing.T)
}
}
+func TestRefreshCanonicalMetadata(t *testing.T) {
+ resource := Resource{
+ ID: "agent-1",
+ Name: "pve-node",
+ Type: ResourceTypeAgent,
+ Status: StatusOnline,
+ Agent: &AgentData{
+ Hostname: "pve-node",
+ },
+ }
+
+ RefreshCanonicalMetadata(&resource)
+
+ if resource.Canonical == nil {
+ t.Fatal("expected canonical identity metadata")
+ }
+ if resource.Policy == nil {
+ t.Fatal("expected policy metadata")
+ }
+ if resource.AISafeSummary == "" {
+ t.Fatal("expected aiSafeSummary")
+ }
+}
+
+func TestRefreshCanonicalMetadataSlice(t *testing.T) {
+ input := []Resource{
+ {
+ ID: "agent-1",
+ Name: "pve-node",
+ Type: ResourceTypeAgent,
+ Status: StatusOnline,
+ Agent: &AgentData{
+ Hostname: "pve-node",
+ },
+ },
+ }
+
+ out := RefreshCanonicalMetadataSlice(input)
+
+ if input[0].Canonical != nil {
+ t.Fatal("expected input slice to remain unmodified")
+ }
+ if len(out) != 1 {
+ t.Fatalf("expected one resource, got %d", len(out))
+ }
+ if out[0].Canonical == nil {
+ t.Fatal("expected canonical identity metadata in output slice")
+ }
+ if out[0].Policy == nil {
+ t.Fatal("expected policy metadata in output slice")
+ }
+ if out[0].AISafeSummary == "" {
+ t.Fatal("expected aiSafeSummary in output slice")
+ }
+}
+
func TestResourcePolicyPresentationLabels(t *testing.T) {
if got := ResourceSensitivityLabel(ResourceSensitivityPublic); got != "Public" {
t.Fatalf("sensitivity label = %q, want %q", got, "Public")