From 38a746a891af573dc69aa36d5e0c4decea5a8d8f Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Mon, 27 Jul 2026 04:25:28 +1000 Subject: [PATCH] fix: make agent-container Docker network explicitly configurable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit archied's container-mode agent tasks were all failing with "nats: no responders available for request" in production. Root cause: pool.go's selfNetwork() auto-detects the daemon's own Docker network by looking up a container named after os.Hostname(), then joins spawned agent containers to that same network so they can resolve "nats" by name. On carina this detection was silently failing (wrong/stale hostname vs. actual container ID) and returning "", so every per-task agent container landed on the default bridge network instead — unable to resolve "nats", never subscribing, hence "no responders" on every request. selfNetwork() swallowed every failure silently (only logged on success), so this had no diagnostic trail. Fix: added Containers.Network config field (containers.network in config.toml) so deployments can name the network explicitly instead of relying on fragile self-detection; selfNetwork() remains as a fallback but now logs a warning on every failure path so this doesn't silently recur. Wired through container.Config and cmd/archied/main.go. --- cmd/archied/main.go | 1 + internal/config/config.go | 8 ++++++++ internal/container/pool.go | 13 ++++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/cmd/archied/main.go b/cmd/archied/main.go index 77f688559..3bc745adf 100644 --- a/cmd/archied/main.go +++ b/cmd/archied/main.go @@ -219,6 +219,7 @@ func run() int { MaxConcurrency: cfg.Containers.MaxConcurrency, MaxUptime: cfg.Containers.MaxUptime.Std(), PullPolicy: cfg.Containers.PullPolicy, + Network: cfg.Containers.Network, DockerClient: dockerCli, }, cfg.NATS.URL, log) if err != nil { diff --git a/internal/config/config.go b/internal/config/config.go index af4cbc344..d9bdc933a 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -456,6 +456,14 @@ type ContainerConfig struct { VolumeTTL Duration `toml:"volume_ttl" yaml:"volume_ttl"` // PullPolicy controls image pulling: "missing" (default) or "always". PullPolicy string `toml:"pull_policy" yaml:"pull_policy"` + // Network is the Docker network spawned agent containers join, so they + // can resolve sibling compose services (nats, etc.) by name. Empty + // falls back to auto-detecting the daemon's own network, which is + // best-effort and silently yields the default bridge network (no + // hostname resolution) if detection fails — set this explicitly in + // compose/production deployments (e.g. "archie-core_default") rather + // than relying on auto-detection. + Network string `toml:"network" yaml:"network"` } // ChatConfig configures conversational front-ends (multi-agent diff --git a/internal/container/pool.go b/internal/container/pool.go index f9895ff47..0c01ea2b0 100644 --- a/internal/container/pool.go +++ b/internal/container/pool.go @@ -83,6 +83,9 @@ type Config struct { // (gate re-runs, human replies) during this window. PRD §1. GracePeriod time.Duration PullPolicy string + // Network is the Docker network spawned agent containers join. Empty + // falls back to selfNetwork's best-effort auto-detection. + Network string // DockerClient is an optional pre-connected Docker client. When nil, // NewPool creates its own via client.New(client.FromEnv). Pass a // shared client to avoid multiple independent connections. @@ -104,13 +107,18 @@ func NewPool(ctx context.Context, cfg Config, natsURL string, log *slog.Logger) } } + network := cfg.Network + if network == "" { + network = selfNetwork(ctx, cli, log) + } + p := &Pool{ cli: cli, cfg: cfg, log: log, natsURL: natsURL, ownCli: cfg.DockerClient == nil, - network: selfNetwork(ctx, cli, log), + network: network, } // Pull image if needed. @@ -296,13 +304,16 @@ func (p *Pool) pullImage(ctx context.Context) error { func selfNetwork(ctx context.Context, cli *client.Client, log *slog.Logger) string { hostname, err := os.Hostname() if err != nil { + log.Warn("container network auto-detect: os.Hostname failed, spawned containers will use the default bridge network and won't resolve sibling services by name — set containers.network explicitly", "err", err) return "" } self, err := cli.ContainerInspect(ctx, hostname, client.ContainerInspectOptions{}) if err != nil { + log.Warn("container network auto-detect: could not inspect self by hostname, spawned containers will use the default bridge network and won't resolve sibling services by name — set containers.network explicitly", "hostname", hostname, "err", err) return "" } if self.Container.NetworkSettings == nil { + log.Warn("container network auto-detect: self container has no NetworkSettings, spawned containers will use the default bridge network — set containers.network explicitly", "hostname", hostname) return "" } for name := range self.Container.NetworkSettings.Networks {