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
Avoid discarded identity candidates in live broadcast projections
pulse-triage[bot]c0525852f82a
diff --git a/docs/release-control/v6/internal/subsystems/performance-and-scalability.md b/docs/release-control/v6/internal/subsystems/performance-and-scalability.mdindex cbbd9a423f..c84ba58888 100644--- a/docs/release-control/v6/internal/subsystems/performance-and-scalability.md+++ b/docs/release-control/v6/internal/subsystems/performance-and-scalability.md@@ -15,6 +15,25 @@## Purpose+### Bounded confidence/priority work in broadcast grouping — issue #2199++The general identity matcher retains every confidence, reason, ordering and+review flag. Top-level grouping requests only its existing high-confidence+floor (0.90), so hostname-only and IP-only peer sets are not built when no+eligible composite signal exists. High-confidence results are identical to+filtering the full general matcher; machine ID, UUID and hostname+MAC still+keep their existing precedence. Host/IP fallback still requires exactly one+strictly better-priority owner. Equal/worse-priority peers are discarded before+allocating/sorting fallback candidates, and a best-priority group has no possible+attachment target. No identity, ambiguity, count, group ID or explanation rule+changes, and no cached output hides live transitions.++Independent pre-repair matching/grouping oracles, candidate-floor differential+cases/fuzzing, a discarded-peer allocation bound, mixed grouping records and the+complete existing identity/topology suites protect these constraints. The+residual synthetic broadcast profile identified discarded matching/grouping as+the dominant cost; it is not a profile of the reporter's installed agent fleet.+### Connected-dashboard snapshot ownership — issue #2199Concrete frontend snapshots encode resources individually into immutable owneddiff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.mdindex 7bf7b0c4a7..04d35708f2 100644--- a/docs/release-control/v6/internal/subsystems/unified-resources.md+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md@@ -23,6 +23,25 @@ and sort the complete canonical change table while startup and ingestion wait.## Purpose+### Bounded confidence/priority work in broadcast grouping — issue #2199++The general identity matcher retains every confidence, reason, ordering and+review flag. Top-level grouping requests only its existing high-confidence+floor (0.90), so hostname-only and IP-only peer sets are not built when no+eligible composite signal exists. High-confidence results are identical to+filtering the full general matcher; machine ID, UUID and hostname+MAC still+keep their existing precedence. Host/IP fallback still requires exactly one+strictly better-priority owner. Equal/worse-priority peers are discarded before+allocating/sorting fallback candidates, and a best-priority group has no possible+attachment target. No identity, ambiguity, count, group ID or explanation rule+changes, and no cached output hides live transitions.++Independent pre-repair matching/grouping oracles, candidate-floor differential+cases/fuzzing, a discarded-peer allocation bound, mixed grouping records and the+complete existing identity/topology suites protect these constraints. The+residual synthetic broadcast profile identified discarded matching/grouping as+the dominant cost; it is not a profile of the reporter's installed agent fleet.+### Allocation-bounded snapshot and clone metadata — issue #2199WebSocket snapshot extraction decodes every entry's ID from the encoded arraydiff --git a/internal/monitoring/canonical_guardrails_test.go b/internal/monitoring/canonical_guardrails_test.goindex 29ee0fb7b1..abb02e0309 100644--- a/internal/monitoring/canonical_guardrails_test.go+++ b/internal/monitoring/canonical_guardrails_test.go@@ -608,7 +608,8 @@ func TestBroadcastResourceProjectionCoalescesSplitHostIdentities(t *testing.T) {for _, snippet := range []string{"metricsTargetResolver := broadcastMetricsTargetResolver(unifiedView.readState)","broadcastResources := unifiedresources.CoalescePresentationHostResources(unifiedView.resources)",- "broadcastFrontendResources, broadcastCatalogs := convertResourcesForBroadcast(broadcastResources, metricsTargetResolver)",+ "broadcastFrontendResources, broadcastCatalogs := convertPresentationResourcesForBroadcast(",+ "attachBroadcastMetricsTargets(broadcastResources, metricsTargetResolver)","frontendState.CapabilityCatalog = broadcastCatalogs.capabilities","frontendState.PolicyCatalog = broadcastCatalogs.policies","frontendState.AISafeSummaryCatalog = broadcastCatalogs.aiSafeSummaries",diff --git a/internal/unifiedresources/broadcast_grouping_reference_test.go b/internal/unifiedresources/broadcast_grouping_reference_test.gonew file mode 100644index 0000000000..7f20ffd5a0--- /dev/null+++ b/internal/unifiedresources/broadcast_grouping_reference_test.go@@ -0,0 +1,308 @@+package unifiedresources++import (+ "sort"+ "strings"+)++// Pre-repair matching and grouping are independent content oracles. Broad+// matching must keep every confidence/review result; grouping may only avoid+// candidates its existing threshold/priority rules already reject.+func (m *IdentityMatcher) findCandidatesReference(identity ResourceIdentity) []MatchCandidate {+ candidates := make(map[string]MatchCandidate)++ // Machine ID match+ if identity.MachineID != "" {+ if existing, ok := m.byMachineID[strings.TrimSpace(identity.MachineID)]; ok {+ candidates[existing] = MatchCandidate{ID: existing, Confidence: 1.0, Reason: "machine_id"}+ }+ }++ // DMI UUID match+ if identity.DMIUUID != "" {+ if existing, ok := m.byDMIUUID[strings.TrimSpace(identity.DMIUUID)]; ok {+ candidates[existing] = promoteCandidate(candidates[existing], MatchCandidate{ID: existing, Confidence: 0.99, Reason: "dmi_uuid"})+ }+ }++ hostnameIDs := m.collectIDs(m.byHostname, identity.Hostnames, NormalizeHostname)+ ipIDs := m.collectIDs(m.byIP, identity.IPAddresses, NormalizeIP)+ macIDs := m.collectIDs(m.byMAC, identity.MACAddresses, NormalizeMAC)++ // Hostname + MAC overlap+ for id := range intersectIDs(hostnameIDs, macIDs) {+ candidates[id] = promoteCandidate(candidates[id], MatchCandidate{ID: id, Confidence: 0.90, Reason: "hostname+mac"})+ }++ // Hostname + IP overlap+ for id := range intersectIDs(hostnameIDs, ipIDs) {+ candidates[id] = promoteCandidate(candidates[id], MatchCandidate{+ ID: id,+ Confidence: 0.80,+ Reason: "hostname+ip",+ RequiresReview: true,+ })+ }++ // Hostname only+ for id := range hostnameIDs {+ candidates[id] = promoteCandidate(candidates[id], MatchCandidate{ID: id, Confidence: 0.50, Reason: "hostname", RequiresReview: true})+ }++ // IP only+ for id := range ipIDs {+ candidates[id] = promoteCandidate(candidates[id], MatchCandidate{ID: id, Confidence: 0.40, Reason: "ip", RequiresReview: true})+ }++ list := make([]MatchCandidate, 0, len(candidates))+ for _, candidate := range candidates {+ list = append(list, candidate)+ }++ sort.Slice(list, func(i, j int) bool {+ if list[i].Confidence == list[j].Confidence {+ return list[i].ID < list[j].ID+ }+ return list[i].Confidence > list[j].Confidence+ })++ return list+}++func resolveTopLevelSystemsReference(resources []Resource) TopLevelSystemResolver {+ if len(resources) == 0 {+ return TopLevelSystemResolver{+ groups: nil,+ resourceToGroup: map[string]string{},+ }+ }++ nodes := make([]topLevelSystemNode, 0, len(resources))+ for i := range resources {+ node := buildTopLevelSystemNode(&resources[i])+ if node.resource == nil {+ continue+ }+ nodes = append(nodes, node)+ }+ if len(nodes) == 0 {+ return TopLevelSystemResolver{+ groups: nil,+ resourceToGroup: map[string]string{},+ }+ }++ parent := make([]int, len(nodes))+ for i := range parent {+ parent[i] = i+ }+ groupEvidence := make(map[int][]topLevelSystemGroupingEvidence, len(nodes))++ find := func(id int) int {+ for parent[id] != id {+ parent[id] = parent[parent[id]]+ id = parent[id]+ }+ return id+ }++ union := func(left, right int, evidence topLevelSystemGroupingEvidence) {+ leftRoot := find(left)+ rightRoot := find(right)+ if leftRoot == rightRoot {+ return+ }+ if existing := groupEvidence[leftRoot]; len(existing) > 0 {+ groupEvidence[rightRoot] = append(groupEvidence[rightRoot], existing...)+ delete(groupEvidence, leftRoot)+ }+ parent[leftRoot] = rightRoot+ if evidence.kind != "" {+ groupEvidence[rightRoot] = append(groupEvidence[rightRoot], evidence)+ }+ }++ strongIDOwners := make(map[string]int)+ for i := range nodes {+ for _, strongID := range topLevelSystemOrderedStrongIDs(nodes[i].strongIDs) {+ if existing, ok := strongIDOwners[strongID]; ok {+ union(i, existing, topLevelSystemStrongIDEvidence(nodes[i].resource, nodes[existing].resource, strongID))+ continue+ }+ strongIDOwners[strongID] = i+ }+ }++ matcher := NewIdentityMatcher()+ nodeIDByMatcherID := make(map[string]int, len(nodes))+ for i := range nodes {+ matcherID := topLevelSystemMatcherID(i)+ nodeIDByMatcherID[matcherID] = i+ matcher.Add(matcherID, nodes[i].identity)+ }+ for i := range nodes {+ matches := matcher.findCandidatesReference(nodes[i].identity)+ for _, match := range matches {+ if match.Confidence < HighConfidenceThreshold {+ continue+ }+ existingIndex, ok := nodeIDByMatcherID[match.ID]+ if !ok || existingIndex == i {+ continue+ }+ union(i, existingIndex, topLevelSystemIdentityMatchEvidence(nodes[i].resource, nodes[existingIndex].resource, match.Reason))+ }+ }++ for {+ initialGroups := buildTopLevelSystemResolvedGroups(nodes, parent, groupEvidence)+ hostOwners, ipOwners := buildTopLevelSystemFallbackOwners(initialGroups)+ hostFormOwners := buildTopLevelSystemHostFormOwners(initialGroups)+ attached := false++ for groupRoot, group := range initialGroups {+ if !group.attachByHost {+ continue+ }+ target, ok := uniqueBetterTopLevelSystemTargetReference(groupRoot, group, hostOwners, ipOwners, hostFormOwners, initialGroups)+ if !ok {+ continue+ }+ union(groupRoot, target.root, target.evidence)+ attached = true+ }++ if !attached {+ finalGroups := buildTopLevelSystemResolvedGroups(nodes, parent, groupEvidence)+ orderedGroups := make([]topLevelSystemResolvedGroup, 0, len(finalGroups))+ for _, group := range finalGroups {+ orderedGroups = append(orderedGroups, group)+ }+ sort.Slice(orderedGroups, func(i, j int) bool {+ if orderedGroups[i].priority != orderedGroups[j].priority {+ return orderedGroups[i].priority < orderedGroups[j].priority+ }+ if len(orderedGroups[i].resources) == 0 || len(orderedGroups[j].resources) == 0 {+ return orderedGroups[i].id < orderedGroups[j].id+ }+ left := monitoredSystemDisplayName(orderedGroups[i].resources, preferredMonitoredSystemResource(orderedGroups[i].resources))+ right := monitoredSystemDisplayName(orderedGroups[j].resources, preferredMonitoredSystemResource(orderedGroups[j].resources))+ if left == right {+ return orderedGroups[i].id < orderedGroups[j].id+ }+ return left < right+ })++ resourceToGroup := make(map[string]string, len(nodes))+ for _, group := range orderedGroups {+ for _, resource := range group.resources {+ if resource == nil || strings.TrimSpace(resource.ID) == "" {+ continue+ }+ resourceToGroup[strings.TrimSpace(resource.ID)] = group.id+ }+ }++ return TopLevelSystemResolver{+ groups: orderedGroups,+ resourceToGroup: resourceToGroup,+ }+ }+ }+}++func uniqueBetterTopLevelSystemTargetReference(+ groupRoot int,+ group topLevelSystemResolvedGroup,+ hostOwners map[string]map[int]struct{},+ ipOwners map[string]map[int]struct{},+ hostFormOwners map[string]map[int]struct{},+ groups map[int]topLevelSystemResolvedGroup,+) (topLevelSystemFallbackTarget, bool) {+ targets := make(map[int]topLevelSystemGroupingEvidence)+ candidateRoots := make(map[int]struct{})+ for host := range group.exactHosts {+ comparable := normalizeComparableHostname(host)+ if comparable == "" {+ continue+ }+ for root := range hostFormOwners[comparable] {+ candidateRoots[root] = struct{}{}+ }+ if short := NormalizeHostname(comparable); short != "" && short != comparable {+ for root := range hostFormOwners[short] {+ candidateRoots[root] = struct{}{}+ }+ }+ }++ for _, host := range topLevelSystemSortedSet(group.exactHosts) {+ for _, targetRoot := range topLevelSystemSortedRoots(hostOwners[host]) {+ if targetRoot == groupRoot {+ continue+ }+ if groups[targetRoot].priority >= group.priority {+ continue+ }+ if _, ok := targets[targetRoot]; !ok {+ targets[targetRoot] = topLevelSystemAttachmentEvidence(+ group,+ groups[targetRoot],+ "exact-host-attachment",+ "exact-host",+ host,+ )+ }+ }+ }+ for _, targetRoot := range topLevelSystemSortedRoots(candidateRoots) {+ if targetRoot == groupRoot {+ continue+ }+ if groups[targetRoot].priority >= group.priority {+ continue+ }+ if _, ok := targets[targetRoot]; ok {+ continue+ }+ if value, ok := topLevelSystemShortFormHostMatchValue(group.exactHosts, groups[targetRoot].exactHosts); ok {+ targets[targetRoot] = topLevelSystemAttachmentEvidence(+ group,+ groups[targetRoot],+ "hostname-form-attachment",+ "short-hostname",+ value,+ )+ }+ }+ for _, ip := range topLevelSystemSortedSet(group.exactIPs) {+ for _, targetRoot := range topLevelSystemSortedRoots(ipOwners[ip]) {+ if targetRoot == groupRoot {+ continue+ }+ if groups[targetRoot].priority >= group.priority {+ continue+ }+ if _, ok := targets[targetRoot]; !ok {+ targets[targetRoot] = topLevelSystemAttachmentEvidence(+ group,+ groups[targetRoot],+ "exact-ip-attachment",+ "exact-ip",+ ip,+ )+ }+ }+ }++ if len(targets) != 1 {+ return topLevelSystemFallbackTarget{}, false+ }+ for targetRoot, evidence := range targets {+ return topLevelSystemFallbackTarget{+ root: targetRoot,+ evidence: evidence,+ }, true+ }+ return topLevelSystemFallbackTarget{}, false+}diff --git a/internal/unifiedresources/identity.go b/internal/unifiedresources/identity.goindex c44cb6050f..22911558e9 100644--- a/internal/unifiedresources/identity.go+++ b/internal/unifiedresources/identity.go@@ -167,6 +167,14 @@ type MatchCandidate struct {// FindCandidates returns possible matches based on the identity signals.func (m *IdentityMatcher) FindCandidates(identity ResourceIdentity) []MatchCandidate {+ return m.findCandidatesAtLeast(identity, 0)+}++// findCandidatesAtLeast avoids materializing signals the caller will discard.+// Top-level grouping accepts only high-confidence matches; producing every+// hostname-only peer made broadcast projection quadratic on shared hostnames.+// General matching still requests the complete candidate/review vocabulary.+func (m *IdentityMatcher) findCandidatesAtLeast(identity ResourceIdentity, minimum float64) []MatchCandidate {candidates := make(map[string]MatchCandidate)// Machine ID match@@ -183,9 +191,16 @@ func (m *IdentityMatcher) FindCandidates(identity ResourceIdentity) []MatchCandi}}- hostnameIDs := m.collectIDs(m.byHostname, identity.Hostnames, NormalizeHostname)- ipIDs := m.collectIDs(m.byIP, identity.IPAddresses, NormalizeIP)- macIDs := m.collectIDs(m.byMAC, identity.MACAddresses, NormalizeMAC)+ var hostnameIDs, ipIDs, macIDs map[string]struct{}+ if minimum <= 0.90 && len(identity.MACAddresses) > 0 {+ macIDs = m.collectIDs(m.byMAC, identity.MACAddresses, NormalizeMAC)+ }+ if minimum <= 0.80 && len(identity.IPAddresses) > 0 {+ ipIDs = m.collectIDs(m.byIP, identity.IPAddresses, NormalizeIP)+ }+ if minimum <= 0.50 || (minimum <= 0.90 && len(macIDs) > 0) || (minimum <= 0.80 && len(ipIDs) > 0) {+ hostnameIDs = m.collectIDs(m.byHostname, identity.Hostnames, NormalizeHostname)+ }// Hostname + MAC overlapfor id := range intersectIDs(hostnameIDs, macIDs) {@@ -214,7 +229,9 @@ func (m *IdentityMatcher) FindCandidates(identity ResourceIdentity) []MatchCandilist := make([]MatchCandidate, 0, len(candidates))for _, candidate := range candidates {- list = append(list, candidate)+ if candidate.Confidence >= minimum {+ list = append(list, candidate)+ }}sort.Slice(list, func(i, j int) bool {diff --git a/internal/unifiedresources/identity_test.go b/internal/unifiedresources/identity_test.goindex e9aa5576dc..889770f093 100644--- a/internal/unifiedresources/identity_test.go+++ b/internal/unifiedresources/identity_test.go@@ -2,6 +2,7 @@ package unifiedresourcesimport ("fmt"+ "reflect""testing")@@ -189,3 +190,73 @@ func TestIPOnlyMatchRequiresReview(t *testing.T) {t.Fatalf("expected requires review")}}++func assertCandidateFloorMatchesReference(t testing.TB, matcher *IdentityMatcher, query ResourceIdentity) {+ t.Helper()+ full := matcher.findCandidatesReference(query)+ if got := matcher.FindCandidates(query); !reflect.DeepEqual(got, full) {+ t.Fatalf("general identity candidate/review results changed: got=%v want=%v", got, full)+ }+ for _, minimum := range []float64{0, 0.4, 0.5, 0.8, HighConfidenceThreshold, 0.99, 1.0, 1.1} {+ want := make([]MatchCandidate, 0)+ for _, match := range full {+ if match.Confidence >= minimum {+ want = append(want, match)+ }+ }+ if got := matcher.findCandidatesAtLeast(query, minimum); !reflect.DeepEqual(got, want) {+ t.Fatalf("floor %v changed identity/reason/order/review: got=%v want=%v", minimum, got, want)+ }+ }+}++func TestBroadcastIdentityFloorMatchesGeneralMatching(t *testing.T) {+ matcher := NewIdentityMatcher()+ identities := []ResourceIdentity{+ {MachineID: "machine", DMIUUID: "uuid", Hostnames: []string{"tower.local"}, IPAddresses: []string{"192.0.2.10"}, MACAddresses: []string{"00:11:22:33:44:55"}},+ {Hostnames: []string{"tower.remote"}, IPAddresses: []string{"192.0.2.10"}, MACAddresses: []string{"00-11-22-33-44-55"}},+ {Hostnames: []string{"tower.other"}, IPAddresses: []string{"192.0.2.11"}},+ {Hostnames: []string{"distinct"}, IPAddresses: []string{"127.0.0.1", "172.17.0.1"}},+ {},+ }+ for i, identity := range identities {+ matcher.Add(fmt.Sprint(i), identity)+ }+ for _, query := range append(identities, ResourceIdentity{MachineID: " machine ", DMIUUID: " uuid ", Hostnames: []string{"TOWER"}}) {+ assertCandidateFloorMatchesReference(t, matcher, query)+ }+}++func TestBroadcastIdentityFloorDoesNotAllocateDiscardedPeers(t *testing.T) {+ makeMatcher := func(count int) *IdentityMatcher {+ matcher := NewIdentityMatcher()+ for i := 0; i < count; i++ {+ matcher.Add(fmt.Sprint(i), ResourceIdentity{Hostnames: []string{"shared-host.local"}})+ }+ return matcher+ }+ query := ResourceIdentity{Hostnames: []string{"shared-host.local"}}+ small, large := makeMatcher(8), makeMatcher(1000)+ if len(large.FindCandidates(query)) != 1000 || len(large.findCandidatesAtLeast(query, HighConfidenceThreshold)) != 0 {+ t.Fatal("candidate floor changed hostname confidence")+ }+ smallAllocs := testing.AllocsPerRun(20, func() { small.findCandidatesAtLeast(query, HighConfidenceThreshold) })+ largeAllocs := testing.AllocsPerRun(20, func() { large.findCandidatesAtLeast(query, HighConfidenceThreshold) })+ if largeAllocs > smallAllocs+8 {+ t.Fatalf("discarded peers allocate with estate size: %v vs %v", smallAllocs, largeAllocs)+ }+}++func FuzzBroadcastIdentityFloorMatchesGeneralMatching(f *testing.F) {+ f.Add("machine", "uuid", "tower.local", "192.0.2.10", "00:11:22:33:44:55")+ f.Add("", "", "tower.remote", "127.0.0.1", "")+ f.Fuzz(func(t *testing.T, machine, uuid, host, ip, mac string) {+ query := ResourceIdentity{MachineID: machine, DMIUUID: uuid, Hostnames: []string{host}, IPAddresses: []string{ip}, MACAddresses: []string{mac}}+ matcher := NewIdentityMatcher()+ matcher.Add("exact", query)+ matcher.Add("hostname", ResourceIdentity{Hostnames: query.Hostnames})+ matcher.Add("ip", ResourceIdentity{IPAddresses: query.IPAddresses})+ matcher.Add("hostname-mac", ResourceIdentity{Hostnames: query.Hostnames, MACAddresses: query.MACAddresses})+ assertCandidateFloorMatchesReference(t, matcher, query)+ })+}diff --git a/internal/unifiedresources/resolved_host_set_test.go b/internal/unifiedresources/resolved_host_set_test.goindex 647cf8bd65..d018608dca 100644--- a/internal/unifiedresources/resolved_host_set_test.go+++ b/internal/unifiedresources/resolved_host_set_test.go@@ -1,6 +1,8 @@package unifiedresourcesimport (+ "encoding/json"+ "fmt""testing""time"@@ -662,3 +664,30 @@ func TestResolvedFormatTime(t *testing.T) {t.Fatalf("expected RFC3339, got %q", got)}}++func TestBroadcastGroupingMatchesPreviousAlgorithm(t *testing.T) {+ for _, count := range []int{0, 1, 8, 100} {+ resources := []Resource{+ topLevelTestAgent("agent", "tower.local", "machine", "agent-id"),+ topLevelTestDockerHost("docker", "tower.local", "docker-id", "agent-id"),+ topLevelTestAgent("different", "separate.local", "other-machine", "other-agent"),+ }+ for i := 0; i < count; i++ {+ resources = append(resources, Resource{ID: fmt.Sprintf("vm-%d", i), Type: ResourceTypeVM, Name: fmt.Sprintf("vm-%d", i), Proxmox: &ProxmoxData{NodeName: "tower.local", VMID: i + 100}, Identity: ResourceIdentity{Hostnames: []string{"shared-node.local"}}})+ }+ got, want := ResolveTopLevelSystems(resources), resolveTopLevelSystemsReference(resources)+ if got.Count() != want.Count() {+ t.Fatalf("count %d: groups %d != %d", count, got.Count(), want.Count())+ }+ for _, r := range resources {+ if got.GroupIDForResource(r) != want.GroupIDForResource(r) {+ t.Fatalf("%s identity/group changed", r.ID)+ }+ }+ gotJSON, _ := json.Marshal(got.records())+ wantJSON, _ := json.Marshal(want.records())+ if string(gotJSON) != string(wantJSON) {+ t.Fatalf("count %d: group record/explanation changed", count)+ }+ }+}diff --git a/internal/unifiedresources/top_level_systems.go b/internal/unifiedresources/top_level_systems.goindex b2629bada2..c46721f24e 100644--- a/internal/unifiedresources/top_level_systems.go+++ b/internal/unifiedresources/top_level_systems.go@@ -122,7 +122,7 @@ func ResolveTopLevelSystems(resources []Resource) TopLevelSystemResolver {matcher.Add(matcherID, nodes[i].identity)}for i := range nodes {- matches := matcher.FindCandidates(nodes[i].identity)+ matches := matcher.findCandidatesAtLeast(nodes[i].identity, HighConfidenceThreshold)for _, match := range matches {if match.Confidence < HighConfidenceThreshold {continue@@ -137,12 +137,18 @@ func ResolveTopLevelSystems(resources []Resource) TopLevelSystemResolver {for {initialGroups := buildTopLevelSystemResolvedGroups(nodes, parent, groupEvidence)+ bestPriority := int(^uint(0) >> 1)+ for _, group := range initialGroups {+ if group.priority < bestPriority {+ bestPriority = group.priority+ }+ }hostOwners, ipOwners := buildTopLevelSystemFallbackOwners(initialGroups)hostFormOwners := buildTopLevelSystemHostFormOwners(initialGroups)attached := falsefor groupRoot, group := range initialGroups {- if !group.attachByHost {+ if !group.attachByHost || group.priority <= bestPriority {continue}target, ok := uniqueBetterTopLevelSystemTarget(groupRoot, group, hostOwners, ipOwners, hostFormOwners, initialGroups)@@ -480,17 +486,21 @@ func uniqueBetterTopLevelSystemTarget(continue}for root := range hostFormOwners[comparable] {- candidateRoots[root] = struct{}{}+ if root != groupRoot && groups[root].priority < group.priority {+ candidateRoots[root] = struct{}{}+ }}if short := NormalizeHostname(comparable); short != "" && short != comparable {for root := range hostFormOwners[short] {- candidateRoots[root] = struct{}{}+ if root != groupRoot && groups[root].priority < group.priority {+ candidateRoots[root] = struct{}{}+ }}}}for _, host := range topLevelSystemSortedSet(group.exactHosts) {- for _, targetRoot := range topLevelSystemSortedRoots(hostOwners[host]) {+ for _, targetRoot := range topLevelSystemBetterRoots(hostOwners[host], groups, group.priority) {if targetRoot == groupRoot {continue}@@ -529,7 +539,7 @@ func uniqueBetterTopLevelSystemTarget(}}for _, ip := range topLevelSystemSortedSet(group.exactIPs) {- for _, targetRoot := range topLevelSystemSortedRoots(ipOwners[ip]) {+ for _, targetRoot := range topLevelSystemBetterRoots(ipOwners[ip], groups, group.priority) {if targetRoot == groupRoot {continue}@@ -960,6 +970,19 @@ func topLevelSystemSortedRoots(values map[int]struct{}) []int {return out}+// Discard ineligible equal/worse-priority peers before allocating and sorting+// candidate lists. They could never win the existing attachment rule.+func topLevelSystemBetterRoots(values map[int]struct{}, groups map[int]topLevelSystemResolvedGroup, priority int) []int {+ var out []int+ for root := range values {+ if groups[root].priority < priority {+ out = append(out, root)+ }+ }+ sort.Ints(out)+ return out+}+func topLevelSystemMaxInt(left, right int) int {if left > right {return left