Skip to content

fix: resolve model config provider via ai_provider_id#26660

Draft
johnstcn wants to merge 5 commits into
mainfrom
fix/codagt-617-provider-icon-mismatch
Draft

fix: resolve model config provider via ai_provider_id#26660
johnstcn wants to merge 5 commits into
mainfrom
fix/codagt-617-provider-icon-mismatch

Conversation

@johnstcn

@johnstcn johnstcn commented Jun 24, 2026

Copy link
Copy Markdown
Member

The GetChatModelConfigs and GetEnabledChatModelConfigs queries now join ai_providers and use COALESCE(ap.type::text, cmc.provider) AS provider so the provider column reflects the canonical ai_providers.type rather than the stale denormalized text on chat_model_configs.

The provider creation form now sends type=bedrock at creation time instead of type=anthropic with Bedrock settings. Previously, the form relied on the BackfillBedrockProviderType startup backfill to promote the provider type, leaving a window where the provider appeared as Anthropic in all UI surfaces until the next server restart.

Implementation details

Backend (coderd/database/queries/chatmodelconfigs.sql): The two list queries use COALESCE(ap.type::text, cmc.provider) AS provider with a LEFT/INNER JOIN to ai_providers. sqlc still generates []ChatModelConfig as the return type.

Frontend (site/src/pages/AISettingsPage/ProvidersPage/components/providerFormApiMap.ts): providerFormValuesToCreate now returns type: "bedrock" when the form type is bedrock, instead of type: "anthropic" with Bedrock settings. The backend validation already accepts type=bedrock with Bedrock settings and rejects API keys for type=bedrock.

Tests: Updated providerFormApiMap.test.ts to expect type: "bedrock" and MockAIProviderBedrock fixture in entities.ts to type: "bedrock".

Refs: CODAGT-549

The denormalized provider text column on chat_model_configs can mismatch
the provider type of the linked ai_providers row. The list endpoint now
fetches AI providers and overrides the provider field from
ai_providers.type, fixing stale legacy rows.

The Models page icon now uses the provider type resolved through
providerStates (via ai_provider_id) instead of the raw model.provider
text, matching the behavior of the Provider column.

Refs: CODAGT-617
@linear-code

linear-code Bot commented Jun 24, 2026

Copy link
Copy Markdown

CODAGT-549

CODAGT-617

The denormalized provider text column on chat_model_configs can mismatch
the provider type of the linked ai_providers row. The list endpoint now
fetches AI providers and overrides the provider field from
ai_providers.type, fixing stale legacy rows.

The Models page icon now uses the provider type resolved through
providerStates (via ai_provider_id) instead of the raw model.provider
text, matching the behavior of the Provider column.

Refs: CODAGT-617

Copy link
Copy Markdown
Member Author

Deep Review Summary

Ran 3 parallel reviewers (Go Architect, Frontend Reviewer, Test Auditor).

Findings addressed in this push:

  • P2 (Go Architect): Conditional dbauthz context switch (ctx for admin, AsChatd for non-admin) was unnecessary. Simplified to use dbauthz.AsChatd(ctx) unconditionally, matching the pattern in createChatModelConfig and updateChatModelConfig.
  • P3 (Test Auditor): Replaced loop-and-flag pattern with require.Len + direct index, matching the sibling DeserializesLegacyPricingJSON convention.
  • P2 (Test Auditor, null ai_provider_id): Dismissed — the DB has a check constraint chat_model_configs_ai_provider_required_when_active that enforces ai_provider_id is always present for non-deleted rows. The edge case cannot occur in the current schema.

No findings (Frontend Reviewer): 5 observations confirming fixture correctness, fallback soundness, and assertion reliability.

Generated with Coder Agents.

@johnstcn johnstcn changed the title fix(coderd): resolve model config provider via ai_provider_id fix: resolve model config provider via ai_provider_id Jun 24, 2026
johnstcn added 3 commits June 24, 2026 15:41
The GetChatModelConfigs and GetEnabledChatModelConfigs queries now
LEFT/INNER JOIN ai_providers and use COALESCE(ap.type::text, cmc.provider)
so the provider column reflects the canonical ai_providers.type rather than
the stale denormalized text on chat_model_configs.

The Models page icon uses the provider type resolved through providerStates
(via ai_provider_id) instead of the raw model.provider text.

Refs: CODAGT-549
The SQL query already returns COALESCE(ap.type, cmc.provider) as the
provider field, so model.provider on the frontend is correct. The
providerType prop and providerTypeByModelId map were resolving the same
ai_provider_id -> ai_providers.type path server-side, adding duplication.

Refs: CODAGT-549
The provider creation form was sending type=anthropic with Bedrock
settings, relying on the BackfillBedrockProviderType startup backfill
to promote it to type=bedrock. Until the backfill runs (next restart),
the provider appears as Anthropic in all UI surfaces that read
ai_providers.type directly.

Send type=bedrock at creation time so the provider is stored correctly
from the start. The backend validation already accepts type=bedrock
with Bedrock settings.

Refs: CODAGT-549
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