From ab3337ced8986c46735960798b994e03352c8ac9 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 14 Jun 2026 14:24:18 +0100 Subject: [PATCH] fix: stale numbers and slug reassignments --- application/api/user/agents/portability.py | 5 +++++ application/storage/db/models.py | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/application/api/user/agents/portability.py b/application/api/user/agents/portability.py index 55461a4d..00586893 100644 --- a/application/api/user/agents/portability.py +++ b/application/api/user/agents/portability.py @@ -751,6 +751,11 @@ def apply_import(conn, user: str, doc: dict, resolution: Optional[dict] = None) agents_repo = AgentsRepository(conn) is_update = bool(target.get("action") == "update" and target.get("agent_id")) exclude_id = str(target["agent_id"]) if is_update else None + # Slug is recomputed from the file, not preserved from the matched row: + # a round-tripped export carries metadata.slug so it stays stable, but an + # update-by-id whose file omits the slug and renames the agent rewrites the + # slug to follow the new name (excluding the row's own slug from collision + # checks). Intended — the slug tracks the file. slug = _unique_slug(agents_repo, user, metadata.get("slug") or spec.get("name"), exclude_id=exclude_id) try: diff --git a/application/storage/db/models.py b/application/storage/db/models.py index 7b6d4bb3..5061c2d8 100644 --- a/application/storage/db/models.py +++ b/application/storage/db/models.py @@ -207,7 +207,7 @@ agents_table = Table( Column("key", CITEXT, unique=True), # Stable per-user human identifier used to match an agent across # YAML export/import (idempotent re-import / GitOps). Uniqueness is - # enforced by a partial unique index in migration 0018, not here, so + # enforced by a partial unique index in migration 0019, not here, so # multiple agents may carry NULL. Column("slug", CITEXT), Column("image", Text), @@ -238,7 +238,7 @@ agents_table = Table( ) # Per-user uniqueness of the export/import slug. Mirrors the partial unique -# index created in migration 0018 so a schema built from this metadata +# index created in migration 0019 so a schema built from this metadata # (e.g. create_all) matches an Alembic-built one. Index( "ix_agents_user_slug",