Skip to content

review fixes + refactoring for 26035#26121

Open
johnstcn wants to merge 11 commits into
mike/bedrock-config-ds37from
cj/mike/bedrock-config-ds37
Open

review fixes + refactoring for 26035#26121
johnstcn wants to merge 11 commits into
mike/bedrock-config-ds37from
cj/mike/bedrock-config-ds37

Conversation

@johnstcn
Copy link
Copy Markdown
Member

@johnstcn johnstcn commented Jun 5, 2026

No description provided.

@johnstcn johnstcn self-assigned this Jun 5, 2026
@johnstcn
Copy link
Copy Markdown
Member Author

johnstcn commented Jun 5, 2026

/coder-agents-review

@coder-agents-review
Copy link
Copy Markdown
Contributor

coder-agents-review Bot commented Jun 5, 2026

Chat: Review in progress | View chat
Requested: 2026-06-08 10:49 UTC by @johnstcn
Spend: $55.89 / $100.00

deep-review v0.7.1 | Round 3 | 3b7ca8b..06fdfc0

Last posted: Round 3, 9 findings (1 P2, 3 P3, 5 Nit), APPROVE. Review

Finding inventory

Findings

# Sev Status Location Summary Round Reviewer Posted
CRF-1 P2 Author fixed (97c75d5) ai_providers_migrate.go:150 Error message references dp.Name when loading keys for existing.ID R1 Leorio P2, Razor P3 Yes
CRF-2 P3 Author contested; panel closed R2 (7/7 accept) chatd.go:8661 Best-effort fallback pattern duplicated across 4 call sites R1 Meruem P3, Zoro P3 Yes
CRF-3 P3 Author fixed (97c75d5) chatd_internal_test.go:367 require.Error too broad, does not pin to specific error path R1 Chopper Yes
CRF-4 Nit Author fixed (97c75d5) chatd_internal_test.go:375 Comment bloat: 3 sentences where 1 delivers the intent R1 Gon Yes
CRF-5 Nit Author fixed (97c75d5) subagent_internal_test.go:3668 Comment first sentence restates test name R1 Gon Yes
CRF-6 Nit Author fixed (97c75d5) ai_providers_migrate.go:111 existingDType/candidateDType naming cryptic R1 Gon Yes
CRF-7 Nit Author fixed (97c75d5) ai_provider_canonical.go:13 database.AiProviderType* constants not migrated to codersdk.* R1 Kite, Knov, Meruem, Ryosuke, Razor Yes
CRF-8 P3 Dropped by orchestrator (intentional design confirmed by 4+ reviewers) model_routing_direct.go:104 directProviderHintAndProviderForConfig hard-errors vs sibling fallback R1 Kite No
CRF-9 P3 Author fixed (40c0d0b) model_routing_aibridge.go:173 newAIGatewayModel re-canonicalizes when route.ModelProviderHint already carries the value R2 Chopper Yes
CRF-10 Nit Open model_routing_aibridge.go:36 canonicalizedProvider comment overstates immutability guarantee R3 Mafuuu Yes

Contested and acknowledged

CRF-2 (P3, chatd.go:8661) - Best-effort fallback pattern duplicated across 4 call sites

  • Finding: Reviewer proposed consolidating the 4-line warn+fallback block into a helper to avoid lockstep updates.
  • Author defense: Differentiated each warn site with a unique message ("for direct route", "for AI gateway route", etc.) for log attributability. A helper would flatten all sites back to the same message or require a parameter, reducing consolidation value.
  • Panel closure (R2, 7/7): All 7 reviewers accepted the defense. Meruem (original raiser) confirmed "no new evidence to re-raise." Chopper verified the messages address the diagnostic concern. Knov traced three distinct error-handling modes across call sites that a helper would blur.

Round log

Round 1

Panel. 1 P2, 2 P3, 4 Nit. 1 dropped. Reviewed against 3b7ca8b..a3bb9f5.

Round 2

Churn guard: PROCEED. 7/7 addressed. CRF-2 contested, panel closed 7/7. 1 new P3 (CRF-9). Reviewed against 3b7ca8b..97c75d5.

Round 3

Churn guard: PROCEED. CRF-9 addressed with canonicalizedProvider struct. 1 new Nit (CRF-10). Reviewed against 3b7ca8b..06fdfc0.

About deep-review

CRF = Coder Review Finding (P0-P4, Nit, Note)

Reviewer Focus
Bisky tests
Chopper ops/errors
Churn-guard change verification
Ging language modernization
Gon naming
Hisoka edge cases
Killua perf
Kite change integrity
Knov contracts
Knuckle SQL
Kurapika security
Law decomposition
Leorio docs
Luffy product
Mafu-san process
Mafuuu contracts
Melody dispatch/pairing
Meruem structural
Nami frontend
Netero mechanical checks
Pariston premise testing
Pen-botter product gaps
Razor verification
Robin duplication
Ryosuke Go arch
Takumi concurrency
Zoro shape

🤖 Managed by Coder Agents.

Copy link
Copy Markdown
Contributor

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

Choose a reason for hiding this comment

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

Clean refactoring that removes six wrapper functions across two packages, changes db2sdk.CanonicalAIProviderType to return codersdk.AIProviderType (the right layer for a runtime concept), eliminates double-canonicalization in resolveAIGatewayRoute, and fixes a genuine bug in error reporting at ai_providers_migrate.go:144.

The test coverage is strong: 74.5% test density, every new error path is covered, and the TestEnabledProviderContainsName table-driven suite exercises 8 distinct code paths through the canonical/raw-type fallback logic.

1 P2, 2 P3, 4 Nit.

The P2 is a missed sibling of the bug fix the PR itself introduced: dp.Name at line 150 should be existing.Name, same as the fix at line 144. The P3s cover a test assertion that could be sharper and a question about whether the inlined best-effort fallback pattern (4 identical copies) should be re-consolidated.

"Boring code. Well-structured refactoring. The wrappers added nothing but indirection, and removing them reveals the actual data flow." (Hisoka)


coderd/ai_providers_migrate.go:150

P2 [CRF-1] The PR fixed the same class of bug at line 144 (dp.Nameexisting.Name), but this adjacent error was missed. GetAIProviderKeysByProviderID loads keys for existing.ID, but the error reports dp.Name. When the Bedrock candidate loop (lines 119-131) reassigns existing to a row found via byName["anthropic"], existing.Name differs from dp.Name, misdirecting an operator debugging a key-loading failure.

The PR correctly fixed the sibling at line 144, but the adjacent error on line 150 was missed. In the Bedrock migration path, existing can be set to a candidate found via byName[aibridge.ProviderAnthropic], so existing.Name may differ from dp.Name. (Leorio P2, Razor P3)

Fix: dp.Nameexisting.Name.

🤖

🤖 This review was automatically generated with Coder Agents.

Comment thread coderd/x/chatd/chatd.go
Comment thread coderd/x/chatd/chatd_internal_test.go Outdated
Comment thread coderd/x/chatd/chatd_internal_test.go Outdated
Comment thread coderd/x/chatd/subagent_internal_test.go Outdated
Comment thread coderd/ai_providers_migrate.go Outdated
Comment thread coderd/x/chatd/ai_provider_canonical.go
@johnstcn
Copy link
Copy Markdown
Member Author

johnstcn commented Jun 8, 2026

CRF-1 (P2): Fixed — existing.Name at line 150, same as the line 144 fix.

@johnstcn
Copy link
Copy Markdown
Member Author

johnstcn commented Jun 8, 2026

/coder-agents-review

Copy link
Copy Markdown
Contributor

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

Choose a reason for hiding this comment

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

Round 2. All R1 findings addressed.

CRF-1 (P2, dp.Name bug): fixed. CRF-3 (P3, require.Error): fixed with ErrorContains. CRF-4, CRF-5, CRF-6, CRF-7 (Nits): all fixed.

CRF-2 (P3, best-effort fallback duplication): panel unanimously accepts the author's defense (7/7). The differentiated warn messages ("for provider config", "for direct route", "for AI gateway route", etc.) address the diagnostic concern. The call sites serve three distinct error-handling modes (best-effort, skip, hard-error) that a unified helper would blur. Closed.

1 new P3.

"I tried to build a case against this change and could not. The problem is correctly understood across all four framings." (Pariston)

🤖 This review was automatically generated with Coder Agents.

Comment thread coderd/x/chatd/model_routing_aibridge.go Outdated
@johnstcn
Copy link
Copy Markdown
Member Author

johnstcn commented Jun 8, 2026

/coder-agents-review

Copy link
Copy Markdown
Contributor

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

Choose a reason for hiding this comment

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

Round 3. All prior findings resolved.

CRF-9 (P3, re-canonicalization in newAIGatewayModel): fixed. The author went further than suggested, introducing a canonicalizedProvider struct that pairs the database row with its pre-computed canonical type. This makes re-canonicalization structurally impossible. Clean design.

1 new Nit (comment wording).

"I tried to build a case against this change. The premises hold. The problem is correctly understood, the solution is proportional, and the fix is at the right causal level." (Pariston)

🤖 This review was automatically generated with Coder Agents.

Comment thread coderd/x/chatd/model_routing_aibridge.go Outdated
@johnstcn johnstcn marked this pull request as ready for review June 8, 2026 14:06
Copilot AI review requested due to automatic review settings June 8, 2026 14:06
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors AI provider “canonical type” handling across chatd routing and related API conversion paths, standardizing on db2sdk.CanonicalAIProviderType (now returning codersdk.AIProviderType) and adding tests around Bedrock/Anthropic legacy settings and malformed provider settings.

Changes:

  • Switch canonical provider type derivation to db2sdk.CanonicalAIProviderType across chatd routing/config codepaths, with consistent warn-and-fallback behavior for malformed settings in most cases.
  • Refactor AI Gateway routing to carry a pre-computed canonical provider type (canonicalizedProvider) rather than re-deriving it at each use site.
  • Add/adjust internal tests to cover canonical Bedrock behavior, malformed settings fallbacks, and provider-name/type matching.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
coderd/x/chatd/subagent.go Uses db2sdk.CanonicalAIProviderType when resolving model configs/providers; improves warning message specificity.
coderd/x/chatd/subagent_internal_test.go Adds table-driven coverage for enabledProviderContainsName including malformed settings and Bedrock/Anthropic legacy behavior.
coderd/x/chatd/model_routing.go Adjusts AI Gateway provider hint storage to use canonicalizedProvider.CanonicalType.
coderd/x/chatd/model_routing_internal_test.go Updates route construction and provider-type mapping tests to use codersdk.AIProviderType.
coderd/x/chatd/model_routing_direct.go Canonicalizes provider type for direct routes via db2sdk, with fallback logging; makes config-by-ID canonicalization strict.
coderd/x/chatd/model_routing_aibridge.go Introduces canonicalizedProvider and switches AI Gateway routing/model construction to use precomputed canonical provider type.
coderd/x/chatd/chatd.go Standardizes provider canonicalization in provider config + key resolution; adjusts fallback behavior for malformed settings.
coderd/x/chatd/chatd_internal_test.go Adds tests for canonical Bedrock routing and malformed settings behavior in direct/AIGateway/config paths.
coderd/x/chatd/ai_provider_canonical.go Simplifies canonical/raw match helpers to rely on db2sdk.CanonicalAIProviderType and codersdk constants.
coderd/exp_chats.go Switches AI provider summary/config conversion to use db2sdk.CanonicalAIProviderType returning codersdk.AIProviderType.
coderd/database/db2sdk/db2sdk.go Changes CanonicalAIProviderType to return codersdk.AIProviderType directly.
coderd/database/db2sdk/db2sdk_test.go Updates expectations for new return type from CanonicalAIProviderType.
coderd/ai_providers.go Inlines canonicalization conversion where helper was removed.
coderd/ai_providers_migrate.go Updates canonicalization usage and fixes error messages to reference the correct provider name.
coderd/ai_provider_canonical.go Removes now-redundant canonicalization helpers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 67 to 73
func (r resolvedModelRoute) withProviderHint(providerHint string) resolvedModelRoute {
switch r.kind {
case modelRouteKindDirect:
r.direct.ProviderHint = providerHint
case modelRouteKindAIGateway:
r.aiGateway.ModelProviderHint = providerHint
r.aiGateway.Provider.CanonicalType = codersdk.AIProviderType(providerHint)
}
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.

2 participants