Repository navigation
Description
Found during the /review of PR #1666 (#1664/#1665/#1667). That PR establishes the invariant that one ownership row claims one volume base and enforces it at agent creation. Rename — the only other producer of volume_base_name — is not gated, so it can still mint the collision.
Summary
PR #1666 added agent_ownership.volume_base_name and gated creation on it:
# services/agent_service/crud.py:298
if not config.ephemeral and db.is_volume_base_reserved(config.name):
raise HTTPException(status_code=409, detail="Agent name unavailable: its data volumes still belong to another agent (it was renamed).")db.is_volume_base_reserved has exactly two enforcement call-sites — create (above) and the purge/orphan sweep (cleanup_service.py:855,965). The rename endpoint checks neither the volume base nor anything that stands in for it:
# routers/agent_rename.py:95 — Docker container only
existing = get_agent_container(sanitized_name)
# db/agent_settings/metadata.py:137 — agent_name column only
taken = conn.execute(select(1).where(agent_ownership.c.agent_name == new_name)).first()Neither sees volume_base_name, so renaming into a base another row already claims is permitted.
Component
Backend / Agent Rename (routers/agent_rename.py, db/agent_settings/metadata.py::rename_agent) × the #1664 volume-identity model
Priority
P1 — cross-tenant data exposure of the same class as #1667, but requires a two-rename sequence and is not a regression (pre-#1666 this path was equally ungated, with worse consequences).
Reproduction Steps
An ordinary ops swap is enough:
- Create agent
prod-agent; enable file sharing (createsagent-prod-agent-public). Volumes live under baseprod-agent. - Rename
prod-agent→prod-agent-old. Row:agent_name='prod-agent-old',volume_base_name='prod-agent'. Volumes keep the old base — by design (bug: #1581 orphan-volume sweep can destroy a live renamed agent's home volume (rename keeps old volume name+label) #1664). - Create a new agent named
prod-agent→ 409, correctly refused by the bug: #1581 orphan-volume sweep can destroy a live renamed agent's home volume (rename keeps old volume name+label) #1664 create gate. - Instead, create agent
staging-agent, then renamestaging-agent→prod-agent:get_agent_container('prod-agent')→ None (the container isagent-prod-agent-oldnow) → passes.select(1).where(agent_name == 'prod-agent')→ no row (it'sprod-agent-old) → passes.- Rename succeeds. Row:
agent_name='prod-agent',volume_base_name='staging-agent'.
- Two rows now claim base
prod-agent:prod-agent-oldvia its pin, andprod-agentvia its name. - Enable file sharing on the new
prod-agent→db.get_public_volume_name('prod-agent')→agent-prod-agent-public→volume_getfinds the other agent's public volume → mounted.
Root Cause
The workspace volume is safe: it resolves through the row's own pin (lifecycle._workspace_volume_name). But get_public_volume_name / get_shared_volume_name name off the live agent name by design (db/agent_settings/file_sharing.py:60, db/shared_folders.py:222) — which #1666's is_volume_base_reserved docstring documents as intentional ("a renamed agent still creates new volumes under its CURRENT name … therefore legitimately owns volumes under two bases"). That design is sound only while a base has a single claimant. Rename is the one path that can give it two.
Impact
- Cross-agent, potentially cross-owner disclosure — the new
prod-agentget-then-creates its way onto the old agent'sagent-prod-agent-public; both containers then write the same disk. This is exactly the silent-adopt class bug: agent creation silently reuses a pre-existing Docker volume of the same name (get-then-create, no adopt/refuse decision) #1667 closed on the create path. - Permanent volume leak — once two rows claim the base, the fix(volumes): rename-safe volume identity — sweep, purge, create and recovery (#1664, #1665, #1667) #1666 purge guard skips removal for both (
is_volume_base_reserved(base)stays true after either row is purged), and the orphan sweep never reclaims it for the same reason. The volumes become unreachable and undeletable by any automated path.
PR #1666's purge path already anticipates this collision, but attributes it only to installs predating the create gate:
volume_base_namecarries no unique constraint, and installs predating the create-time gate (crud.py, #1664) can hold a collision: agentnewpinned to baseoldPLUS a live agent literally namedold, both on the same volumes.
Rename can mint it fresh, post-fix. The purge handling is correctly fail-safe (skip, don't destroy), so this is a gap in prevention, not in safety.
Suggested Fix
Mirror the create gate in the rename endpoint, after the existing container/name checks:
# routers/agent_rename.py
if db.is_volume_base_reserved(sanitized_name):
raise HTTPException(
status_code=409,
detail=(
"Name unavailable: its data volumes still belong to another "
"agent (it was renamed). Pick a different name."
),
)Enforcing it inside db.rename_agent's transaction (alongside the existing taken check) would be stronger — it closes the TOCTOU between the router check and the write, and covers any future caller. Either way it needs a regression test named for this issue; tests/unit/test_1664_renamed_agent_volume_safety.py has the fixtures (TestVolumeBaseOwnership) and is the natural home.
Worth considering alongside: a partial unique index on volume_base_name would make the invariant structural rather than checked, but the union semantics (a row claims a base via agent_name or volume_base_name) don't map onto a single-column constraint cleanly.
Related
- bug: #1581 orphan-volume sweep can destroy a live renamed agent's home volume (rename keeps old volume name+label) #1664 / PR fix(volumes): rename-safe volume identity — sweep, purge, create and recovery (#1664, #1665, #1667) #1666 — established
volume_base_name+is_volume_base_reserved; gated create, not rename - bug: agent creation silently reuses a pre-existing Docker volume of the same name (get-then-create, no adopt/refuse decision) #1667 — the same silent-adopt disclosure, closed on the create path
- bug: renamed agent's soft-delete recovery mounts a fresh empty workspace volume (rename keeps the old volume) #1665 — the other rename/volume-identity gap (recovery mounting a fresh empty volume)
- bug: Docker volumes are never deleted — volume_remove has zero callers; agent purge leaks workspace/public/shared volumes forever #1581 — the reclaim sweep whose skip-on-collision turns this into the leak
Activity
fix(agents): gate rename on volume-base ownership — one row per base,…
dolho commentedon Jul 17, 2026
Fixed in #1666 (
74f4a9a7) rather than as a follow-up — will close when that PR merges.Reasoning for pulling it in: you scoped this as a prevention gap, not a safety one, which is accurate, but #1666's own purge guard assumes a single claimant. With two rows on a base,
is_volume_base_reservedstays true after either is purged, so the guard skips both bases and the orphan sweep never reclaims them — the volumes become unreachable and undeletable by any automated path. Shipping the invariant enforced at one of its two producers would have left that guard resting on something the code doesn't guarantee.Implemented your stronger option: enforced inside
db.rename_agent's transaction (chokepoint — closes the check-then-write gap, covers future callers), plus a router gate raised before the container is stopped/renamed, so a refusal leaves nothing half-done and returns an actionable 409 instead of that path's generic 500. That's the #1445 router+chokepoint pattern you were pointing at.One correction to the suggested one-liner — it refuses a legitimate rename-back: an agent created
Band renamed toAkeeps pinB, sois_volume_base_reserved('B')is True via its own row, and renamingA→B(which it owns, single claimant) would be refused and told its own volumes belong to someone else. So the predicate grewexclude_agent— "does anyone else claim this base?" — and rename passes itself.Verified on a real DB, your repro verbatim: the swap is now refused, exactly one row claims base
prodafterwards, andB→A→Bstill works. 5 regression tests inTestRenameIsGatedOnVolumeBase.Re: the partial unique index — agreed it doesn't map cleanly. The claim is
agent_nameORvolume_base_name, so a single-column index can't express it, and materialising the base into every row to make it structural would trade away the zero-backfill property #1664 was built around. Checked-not-structural for now; worth revisiting if a third producer ever appears.fix(volumes): rename-safe volume identity — sweep, purge, create and …
AndriiPasternak31 commentedon Jul 17, 2026
/claim — taking the rename-side gap: the one-row-per-volume-base invariant from #1666 is enforced at create (
is_volume_base_reserved, crud.py:298) but not on rename. Picking this up as part of the open-ticket push; will sync with @dolho on the exact boundary before building.github-actions commentedon Jul 17, 2026
Claimed by @AndriiPasternak31. Label
status-in-progressadded.Next steps:
feature/1671-<short-slug>Fixes #1671feat(agents): editable display label with an immutable slug (ent#181) (…
refactor(agents): the rename becomes a primitive a platform caller ca…