Repository navigation
fix(coderd): allow deleting chat providers used in historical chats - #24568
Conversation
Drop the chat_model_configs.provider -> chat_providers.provider foreign key and soft-delete model configs when their provider is removed. The provider row is now hard-deleted inside a transaction that also tombstones its model configs and promotes a replacement default when needed. Historical chats and messages keep pointing at the soft-deleted model config rows, which are hidden from live/admin queries but still resolve for read. The runtime chat path already falls back to the default model config when a soft-deleted config is looked up. Replaces the lost FK validation in the create/update model-config handlers with an explicit provider lookup that returns the existing `Chat provider is not configured.` 400. Closes CODAGT-23
b424bed to
3c22da5
Compare
ethanndickson
left a comment
There was a problem hiding this comment.
Nice fix. Dropping the FK and pairing FOR UPDATE on the provider row with an explicit requireChatProviderForModelConfig check is the right shape: the create/delete race is serialized, the runtime chatd fallback already absorbs the soft-delete, and replacing database.IsForeignKeyViolation(err) with the errChatProviderNotConfigured sentinel tightens error classification.
One P0 merge-blocker (missing dbauthz test entries, CI is already failing on it), four P2s worth looking at (lock class, invariant-moved-to-handler, inlined cascade, test coverage gap), a few P3s, and nits across 9 inline comments. This review contains findings that may need attention before merge.
Add the missing dbauthz method-suite coverage for the three new chat provider wrapper methods so the accounting test reflects their RBAC contracts and CI can pass again. Map sql.ErrNoRows from updateChatModelConfig's transaction to 404 instead of leaking a 500 when the target row disappears mid-update. Add coverage for deleting the only provider when its sole default model config is historically referenced, and document the rollback migration's stub-provider backfill assumptions.
|
@codex review |
ethanndickson
left a comment
There was a problem hiding this comment.
Thanks for turning the round-1 findings around quickly. Verified: the three TestMethodTestSuite entries, SuccessWithHistoricalChatsAndNoReplacementConfig, the rollback comment, and the sql.ErrNoRows → 404 mapping in updateChatModelConfig all do what they claim, and the new failNextUpdateChatModelConfigStore is the correct shape for intercepting an in-tx method.
Fresh review found one P3 and a few nits across 5 inline comments.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cb4b9d76d9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
|
Codex Review: Didn't find any major issues. Swish! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Drop the
chat_model_configs.provider -> chat_providers.providerforeign key and soft-delete model configs when their provider is removed. The provider row is now hard-deleted inside a transaction that also tombstones its model configs and promotes a replacement default when needed.Historical chats and messages keep pointing at the soft-deleted model config rows, which are hidden from live/admin queries but still resolve for read. The runtime chat path already falls back to the default model config when a soft-deleted config is looked up.
Replaces the lost FK validation in the create/update model-config handlers with an explicit provider lookup that returns the existing
Chat provider is not configured.400.UX
Admin deleting a chat provider that has historical usage
Provider models are still referenced by existing chats.Admins had no in-product way to remove a provider that had ever been used.ensureDefaultChatModelConfigpicks the first live config byprovider ASC, model ASC, updated_at DESC, id DESC); there is no picker, and no toast or response detail names which config became the new default.End users with chats that used a deleted provider's model
no default chat model config is available.Admin creating or updating a model config against a provider that is not configured
Chat provider is not configured.Only the detection mechanism changed (explicitFOR UPDATElookup inside the transaction, which also serializes against a concurrent provider delete).Admin updating a model config whose row disappears mid-transaction
Resource not found or you do not have access to this resourceinstead of the previous 500 that leakedsql: no rows in result setin the detail. Unrelated internal races (for example a race on the promoted default candidate) are still reported as 500 so they are not misclassified as "your target is gone".Closes CODAGT-23