Skip to content

feat: use AI provider chat APIs - #25415

Merged
ibetitsmike merged 1 commit into
mainfrom
mike/ai-providers/frontend-cutover
May 22, 2026
Merged

ibetitsmike merged 1 commit into
mainfrom
mike/ai-providers/frontend-cutover

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented May 16, 2026 •

Copy link
Copy Markdown
Collaborator

Mux working on behalf of Mike.

Stack Context

This stack now starts from main. PR #25412 and PR #25414 were merged into main, so this PR contains only the API, SDK, frontend, and test cutover work.

Active Stack

Order PR Branch Base Scope
1 #25415 mike/ai-providers/frontend-cutover main API and Agents settings UI use AI provider backed data.
2 #25416 mike/ai-providers/legacy-cleanup mike/ai-providers/frontend-cutover Remove legacy chat provider tables and compatibility code.

What?

  • Rewires chat admin and user key APIs to AI provider backed data while keeping the existing Agents UI flow working.
  • Uses the canonical /api/v2/ai/providers REST API and embedded api_keys mutations for admin provider configs.
  • Moves user AI provider key routes to /api/experimental/users/{user}/ai-provider-keys and updates SDK/frontend callers.
  • Requires AI provider IDs when creating model configs and uses provider summaries for rendering.
  • Updates chatd and enterprise chat tests to create concrete AI providers before creating model configs.
  • Requires AI provider base URLs on create and update, with UI defaults or placeholders for known provider types.
  • Enforces leading and trailing whitespace validation for provider-scoped and user BYOK API keys without silently trimming secrets.
  • Uses a narrow AI provider metadata reader actor for user key metadata reads.
  • Batches provider key presence checks to avoid per-provider key lookups.
  • Updates enabled model config queries to include AI provider backed model configs while preserving legacy chat provider configs.
  • Updates the Agents settings UI to select concrete AI provider backed model configs and reflect soft-delete behavior.
  • Adds an Add provider menu so admins can create additional provider instances from the Providers page.

Follow-up

Validation

  • go test ./enterprise/coderd -run 'TestChatStreamRelay|TestChatModelConfigDefault|TestCreateChatNonDefaultOrg|TestListChats_OrgAdminOnlySeesOwnChats' -count=1
  • go test ./coderd/x/chatd -run 'TestResolveUserProviderAPIKeys_AIProvider|TestProviderAPIKeysFromAIProviders|TestSubagentChatExcludesWorkspaceProvisioningTools|TestPlanModeSubagentChatExcludesAskUserQuestion|TestExploreSubagentIsReadOnly|TestCreateWorkspaceTool_EndToEnd|TestStartWorkspaceTool_EndToEnd|TestAgentContextFilesAndSkillsLoadedIntoChat' -count=1
  • make pre-commit

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@ibetitsmike ibetitsmike changed the title feat(site): use AI provider chat APIs feat: use AI provider chat APIs May 16, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ea3c1ab416

ℹ️ 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".

Comment thread site/src/api/queries/chats.ts Resolved
Comment thread site/src/api/queries/chats.ts Resolved
Comment thread site/src/api/queries/chats.ts Resolved

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First-pass review (Netero). This is a mechanical scan; the full review panel has not yet reviewed this PR. 3 P2, 3 P3.

The migration approach is clean: existing query contracts are preserved while the internal implementation switches to AI provider APIs. The Go handler branching for AI-provider-backed vs. legacy configs is straightforward.

The P2 findings are: non-atomic key rotation in the frontend mutation (keys deleted before replacement is confirmed), hardcoded boolean fields that silently swallow UI toggle state, and no Go test coverage for the new validation paths. The P3s cover an N+1 request pattern, stale Storybook spies, and duplicated provider-lookup logic.

These are first-pass findings. The panel will review after they are addressed.

"271 new lines of production code (Go + TS), 3 lines of test changes (story fixture type adjustments)." (Netero)


site/src/pages/AgentsPage/components/ChatModelAdminPanel/ChatModelAdminPanel.stories.tsx:73

P3 [DEREM-5] setupChatSpies still mocks getChatProviderConfigs, createChatProviderConfig, updateChatProviderConfig, deleteChatProviderConfig, but the query functions now call listAIProviders, listAIProviderKeys, createAIProvider, createAIProviderKey, updateAIProvider, deleteAIProvider. The 6 stories using setupChatSpies set up spies that never intercept.

🤖

🤖 This review was automatically generated with Coder Agents.

Comment thread site/src/api/queries/chats.ts Resolved
Comment thread site/src/api/queries/chats.ts Resolved
Comment thread coderd/exp_chats.go Resolved
Comment thread site/src/api/queries/chats.ts Resolved
Comment thread coderd/exp_chats.go Resolved
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

1 similar comment
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round 2 is blocked. The three P2 findings (DEREM-1, DEREM-2, DEREM-3) were addressed. The three remaining P3 findings have no author response and no code changes:

  • DEREM-4 (P3, chats.ts:1614): N+1 HTTP requests in chatProviderConfigs query (1 listAIProviders + N listAIProviderKeys calls). Previous implementation was a single call.
  • DEREM-5 (P3, ChatModelAdminPanel.stories.tsx:73): setupChatSpies still mocks API methods the query functions no longer call. Six stories set up spies that never intercept.
  • DEREM-6 (P3, exp_chats.go:7468): AI provider lookup logic duplicated between createChatModelConfig and updateChatModelConfig.

Further review is blocked until the author responds to or addresses these findings. A response acknowledging, contesting, or deferring each finding is sufficient to unblock.

🤖 This review was automatically generated with Coder Agents.

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round 3 is still blocked. The three P3 findings from round 1 remain without author response across two consecutive blocked rounds:

  • DEREM-4 (P3, chats.ts:1614): N+1 HTTP requests in chatProviderConfigs query.
  • DEREM-5 (P3, ChatModelAdminPanel.stories.tsx:73): setupChatSpies mocks methods the query functions no longer call.
  • DEREM-6 (P3, exp_chats.go:7468): AI provider lookup logic duplicated between create and update handlers.

A brief acknowledgment, contest, or deferral on each finding is sufficient to unblock the full panel review.

🤖 This review was automatically generated with Coder Agents.

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

Mux working on behalf of Mike.

Acknowledging remaining P3s:

  • DEREM-4: Deferring the N+1 key listing. The frontend is adapting to the current API shape, where key summaries are scoped under each AI Provider. This can be optimized with a backend aggregate endpoint after the migration lands.
  • DEREM-5: Deferring story spy cleanup. The extra spies are harmless compatibility scaffolding while this stack still bridges legacy and AI Provider APIs.
  • DEREM-6: Deferring the duplicate AI Provider lookup helper in model config handlers. The duplicated block is small and explicit, and refactoring it now would broaden this frontend PR into API cleanup.

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

1 similar comment
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round 4 first-pass review (Netero). The full review panel has not yet reviewed this PR. 1 P2 (reopened), 1 new P3.

The three P2 findings from R1 were addressed, and the three P3s were acknowledged by the author. However, DEREM-3 is reopened: the tests added in e82b66fb9 and 1a3338cf4 cover AI provider CRUD and subagent resolution, but no test exercises the if req.AIProviderID != nil branch in createChatModelConfig or updateChatModelConfig. The untested paths include: creating a model config linked to an AI provider, rejecting a disabled provider, rejecting a nonexistent provider ID, and the requireChatProviderForModelConfig skip.

New finding: normalizeProviderPolicyDefaults is dead code after this PR removes its only production import.

The panel will review after DEREM-3 is addressed.

"Those commits added TestAIProviderCRUD and subagent resolution tests, but neither exercises the if req.AIProviderID != nil branch in createChatModelConfig or updateChatModelConfig." (Netero)


site/src/pages/AgentsPage/components/ChatModelAdminPanel/providerPolicyDefaults.ts:16

P3 [DEREM-7] normalizeProviderPolicyDefaults was the sole production import from this module (via ProviderForm.tsx), and this PR removes that import. The module and its test file (providerPolicyDefaults.test.ts) are now dead code. Delete both files.

🤖

🤖 This review was automatically generated with Coder Agents.

Comment thread coderd/exp_chats.go Resolved

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round 5 is blocked. Two open findings have no author response:

  • DEREM-3 (P2, exp_chats.go:7494): No tests exercise the AIProviderID branch in createChatModelConfig or updateChatModelConfig. The prior fix (e82b66fb9) covered AI provider CRUD, not the model config handlers.
  • DEREM-7 (P3, providerPolicyDefaults.ts:16): normalizeProviderPolicyDefaults and its test file are dead code after this PR removes the only production import.

A brief acknowledgment, contest, or deferral on each is sufficient to unblock the panel review.

🤖 This review was automatically generated with Coder Agents.

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

1 similar comment
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round 6 is blocked. DEREM-7 (dead code) was addressed by deleting providerPolicyDefaults.ts and its test.

One open finding remains without author response:

  • DEREM-3 (P2, exp_chats.go:7494): No tests exercise the AIProviderID branch in createChatModelConfig or updateChatModelConfig. New test commits since R4 added coverage for AI provider CRUD (input normalization, base URL validation, delete missing, large key) and user key flows (reject disabled provider), but none set AIProviderID on CreateChatModelConfigRequest or UpdateChatModelConfigRequest. The specific model config handler paths remain uncovered.

A brief acknowledgment, contest, or deferral is sufficient to unblock the panel review.

🤖 This review was automatically generated with Coder Agents.

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round 7 is blocked (3rd consecutive blocked round). The sole remaining open finding has no author response:

  • DEREM-3 (P2, exp_chats.go:7494): No tests exercise the AIProviderID branch in createChatModelConfig or updateChatModelConfig. Commits since R4 added AI provider CRUD tests, user key tests, and docs edits, but none set AIProviderID on CreateChatModelConfigRequest or UpdateChatModelConfigRequest.

This finding has been open since R1 (reopened R4) and blocked since R5. A brief acknowledgment, contest, or deferral unblocks the panel.

🤖 This review was automatically generated with Coder Agents.

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round 8 is blocked (4th consecutive). DEREM-3 (P2) remains the sole open finding with no author response since it was reopened in R4.

  • DEREM-3 (P2, exp_chats.go:7494): No tests exercise the AIProviderID branch in createChatModelConfig or updateChatModelConfig.

This has been raised in every review since R4. An acknowledgment, contest, or deferral unblocks the panel.

🤖 This review was automatically generated with Coder Agents.

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

Mux working on behalf of Mike.

Response to the remaining frontend-cutover finding:

  • DEREM-3: fixed in ac2175b05a. Added Go coverage for create and update model-config AIProviderID validation, including happy path, missing provider, and disabled provider cases.

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

7 similar comments
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@ibetitsmike
ibetitsmike force-pushed the mike/ai-providers/frontend-cutover branch from 77974aa to 9548275 Compare May 18, 2026 00:29
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9548275f18

ℹ️ 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".

Comment thread site/src/api/queries/chats.ts Resolved
@ibetitsmike
ibetitsmike force-pushed the mike/ai-providers/frontend-cutover branch from 9548275 to 88405e8 Compare May 18, 2026 00:44
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 88405e8d13

ℹ️ 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".

Comment thread site/src/api/queries/chats.ts Resolved
@ibetitsmike
ibetitsmike force-pushed the mike/ai-providers/frontend-cutover branch from 88405e8 to 43d83ca Compare May 18, 2026 01:25
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 43d83ca9f4

ℹ️ 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".

Comment thread coderd/exp_chats.go Resolved
@ibetitsmike
ibetitsmike force-pushed the mike/ai-providers/frontend-cutover branch from 43d83ca to 0adf570 Compare May 18, 2026 01:44
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0adf570860

ℹ️ 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".

@ibetitsmike
ibetitsmike force-pushed the mike/ai-providers/frontend-cutover branch from 0adf570 to b2fe994 Compare May 18, 2026 02:02
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b2fe99418e

ℹ️ 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".

Comment thread site/src/api/queries/chats.ts Resolved
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

ℹ️ 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".

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

Disclosure: Mux is acting on behalf of Mike to request automated Codex review for the current PR head.

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b5a2ebfff2

ℹ️ 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".

Comment thread site/src/api/queries/chats.ts Resolved
Comment thread coderd/ai_providers_test.go Resolved
Comment thread coderd/coderd.go Resolved
Comment thread coderd/exp_chats.go Resolved
Comment thread coderd/exp_chats.go Resolved
Comment thread coderd/exp_chats.go Resolved
Comment thread coderd/exp_chats.go Resolved
Comment thread coderd/exp_chats.go Resolved
Comment thread coderd/exp_chats.go Resolved
Comment thread coderd/exp_chats.go Resolved
Comment thread coderd/exp_chats.go Resolved
Comment thread coderd/exp_chats.go Resolved
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Full re-review after major restructure (35 files, 4147 diff lines vs 15 files at R12). Prior DEREM-1 through DEREM-14 all closed.

The restructuring does a lot well: the new AsAIProviderMetadataReader actor is correctly scoped to a single read permission, the user AI provider key lifecycle has thorough test coverage (six subtests, full round-trip through the database), the AddProviderFromMenu story exercises the new dropdown-to-form flow end-to-end, and the dead providerPolicyDefaults module was cleanly removed with zero orphaned references. The RBAC, SDK types, and frontend state machine are solid.

One P1 blocker: DEREM-15 (re-raise of DEREM-9). The frontend write path was rewired to ai_providers, but the runtime read path (GetEnabledChatModelConfigs) still INNER JOINs on chat_providers. On fresh deployments or for new provider types, non-admin users see zero models. 10 of 20 reviewers independently identified this. As ryosuke put it: "Like a car with a new fuel line that bypasses the engine."

Severity count: 1 P1. Prior acknowledged findings (DEREM-4, 5, 6, 14) not re-raised.

🤖 This review was automatically generated with Coder Agents.

Comment thread site/src/api/queries/chats.ts Resolved
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

R18 re-review verifies the R17 P1 fix (DEREM-15, ea355175dd). All 3 panelists confirmed the LEFT JOIN on both ai_providers and chat_providers with conditional WHERE correctly routes AI-provider-backed and legacy model configs. The dedicated test (TestGetEnabledChatModelConfigsUsesAIProviders) covers enabled, disabled-provider, disabled-model, and legacy paths against real Postgres.

No new findings.

Across 18 rounds: 15 findings (3 P1, 4 P2, 8 P3). 11 fixed, 4 author-accepted. All closed.

🤖 This review was automatically generated with Coder Agents.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants