-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix(coderd): require bedrock models when seeding providers from env #27868
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -338,6 +338,14 @@ func providersFromEnv(ctx context.Context, cfg codersdk.AIBridgeConfig, logger s | |
| Type: database.AIProviderTypeAnthropic, | ||
| } | ||
| if hasLegacyBedrock { | ||
| // The env vars cannot express a protocol, so a seeded Bedrock | ||
| // provider always uses InvokeModel, which substitutes the | ||
| // configured models into every upstream request. Both options | ||
| // carry defaults, so this only fires when an operator sets one | ||
| // to the empty string. | ||
| if err := validateSeededBedrockModels(bedrock); err != nil { | ||
| return nil, xerrors.Errorf("legacy bedrock provider: %w, set CODER_AI_GATEWAY_BEDROCK_MODEL and CODER_AI_GATEWAY_BEDROCK_SMALL_FAST_MODEL", err) | ||
| } | ||
| dp.Type = database.AIProviderTypeBedrock | ||
| if hasAnthropicKey { | ||
| logger.Warn(ctx, "ignoring legacy Anthropic API key because Bedrock credentials are configured; Bedrock authenticates via access keys or credential chain", | ||
|
|
@@ -407,6 +415,12 @@ func providersFromEnv(ctx context.Context, cfg codersdk.AIBridgeConfig, logger s | |
| ) | ||
| isBedrock = codersdk.IsBedrockConfigured(p.BedrockBaseURL, bedrock) | ||
| if isBedrock { | ||
| // Unlike the legacy CODER_AI_GATEWAY_BEDROCK_* options, the | ||
| // indexed ones carry no defaults, so a provider migrated from | ||
| // legacy to indexed env vars loses its models silently. | ||
| if err := validateSeededBedrockModels(bedrock); err != nil { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2 [CRF-2] The same dead-row-and-404 failure still ships for an indexed Bedrock provider configured with
Confirmed by reading both predicates:
|
||
| return nil, xerrors.Errorf("indexed AI provider %q: %w, set BEDROCK_MODEL and BEDROCK_SMALL_FAST_MODEL on it", name, err) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1 [CRF-1] The remediation this error prints does not repair a Bedrock row that was already seeded without models, so startup goes green while the provider keeps returning 404. (Netero)
I verified both halves of the mechanism independently: This is the population the linked issue describes: indexed env vars have no model defaults, so any existing indexed Bedrock provider configured without
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3 [CRF-4] The indexed error names
Confirmed:
|
||
| } | ||
| dp.Bedrock = &bedrock | ||
| // Always overwrite the generic BaseURL so removing | ||
| // BASE_URL later doesn't trigger drift. Empty is fine: | ||
|
|
@@ -459,3 +473,22 @@ func providersFromEnv(ctx context.Context, cfg codersdk.AIBridgeConfig, logger s | |
| } | ||
| return res, nil | ||
| } | ||
|
|
||
| // validateSeededBedrockModels rejects an env-seeded Bedrock provider | ||
| // that omits the model identifiers. Neither env path can express a | ||
| // protocol, so a seeded provider always uses InvokeModel, which | ||
| // replaces the client's model with the configured one on every | ||
| // request. Without them the provider fails to build and is skipped, | ||
| // leaving every request to it to return a bare 404, so failing here | ||
| // keeps the dead row out of the database. | ||
| func validateSeededBedrockModels(b codersdk.AIProviderBedrockSettings) error { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2 [CRF-3]
Verified: the codersdk validator returns early unless
|
||
| switch { | ||
| case b.Model == "" && b.SmallFastModel == "": | ||
| return xerrors.New("bedrock model and small fast model are required") | ||
| case b.Model == "": | ||
| return xerrors.New("bedrock model is required") | ||
| case b.SmallFastModel == "": | ||
| return xerrors.New("bedrock small fast model is required") | ||
| } | ||
| return nil | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note [CRF-5] The check turns a partially-broken deployment into a deployment that will not boot. (Netero)
Agreed on both counts: consistent with the file's existing behavior, and worth stating in the PR body so whoever rolls this out knows the failure mode changed from one degraded provider to a refused startup. Note only, no change requested.