fix: backfill legacy Bedrock AI provider rows and stale model config strings (#26155)#26453
Merged
Conversation
…strings (#26155) Fixes CODAGT-548 Adds two idempotent startup backfills run after `newAPI(): - `BackfillBedrockProviderType`: promotes `ai_providers` rows from `type=anthropic` with Bedrock settings to `type=bedrock`. - `BackfillChatModelConfigProviderStrings`: fixes stale `chat_model_configs.provider = "anthropic"` strings on rows whose linked provider was just promoted. - `UpdateAIProvider` query now also writes the `type` column, so the fix persists on any subsequent PATCH. > 🤖 Generated by Claude with oversight from a human. (cherry picked from commit a4c867f)
Contributor
There was a problem hiding this comment.
Pull request overview
Adds startup backfills to correct legacy AWS Bedrock provider rows that were stored as type=anthropic, and to repair stale chat_model_configs.provider strings that no longer match the provider’s promoted type. It also updates the UpdateAIProvider SQL query to persist provider type changes going forward.
Changes:
- Add startup backfills: promote legacy Bedrock providers to
type=bedrock, then update stalechat_model_configs.providerstrings tobedrock. - Update
UpdateAIProviderto write thetypecolumn, and update call sites to passType. - Add DB, auth, metrics, and mock plumbing plus regression tests (including encrypted-settings coverage in Enterprise).
Reviewed changes
Copilot reviewed 15 out of 18 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| enterprise/dbcrypt/dbcrypt_internal_test.go | Updates dbcrypt tests to populate UpdateAIProviderParams.Type. |
| enterprise/coderd/x/chatd/chatd_test.go | Updates enterprise chatd tests to pass provider Type into UpdateAIProvider. |
| enterprise/coderd/ai_providers_backfill_test.go | Adds enterprise regression test verifying backfill works with encrypted settings. |
| coderd/x/chatd/chatd_test.go | Updates OSS chatd tests to pass provider Type into UpdateAIProvider. |
| coderd/database/queries/chatmodelconfigs.sql | Adds BackfillChatModelConfigProvider SQL update to fix stale provider strings. |
| coderd/database/queries/ai_providers.sql | Updates UpdateAIProvider SQL to also write type. |
| coderd/database/queries.sql.go | Regenerates sqlc output for the updated UpdateAIProvider and new backfill query. |
| coderd/database/querier.go | Extends sqlc querier interface with BackfillChatModelConfigProvider (returns sql.Result). |
| coderd/database/dbmock/dbmock.go | Regenerates mocks to include BackfillChatModelConfigProvider. |
| coderd/database/dbmetrics/querymetrics.go | Adds metrics instrumentation for BackfillChatModelConfigProvider. |
| coderd/database/dbauthz/dbauthz.go | Adds RBAC enforcement wrapper for BackfillChatModelConfigProvider. |
| coderd/database/dbauthz/dbauthz_test.go | Adds RBAC test coverage for the new DB method. |
| coderd/ai_providers.go | Ensures PATCH update path passes existing Type to UpdateAIProvider. |
| coderd/ai_providers_migrate.go | Adjusts env seeding drift detection and legacy Bedrock env behavior to align with type=bedrock. |
| coderd/ai_providers_migrate_test.go | Updates/extends seed tests for the new Bedrock type behavior and idempotency after backfill. |
| coderd/ai_providers_backfill.go | Adds the two startup backfill functions. |
| coderd/ai_providers_backfill_test.go | Adds DB-backed and mocked tests for both backfills and failure paths. |
| cli/server.go | Wires backfills into server startup after newAPI() and env seeding. |
Files not reviewed (3)
- coderd/database/dbmetrics/querymetrics.go: Generated file
- coderd/database/dbmock/dbmock.go: Generated file
- coderd/database/querier.go: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+28
to
+30
| key := make([]byte, 32) | ||
| _, _ = rand.Read(key) | ||
| ciphers, err := dbcrypt.NewCiphers(key) |
Comment on lines
+1032
to
+1034
| // Must run after BackfillBedrockProviderType; shares aibridgeInitCtx so | ||
| // a timeout on the first backfill will skip this one until next startup. | ||
| coderd.BackfillChatModelConfigProviderStrings(aibridgeInitCtx, options.Database, logger.Named("aibridge.backfill")) |
f0ssel
approved these changes
Jun 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes CODAGT-548
Adds two idempotent startup backfills run after `newAPI():
BackfillBedrockProviderType: promotesai_providersrows fromtype=anthropicwith Bedrock settings totype=bedrock.BackfillChatModelConfigProviderStrings: fixes stalechat_model_configs.provider = "anthropic"strings on rows whose linked provider was just promoted.UpdateAIProviderquery now also writes thetypecolumn, so the fix persists on any subsequent PATCH.(cherry picked from commit a4c867f)