From 7ee252bd843ad5de80d62fd63bdfb376a1fe927d Mon Sep 17 00:00:00 2001 From: rcourtman Date: Fri, 7 Nov 2025 13:46:35 +0000 Subject: [PATCH] Fix Docker host display bug when multiple agents share API tokens (related to #658) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Root cause: findMatchingDockerHost() was matching hosts by token ID alone, causing multiple Docker agents using the same API token to overwrite each other in state. This resulted in only N visible hosts (where N = number of unique tokens) instead of all M agents, with hosts "rotating" as each agent reported every 10 seconds. Example: 4 agents using 2 tokens would show only 2 hosts, rotating between agents 1↔2 (token A) and agents 3↔4 (token B). Fix: Remove token-only matching from findMatchingDockerHost(). Hosts should only match by: 1. Agent ID (unique per agent) 2. Machine ID + hostname combination (with optional token validation) 3. Machine ID or hostname alone (only for tokenless agents) This allows multiple agents to share the same API token without colliding. Additional fix: UpsertDockerHost() now preserves Hidden, PendingUninstall, and Command fields from existing hosts, preventing these flags from being reset to defaults on every agent report. --- internal/models/models.go | 7 +++++++ internal/monitoring/monitor.go | 8 -------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/internal/models/models.go b/internal/models/models.go index 8a64817c1..40d50df67 100644 --- a/internal/models/models.go +++ b/internal/models/models.go @@ -1136,6 +1136,13 @@ func (s *State) UpsertDockerHost(host DockerHost) { if existing.CustomDisplayName != "" { host.CustomDisplayName = existing.CustomDisplayName } + // Preserve Hidden and PendingUninstall flags + host.Hidden = existing.Hidden + host.PendingUninstall = existing.PendingUninstall + // Preserve Command if it exists + if existing.Command != nil { + host.Command = existing.Command + } s.DockerHosts[i] = host updated = true break diff --git a/internal/monitoring/monitor.go b/internal/monitoring/monitor.go index f2ef55fff..48e078304 100644 --- a/internal/monitoring/monitor.go +++ b/internal/monitoring/monitor.go @@ -1304,14 +1304,6 @@ func findMatchingDockerHost(hosts []models.DockerHost, report agentsdocker.Repor } } - if tokenID != "" { - for _, host := range hosts { - if strings.TrimSpace(host.TokenID) == tokenID { - return host, true - } - } - } - if machineID != "" && hostname != "" { for _, host := range hosts { if strings.TrimSpace(host.MachineID) == machineID && strings.TrimSpace(host.Hostname) == hostname {