{"record":{"id":"02ab1a3346e10b1f","repo":"amir20/dozzle","slug":"q-matches-multiple-containers-s-to-act-on-the","errorCode":null,"errorMessage":"%q matches multiple containers: %s. To act on the right one, %s","messagePattern":"%q matches multiple containers: (.+?)\\. To act on the right one, (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cloud/tools_resolve.go","lineNumber":259,"sourceCode":"\tparts := make([]string, len(candidates))\n\tsameHost := true\n\tfor i, c := range candidates {\n\t\tparts[i] = fmt.Sprintf(\"%s (id %s, %s, on host %s)\", c.Name, shortID(c.ID), describeState(c), resolveHostName(c.Host, hostNames))\n\t\tif c.Host != candidates[0].Host {\n\t\t\tsameHost = false\n\t\t}\n\t}\n\n\tvar hint string\n\tswitch {\n\tcase hostRef != \"\" || sameHost:\n\t\t// A host was already supplied, or every candidate is on the same host —\n\t\t// scoping by host_id cannot narrow it further.\n\t\thint = \"pass the exact container id or the full container name to disambiguate\"\n\tdefault:\n\t\thint = \"pass host_id to scope to one host, or pass the exact container id\"\n\t}\n\treturn fmt.Errorf(\"%q matches multiple containers: %s. To act on the right one, %s\", containerRef, strings.Join(parts, \"; \"), hint)\n}\n\n// runningContainers returns only the candidates in the running state. It breaks\n// a multi-match tie down to the single live container when every other candidate\n// is a stopped corpse (the typical Swarm-redeploy / restart-churn case), which\n// is the one situation where picking among matches is unambiguous and safe.\nfunc runningContainers(cs []container.Container) []container.Container {\n\tlive := make([]container.Container, 0, len(cs))\n\tfor _, c := range cs {\n\t\tif strings.EqualFold(c.State, \"running\") {\n\t\t\tlive = append(live, c)\n\t\t}\n\t}\n\treturn live\n}\n\n// bestCandidate picks the single most-relevant container from an ambiguous name\n// match for the read-only path. Ordering: running beats stopped, then newest","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/amir20/dozzle/blob/d9463cbe21874e44ab79db6fa63e746ca7d22928/internal/cloud/tools_resolve.go#L241-L277","documentation":"ambiguousError is produced by resolveContainerRef when a container name/id prefix matches multiple containers. It lists each candidate (host-qualified) and adds a context-specific hint telling the LLM caller exactly how to disambiguate, since acting on the wrong container would be destructive.","triggerScenarios":"resolveContainerRef's name lookup returns several containers and the runningContainers tie-breaker did not reduce them to one; raised in the final return of ambiguousError. Triggered by tool calls using a short name or id prefix shared by multiple containers (possibly across hosts).","commonSituations":"Swarm redeploy leaves old and new replicas of the same service name; duplicate container names across hosts in a multi-host setup; id-prefix that is too short to be unique.","solutions":["Re-issue the call passing host_id to scope to a single host (per the hint when candidates span hosts)","Pass the full container id or the exact full container name instead of a prefix/short name","Clean up stale stopped containers so only one live match remains"],"exampleFix":"// before\nresolveContainerRef(ctx, deps, \"web\")\n// after\nresolveContainerRef(ctx, deps, \"a1b2c3d4e5f6\") // full id, or pass host_id: \"abc123\" alongside the name","handlingStrategy":"validation","validationCode":"matches := findContainersByName(ref)\nif len(matches) > 1 { resolve with host_id or full id before acting }","typeGuard":"func isFullContainerID(ref string) bool {\n  return len(ref) >= 32 && !strings.Contains(ref, \"/\")\n}","tryCatchPattern":null,"preventionTips":["Use full container ids in tool calls","Scope by host_id when multiple hosts are registered","Prune stopped duplicate containers after Swarm redeploys"],"tags":["cloud-tools","container-resolution","ambiguity"],"backgroundTag":"invalid-identifier","analyzedSha":"d9463cbe21874e44ab79db6fa63e746ca7d22928","analyzedAt":"2026-09-07T10:08:55.855Z","contentChangedAt":"2026-09-07T10:08:55.855Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}