Skip to content

fix(api): refuse to delete providers, connections and agents that are still used (#434) - #516

Merged
mkluiver merged 1 commit into
mainfrom
fix/434-in-use-deletes
Nov 26, 2026
Merged

mkluiver merged 1 commit into
mainfrom
fix/434-in-use-deletes

Conversation

@mblaauw

@mblaauw mblaauw commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Closes #434.

Summary

Providers, connections and agents are referenced from JSON (agent specs, team
definitions, environment mappings, worker profiles), so no foreign key stopped a
delete: it returned 204 and the dependants failed later at run time with an
unrelated-looking error. Skills and worker profiles already refused.

  • Store: new in_use module with "used by" queries. delete_provider,
    delete_connection and delete_agent lock the row, refuse with the new
    StoreError::InUse while anything refers to it, then delete in the same
    transaction. Providers: agent model, team and step/node model overrides,
    worker profiles. Connections: agent connector bindings, team connectionIds and
    work source, environment mappings, worker profile env mappings. Agents: team
    steps and workflow nodes, worker profile agent scopes (team run history is
    still protected by the team_steps key). The bulk agent delete uses the same
    path, so its preview reports the same conflicts.
  • API: InUse becomes a 409 envelope whose details name each dependant
    (path usedBy). A permanent agent delete records what went with it
    (executions, triggers, tool policies, memory, runtimes, outputs deleted or
    detached) in the audit entry. New GET /api/v1/agents/{id}/delete-impact
    returns usedBy and removes for the confirmation dialog.
  • Web: the agent delete dialogs load the impact first; an agent still in use is
    not offered for deletion (a message names the dependants), otherwise the
    dialog lists what is removed. Provider and connection deletes name the
    dependants when refused.
  • Docs: agents, connections and providers guides; UI test plan.

Testing

  • cargo fmt --check, clippy --workspace --all-targets -D warnings: clean
  • cargo test --workspace --no-fail-fast with a database: 0 failures (189 API integration); new in_use_providers_connections_and_agents_refuse_delete
  • pnpm api:generate --check: passed (new GET /api/v1/agents/{id}/delete-impact)
  • Web: typecheck passed; test 96 passed (2 new in lib/delete-impact.test.ts); pnpm docs:check passed

Not checked in a browser. Provider and connection dialogs show dependants only after the refusal, not before confirming. Connection references from agent bindings, teams and worker profiles are covered by the queries but not by their own tests. Conflicts with #510 in the generated openapi.json/schema.d.ts and api_integration.rs; whichever merges second reruns pnpm api:generate.

🤖 Generated with Claude Code

… still used (#434)

Providers, connections and agents are referenced from JSON (agent specs, team
definitions, environment mappings, worker profiles), so no foreign key stopped a
delete: it returned 204 and the dependants failed later at run time with an
unrelated-looking error. Skills and worker profiles already refused.

- Store: new `in_use` module with "used by" queries. `delete_provider`,
  `delete_connection` and `delete_agent` lock the row, refuse with the new
  `StoreError::InUse` while anything refers to it, then delete in the same
  transaction. Providers: agent model, team and step/node model overrides,
  worker profiles. Connections: agent connector bindings, team connectionIds and
  work source, environment mappings, worker profile env mappings. Agents: team
  steps and workflow nodes, worker profile agent scopes (team run history is
  still protected by the team_steps key). The bulk agent delete uses the same
  path, so its preview reports the same conflicts.
- API: `InUse` becomes a 409 envelope whose `details` name each dependant
  (path `usedBy`). A permanent agent delete records what went with it
  (executions, triggers, tool policies, memory, runtimes, outputs deleted or
  detached) in the audit entry. New `GET /api/v1/agents/{id}/delete-impact`
  returns `usedBy` and `removes` for the confirmation dialog.
- Web: the agent delete dialogs load the impact first; an agent still in use is
  not offered for deletion (a message names the dependants), otherwise the
  dialog lists what is removed. Provider and connection deletes name the
  dependants when refused.
- Docs: agents, connections and providers guides; UI test plan.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mkluiver
mkluiver merged commit 8a52a92 into main Nov 26, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deleting a provider, connection or agent that is still in use succeeds and leaves dangling references

2 participants