{"record":{"id":"8ffaaf5b41bcf2f9","repo":"nanocoai/nanoclaw","slug":"container-name-collision-existing-container-is-no","errorCode":null,"errorMessage":"Container name collision: existing container is not this session","messagePattern":"Container name collision: existing container is not this session","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/drivers/docker-driver.ts","lineNumber":434,"sourceCode":"   * container. Adopting one by name would attach this session to a runtime it\n   * does not own, so the canonical labels are verified and a mismatch refuses\n   * loudly instead of aliasing.\n   */\n  #existingSession(name: string, key: SessionKey): boolean {\n    let out: string;\n    try {\n      out = this.#cli.run([\n        'inspect',\n        '--format',\n        `{{index .Config.Labels \"${LABELS.install}\"}}|{{index .Config.Labels \"${LABELS.group}\"}}|{{index .Config.Labels \"${LABELS.session}\"}}`,\n        name,\n      ]);\n    } catch {\n      return false;\n    }\n    const [install, group, session] = out.trim().split('|');\n    if (install === key.installSlug && group === key.agentGroupId && session === key.sessionId) return true;\n    log.warn('Container name collision: existing container is not this session', {\n      containerName: name,\n      wanted: key,\n      found: { install, group, session },\n    });\n    throw asFailureError({ kind: 'unknown', retryable: false, opaqueRef: `name-collision-${name}` });\n  }\n}\n\nclass DockerHandle implements SessionHandle {\n  #proc: SupervisedProcess | null = null;\n  /** Log hygiene only — events are never intent-filtered here (that is the hub's job). */\n  #stopping = false;\n  /** Exit code the attach process observed; undefined until it exits. */\n  #attachExitCode: number | null | undefined;\n  readonly #stderrTail: string[] = [];\n\n  constructor(\n    readonly key: SessionKey,","sourceCodeStart":416,"sourceCodeEnd":452,"githubUrl":"https://github.com/nanocoai/nanoclaw/blob/294ef2aee85218b23ad30eda9dfe10e590b54a8c/src/drivers/docker-driver.ts#L416-L452","documentation":"Docker driver throws this when a container already exists with the name this session wants, but the existing container's labels (install slug, agent group, session) don't match. It's a guard against one session's container name being taken by another session or another NanoClaw install, so prepare refuses rather than hijacking the container.","triggerScenarios":"prepare() for session X finds container nanoclaw-<hash> exists; docker inspect label query returns a different installSlug/agentGroupId/sessionId triple; a non-retryable name-collision failure is thrown.","commonSituations":"Two NanoClaw installs on one host generating colliding names; stale container left after an unclean shutdown with a re-derived session key; manual container created with a conflicting name; changed install slug without cleaning old containers.","solutions":["Run docker ps -a | grep <containerName> and inspect its labels to identify which install/session owns it","If it's a stale/orphaned container from this install, docker rm -f it and retry prepare","If it belongs to another install, change the install slug / container naming so the two installs don't collide","Never force-reuse the name; the mismatch means session data would cross installs"],"exampleFix":"# before\ncollision on nanoclaw-abc123 — unclear owner\n\n# after\ndocker inspect nanoclaw-abc123 --format '{{.Config.Labels}}'\ndocker rm -f nanoclaw-abc123   # if stale from this install\n# then retry session start","handlingStrategy":"try-catch","validationCode":"import { isFailureError } from 'src/failures.js';\n// before prepare(), check ownership:\n// docker inspect <name> labels match installSlug/agentGroupId/sessionId","typeGuard":"function isNameCollisionFailure(e: unknown): boolean {\n  return typeof (e as any)?.opaqueRef === 'string' &&\n    (e as any).opaqueRef.startsWith('name-collision-');\n}","tryCatchPattern":"try {\n  await driver.prepare(session);\n} catch (e) {\n  if (isNameCollisionFailure(e)) {\n    // inspect & remove the foreign/stale container, then surface to operator\n  } else throw e;\n}","preventionTips":["Never run two installs with the same install slug on one Docker host","Clean up containers when re-deriving session keys or changing install slug","Label containers at creation so ownership checks are always possible"],"tags":["docker","container","name-collision","isolation"],"backgroundTag":"container-name-collision","analyzedSha":"294ef2aee85218b23ad30eda9dfe10e590b54a8c","analyzedAt":"2026-08-28T13:59:10.357Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}