WIZ-prereq-B POST /agents/types/{old}/rename — transactional type rename #671

Closed
opened 2026-05-01 19:26:05 +00:00 by claude-desktop · 1 comment
Collaborator

User story

As a platform engineer, I want a single transactional endpoint that atomically rewrites every per-type column reference across the agent-config DB and the in-memory config cache, so renames the wizard or any future operator action triggers cannot leave the system in a half-renamed state.

Acceptance criteria

Endpoint

  • POST /agents/types/{old_name}/rename body { new_name }. Operator-auth-gated.
  • Returns 200 { ok: true, renamed: { old, new, affected_rows: { agents, agent_type_config, skill, system_prompt, plugin_binding, plugin_marketplace, mcp_server } } } on success.
  • Returns 400 when new_name is empty / equals old_name / clashes with an existing type / clashes with a reserved role name (host, code-lead, code, review, design, design-review).
  • Returns 404 when old_name does not exist.
  • Returns 409 when a rename is already in progress for the same source (idempotency).

Transaction

  • One SQLite transaction. Updates: agents.type, agent_type_config.agent_type, skill.agent_type, system_prompt.agent_type, plugin_binding.agent_type, plugin_marketplace.agent_type, mcp_server.agent_type. Returns counts per table.
  • After commit: updates the in-memory config cache + writes config/agents.json on disk. File-write failure logs but does not roll back the DB (DB is source of truth).
  • Posts a config_revision row with kind = "type_rename", name = old_name, body_snapshot = { old_name, new_name, affected_rows }.

Side effects

  • Triggers agent-env-sync.renderForInstance for every instance of the renamed type after commit.
  • Triggers an SSE agent_type_renamed event so dashboard caches invalidate.

Tests

  • Round-trip: create type boss, add 3 agents + 5 skill rows + 2 plugin rows. Rename to tech-lead. Every row reflects the new name; old name returns 404.
  • Idempotency: second rename call with same old/new returns 200 (no-op).
  • Reserved-name check: rename to host returns 400.
  • Clash check: rename boss to dev (existing) returns 400.
  • Atomicity: simulated DB error mid-transaction rolls back; no partial rename observable.

Out of scope

  • Wizard UI (WIZ-1+).
  • Bulk rename of multiple types.

References

  • specs/first-login-wizard.md §Story WIZ-prereq-B
  • specs/agent-config-customization.md — DB schema this rewrites.
  • Depends on WIZ-prereq-A.
## User story As a platform engineer, I want a single transactional endpoint that atomically rewrites every per-type column reference across the agent-config DB and the in-memory config cache, so renames the wizard or any future operator action triggers cannot leave the system in a half-renamed state. ## Acceptance criteria ### Endpoint - [ ] `POST /agents/types/{old_name}/rename` body `{ new_name }`. Operator-auth-gated. - [ ] Returns 200 `{ ok: true, renamed: { old, new, affected_rows: { agents, agent_type_config, skill, system_prompt, plugin_binding, plugin_marketplace, mcp_server } } }` on success. - [ ] Returns 400 when `new_name` is empty / equals `old_name` / clashes with an existing type / clashes with a reserved role name (`host`, `code-lead`, `code`, `review`, `design`, `design-review`). - [ ] Returns 404 when `old_name` does not exist. - [ ] Returns 409 when a rename is already in progress for the same source (idempotency). ### Transaction - [ ] One SQLite transaction. Updates: `agents.type`, `agent_type_config.agent_type`, `skill.agent_type`, `system_prompt.agent_type`, `plugin_binding.agent_type`, `plugin_marketplace.agent_type`, `mcp_server.agent_type`. Returns counts per table. - [ ] After commit: updates the in-memory config cache + writes `config/agents.json` on disk. File-write failure logs but does not roll back the DB (DB is source of truth). - [ ] Posts a `config_revision` row with `kind = "type_rename"`, `name = old_name`, `body_snapshot = { old_name, new_name, affected_rows }`. ### Side effects - [ ] Triggers `agent-env-sync.renderForInstance` for every instance of the renamed type after commit. - [ ] Triggers an SSE `agent_type_renamed` event so dashboard caches invalidate. ### Tests - [ ] Round-trip: create type `boss`, add 3 agents + 5 skill rows + 2 plugin rows. Rename to `tech-lead`. Every row reflects the new name; old name returns 404. - [ ] Idempotency: second rename call with same old/new returns 200 (no-op). - [ ] Reserved-name check: rename to `host` returns 400. - [ ] Clash check: rename `boss` to `dev` (existing) returns 400. - [ ] Atomicity: simulated DB error mid-transaction rolls back; no partial rename observable. ## Out of scope - Wizard UI (WIZ-1+). - Bulk rename of multiple types. ## References - `specs/first-login-wizard.md` §Story WIZ-prereq-B - `specs/agent-config-customization.md` — DB schema this rewrites. - Depends on **WIZ-prereq-A**.
Collaborator

🤖 Auto-assigned to boss (heuristic: area:agents → boss (architecture-touching)). Reply /unassign to reroute.

🤖 Auto-assigned to **boss** (heuristic: area:agents → boss (architecture-touching)). Reply `/unassign` to reroute.
Sign in to join this conversation.
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
charles/claude-hooks#671
No description provided.