fix(bottle): identity-key all per-bottle resources by (agent, cwd)
test / unit (pull_request) Successful in 16s
test / integration (pull_request) Successful in 1m30s

The single point that computed `slug = slugify(agent_name)` in
prepare.py is now `slug = bottle_identity(agent_name, cwd)`. With
--cwd the identity has a sha256(resolved-cwd)[:12] suffix, so the
same agent against different projects gets distinct container
names, network names, queue dir, audit log paths, and per-bottle
state (Dockerfile + transcript). Without --cwd the identity is
just slugify(agent_name), unchanged from before — no-cwd bottles
look the same as today.

The downstream `slug` field on DockerBottlePlan keeps its name —
every module already threads it under "slug" and the value flowing
through is now the bottle's full identity. A comment in prepare.py
flags the change.

Fixes the bug surfaced in PR #22 review: running the same agent
against project-A's cwd then project-B's would silently share
project-A's per-bottle Dockerfile + transcript snapshot, container
name (forcing serialized runs), and queue/audit history.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-25 05:46:26 -04:00
parent ac8f14ae6f
commit e996f72532
3 changed files with 99 additions and 15 deletions
+11 -1
View File
@@ -27,6 +27,7 @@ from .cred_proxy import (
)
from .git_gate import DockerGitGate, git_gate_container_name
from .bottle_state import (
bottle_identity,
per_bottle_dockerfile,
per_bottle_dockerfile_path,
per_bottle_image_tag,
@@ -53,7 +54,16 @@ def resolve_plan(
agent = manifest.agents[spec.agent_name]
bottle = manifest.bottle_for(spec.agent_name)
slug = docker_mod.slugify(spec.agent_name)
# PRD 0016 follow-up: identity, not bare slug. With --cwd, the
# identity carries a sha256(cwd) suffix so the same agent against
# different projects gets distinct container names, networks,
# queue + audit + state dirs. Without --cwd, identity ==
# slugify(agent_name) — same value the old `slug` produced — so
# no-cwd bottles look unchanged. We keep the variable named `slug`
# because every downstream module already threads it under that
# name; the value is now the bottle's full identity.
cwd_for_identity = Path(spec.user_cwd).resolve() if spec.copy_cwd else None
slug = bottle_identity(spec.agent_name, cwd_for_identity)
# PRD 0016 capability-block: if a per-bottle Dockerfile has been
# written (via apply_capability_change), the base image becomes