fix: make agent-container Docker network explicitly configurable

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.
This commit is contained in:
sam committed 2026-07-27 04:25:28 +10:00
1 parent 63719cc3ec
commit 38a746a891
3 files changed
+21 -1

No files matched your search

+1
View File
@@ -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 {
+8
View File
@@ -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
+12 -1
View File
@@ -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 {