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
Stop the availability projection writing into the live registry
rcourtmanafc0c865d4de
diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.mdindex 3684c49e8f..646908d4bf 100644--- a/docs/release-control/v6/internal/subsystems/unified-resources.md+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md@@ -1643,6 +1643,18 @@ AI-only summary payloads, or page-local heuristics.`TestStorageTopologyAndVDevLayoutAreDistinctIdentityFields` in`internal/unifiedresources/canonical_identity_test.go`.+29. `cloneResource` owns copy isolation for every slice on `Resource`,+ including `Relationships`. A clone that shares the original's+ relationship backing array lets any in-place compaction write through+ into the live registry from whatever goroutine holds the clone, which+ is reachable on the ordinary `GET /api/resources` rebuild path.+ Relationship filters additionally build a fresh slice rather than+ compacting in place, so correctness does not depend on every caller+ having cloned first. Regression coverage:+ `TestCloneResourceGivesRelationshipsTheirOwnBackingArray` in+ `internal/unifiedresources/clone_test.go`.++## Current State### Host views expose the integration-source discriminatordiff --git a/internal/unifiedresources/availability_link_test.go b/internal/unifiedresources/availability_link_test.goindex 9a1fe3d68f..3db6e0c463 100644--- a/internal/unifiedresources/availability_link_test.go+++ b/internal/unifiedresources/availability_link_test.go@@ -576,3 +576,51 @@ func TestAvailabilityIdentityRemainsTenantLocal(t *testing.T) {)}}++// TestAvailabilityRepeatedProjectionKeepsHostRelationshipsStable pins the+// registry side of the relationship-aliasing fix. The projection scrub filters+// each resource's `checks` edges before re-projecting; when it compacted the+// slice in place, a resource whose relationships still shared a backing array+// with another copy ended up with a duplicated trailing edge. Re-ingesting the+// same check repeatedly is the ordinary path (every registry rebuild replays+// availability records), so the edge set must stay stable.+func TestAvailabilityRepeatedProjectionKeepsHostRelationshipsStable(t *testing.T) {+ rr := NewRegistry(nil)+ hostID := ingestAgentFixture(t, rr, "host-1", "machine-1")++ var checkEdges int+ for round := range 4 {+ observedAt := time.Now().UTC()+ rr.IngestRecords(SourceAvailability, []IngestRecord{+ availabilityProbeRecord("probe-1", "192.0.2.10", &AvailabilityData{+ LinkedResourceID: hostID,+ Address: "192.0.2.10",+ Protocol: "icmp",+ Enabled: true,+ Available: true,+ LastChecked: &observedAt,+ Evidence: availabilityProbeEvidence(t, "probe-1", observedAt),+ }),+ })++ host, ok := rr.Get(hostID)+ if !ok || host == nil {+ t.Fatalf("host %q missing after round %d", hostID, round)+ }++ round0Edges := 0+ for _, relationship := range host.Relationships {+ if relationship.Type == RelChecks {+ round0Edges+++ }+ }+ if round == 0 {+ checkEdges = round0Edges+ continue+ }+ if round0Edges != checkEdges {+ t.Fatalf("round %d: checks edges = %d, want %d stable across re-projection",+ round, round0Edges, checkEdges)+ }+ }+}diff --git a/internal/unifiedresources/clone.go b/internal/unifiedresources/clone.goindex 7ed599e71c..c15b7aeba3 100644--- a/internal/unifiedresources/clone.go+++ b/internal/unifiedresources/clone.go@@ -34,6 +34,7 @@ func cloneResource(in *Resource) Resource {out.parentBySource = cloneParentBySourceMap(in.parentBySource)out.Tags = cloneStringSlice(in.Tags)out.Incidents = cloneResourceIncidentSlice(in.Incidents)+ out.Relationships = cloneResourceRelationshipSlice(in.Relationships)out.Proxmox = cloneProxmoxData(in.Proxmox)out.Storage = cloneStorageMeta(in.Storage)out.Agent = cloneAgentData(in.Agent)@@ -208,6 +209,19 @@ func cloneStorageConsumerMetaSlice(in []StorageConsumerMeta) []StorageConsumerMereturn out}+// cloneResourceRelationshipSlice gives the clone its own backing array. Without+// it a clone shares the original's array, and any in-place compaction (a+// `Relationships[:0]` filter) writes straight through into the live registry+// from whatever goroutine holds the clone.+func cloneResourceRelationshipSlice(in []ResourceRelationship) []ResourceRelationship {+ if len(in) == 0 {+ return nil+ }+ out := make([]ResourceRelationship, len(in))+ copy(out, in)+ return out+}+func cloneResourceIncidentSlice(in []ResourceIncident) []ResourceIncident {if len(in) == 0 {return nildiff --git a/internal/unifiedresources/clone_test.go b/internal/unifiedresources/clone_test.goindex bd0ad3c127..17815a5495 100644--- a/internal/unifiedresources/clone_test.go+++ b/internal/unifiedresources/clone_test.go@@ -718,3 +718,45 @@ func TestZeroTimeToPtr_NonZeroReturnsPtr(t *testing.T) {t.Error("returned time should equal input")}}++// TestCloneResourceGivesRelationshipsTheirOwnBackingArray pins the aliasing fix+// for the availability projection scrub. cloneResource deep-copies every other+// slice on Resource; Relationships was left shallow, so a clone shared the+// original's backing array and removeAvailabilityProjectionLocked's in-place+// compaction wrote through into the live registry from an HTTP goroutine.+func TestCloneResourceGivesRelationshipsTheirOwnBackingArray(t *testing.T) {+ original := Resource{+ ID: "host-1",+ Type: ResourceTypeAgent,+ Name: "host-1",+ Relationships: []ResourceRelationship{+ {SourceID: "check-1", TargetID: "host-1", Type: RelChecks, Active: true},+ {SourceID: "check-2", TargetID: "host-1", Type: RelChecks, Active: true},+ {SourceID: "host-1", TargetID: "vm-1", Type: RelRunsOn, Active: true},+ },+ }++ cloned := cloneResource(&original)+ if len(cloned.Relationships) != 3 {+ t.Fatalf("cloned relationships = %d, want 3", len(cloned.Relationships))+ }++ // Simulate the projection scrub compacting the clone in place.+ filtered := cloned.Relationships[:0]+ for _, relationship := range cloned.Relationships {+ if relationship.Type == RelChecks {+ continue+ }+ filtered = append(filtered, relationship)+ }+ cloned.Relationships = filtered++ if len(original.Relationships) != 3 {+ t.Fatalf("original relationships = %d, want 3", len(original.Relationships))+ }+ for i, want := range []string{"check-1", "check-2", "host-1"} {+ if got := original.Relationships[i].SourceID; got != want {+ t.Fatalf("original relationship %d sourceID = %q, want %q (clone wrote through)", i, got, want)+ }+ }+}diff --git a/internal/unifiedresources/registry.go b/internal/unifiedresources/registry.goindex 5f75383c6d..1bfb18fc3d 100644--- a/internal/unifiedresources/registry.go+++ b/internal/unifiedresources/registry.go@@ -2607,7 +2607,10 @@ func (rr *ResourceRegistry) removeAvailabilityProjectionLocked(}}- filteredRelationships := resource.Relationships[:0]+ // Build a fresh slice rather than compacting in place: callers may hold+ // a resource whose relationships still share a backing array with+ // another copy, and an in-place filter would write through into it.+ filteredRelationships := make([]ResourceRelationship, 0, len(resource.Relationships))for _, relationship := range resource.Relationships {relationshipTargetID, _ := relationship.Metadata["targetId"].(string)if relationship.Type == RelChecks &&