Skip to content

fix(v6.51.3): AI providers can be deleted after they have been used (ADR-255) - #309

Merged
cgbarlow merged 1 commit into
mainfrom
fix/delete-used-ai-provider
Sep 27, 2026
Merged

cgbarlow merged 1 commit into
mainfrom
fix/delete-used-ai-provider

Conversation

@cgbarlow

Copy link
Copy Markdown
Owner

Problem

On UAT, deleting any non-default AI provider from Admin → Settings → AI showed "Delete failed". The browser console reported a CORS error, but the Render logs show the real cause:

asyncpg.exceptions.ForeignKeyViolationError: update or delete on table "ai_providers" violates foreign key constraint "ai_conversations_provider_id_fkey" on table "ai_conversations"

ai_conversations.provider_id and ai_usage_log.provider_id reference ai_providers(id) with no ON DELETE action, so a provider that had ever answered a question couldn't be deleted. The endpoint returned an unhandled 500, and because that error skips the CORS middleware, the browser reported it as a CORS error.

Fix

service.delete_provider sets provider_id = NULL on the referencing ai_conversations and ai_usage_log rows, then deletes the provider, all in one commit. History is kept, and each row still records its model name. The default provider still can't be deleted, as before. No schema change; API, MCP and CLI are unchanged, so surface parity is unaffected.

Docs

  • ADR-255: docs/adrs/ADR-255-Delete-Used-AI-Provider.md
  • SPEC-255-A: docs/adrs/specs/SPEC-255-A-Delete-Used-AI-Provider.md
  • CHANGELOG entry for 6.51.3, with the version bumped in backend, mcp, iris-client and frontend

Tests

  • New test_delete_provider_that_has_been_used (with PRAGMA foreign_keys=ON). Written first, it failed with the same FK IntegrityError as production, and it passes with the fix.
  • backend/tests/test_ai: 232 passed
  • scripts/check_surface_parity.py: passes

🤖 Generated with Claude Code

https://claude.ai/code/session_01EbTwcTX1wKVooS7oWd7cP9

…ADR-255)

Deleting a provider referenced by ai_conversations or ai_usage_log hit a
foreign-key violation and returned an unhandled 500 (shown in the browser as
a CORS error). delete_provider now clears provider_id on those rows before
deleting, keeping conversation history and usage logs.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01EbTwcTX1wKVooS7oWd7cP9
@cgbarlow
cgbarlow merged commit 1e1ce2e into main Sep 27, 2026
1 check 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.

1 participant