Files
coder/coderd
Michael Suchacz 08a10228db refactor(coderd/x/chatd): inline the model config provider identity (#31000)
This PR deletes `modelConfigProviderIdentity` and its test table; both
callers now use `AIProviderID.UUID.String()` directly. The helper fell
back to the provider type name for model configs without an
`ai_provider_id`. It changes no behavior, because no such config reaches
either caller: the `chat_model_configs_ai_provider_required_when_active`
check constraint allows a NULL `ai_provider_id` only on deleted configs,
and both callers reject such a config before they read the identity.

- Turn preparation resolves the chat's config through
`gatewayProviderForConfig`, which returns "AI Gateway routing requires
AI provider metadata" for a config without a provider ID.
- History sanitization resolves each row's origin config through
`resolveNormalizedProviderForModelConfig`, which returns
`sql.ErrNoRows`. The sanitizer treats that origin as unavailable and
strips the row's provider-specific state (fail closed), as before.

**Why it is safe**

The deleted table tested the helper. Its live contract is that identity
is the provider instance UUID, so two providers of the same type are
distinct. I mutated the two inlined lines and ran `./coderd/x/chatd/`
with `go test -overlay`. The tests catch all three mutants:

- Turn target identity set to the provider type:
`TestActiveServer_AnthropicProviderToolPreRequestGuard`,
`TestOpenAIResponsesFullReplayPairsReasoningAndWebSearch` and others
fail.
- Origin identity set to the normalized type: the same tests fail.
- Both sites set to the type, so they agree:
`TestOpenAIResponsesReasoningNotReplayedAfterModelConfigChange/ProviderMoved`
and `TestProviderSwitchSanitizesAndRestoresPEToolHistory` fail.

`git grep modelConfigProviderIdentity` finds no references left in the
repository, including `site/`, `enterprise/`, `cli/` and `docs/`.

**Review focus**

`sanitizeForeignProviderStateRows` now discards the normalized provider
name that `resolveModelConfigAndNormalizedProvider` returns. It still
calls that function, because the function also checks that the config is
enabled and its provider is valid.

**Validation**

- `go test ./coderd/x/chatd/ -count=1 -p 4 -parallel 4`: ok
- `go vet ./coderd/x/chatd/` and `golangci-lint run --fix=false
./coderd/x/chatd/...`: clean
- pre-commit hook: passed

**Stack**

This stack retires chatd compatibility paths for chat data that older
Coder versions stored.

1. #30996 stamp chat message fixtures with the current content version
2. #30997 drop tests of the legacy content codec
3. #30998 retire the V0 chat message content decoder
4. #31000 inline the model config provider identity (this PR)
5. #31005 retire the `close_agent` tool alias

> Xum, an AI agent, opened this PR for @ibetitsmike and wrote this
description.
2026-10-30 01:30:11 +00:00
..