-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix: require bedrock model fields for the invoke-model protocol #27846
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 |
|---|---|---|
|
|
@@ -285,6 +285,7 @@ func (req CreateAIProviderRequest) Validate() []ValidationError { | |
| }) | ||
| } | ||
| validations = append(validations, validateAIProviderBedrockMantleRegion(*req.Settings.Bedrock)...) | ||
| validations = append(validations, validateAIProviderBedrockModels(*req.Settings.Bedrock)...) | ||
| } | ||
| if req.Type == AIProviderTypeCopilot && len(req.APIKeys) > 0 { | ||
| validations = append(validations, ValidationError{ | ||
|
|
@@ -335,10 +336,17 @@ func (req UpdateAIProviderRequest) Validate() []ValidationError { | |
| if req.APIKeys != nil { | ||
| validations = append(validations, validateAIProviderKeyMutations(*req.APIKeys)...) | ||
| } | ||
| // Despite arriving on a PATCH, a bedrock settings blob is a full | ||
| // replacement rather than a per-field patch: the caller must set every | ||
| // field, except AccessKey, AccessKeySecret, and ExternalID, which | ||
| // mergeAIProviderSettings carries forward from the stored row when | ||
| // omitted. Omitting any other field clears it, so the checks below apply | ||
| // to the patch exactly as they would to what gets stored. | ||
| if req.Settings != nil && req.Settings.Bedrock != nil { | ||
| validations = append(validations, validateAIProviderRoleARN(req.Settings.Bedrock.RoleARN)...) | ||
| validations = append(validations, validateAIProviderBedrockProtocol(req.Settings.Bedrock.Protocol)...) | ||
| validations = append(validations, validateAIProviderBedrockMantleRegion(*req.Settings.Bedrock)...) | ||
| validations = append(validations, validateAIProviderBedrockModels(*req.Settings.Bedrock)...) | ||
| } | ||
| return validations | ||
| } | ||
|
|
@@ -385,6 +393,32 @@ func validateAIProviderBedrockMantleRegion(b AIProviderBedrockSettings) []Valida | |
| return nil | ||
| } | ||
|
|
||
| // validateAIProviderBedrockModels requires the model identifiers that the | ||
|
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. Note [CRF-5] Existing rows that already carry the broken shape are unaffected by this PR. (Netero)
Recorded, not a request to change this PR. Whether AIGOV-564 is closed for deployments already in the broken state, and whether that needs a backfill or a surfaced provider-build status, is a human call. Say which one you intend, here or in the issue.
|
||
| // invoke-model protocol substitutes into every upstream request. Without them | ||
| // the provider cannot be constructed at runtime (see | ||
| // config.AWSBedrock.Validate), so it would be skipped at gateway startup and | ||
| // every request to it would 404. The mantle protocol forwards the client's | ||
| // model unchanged and needs neither field. | ||
| func validateAIProviderBedrockModels(b AIProviderBedrockSettings) []ValidationError { | ||
| if b.ResolvedProtocol() != AIProviderBedrockProtocolInvokeModel { | ||
|
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-2] The models gate fires on any non-nil bedrock blob, including one that is not a Bedrock provider at all, so a bearer-token Anthropic create carrying
The error names fields the caller has no reason to set. There is a second consequence on the PATCH path: One correction to the reviewer's proposed fix. Not reachable from the UI:
|
||
| return nil | ||
| } | ||
| var validations []ValidationError | ||
| if b.Model == "" { | ||
| validations = append(validations, ValidationError{ | ||
| Field: "settings.model", | ||
| Detail: "model is required for the invoke-model protocol", | ||
| }) | ||
| } | ||
| if b.SmallFastModel == "" { | ||
| validations = append(validations, ValidationError{ | ||
| Field: "settings.small_fast_model", | ||
| Detail: "small_fast_model is required for the invoke-model protocol", | ||
| }) | ||
| } | ||
| return validations | ||
| } | ||
|
|
||
| func validateAIProviderRoleARN(roleARN string) []ValidationError { | ||
| if roleARN == "" { | ||
| return nil | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,13 +76,9 @@ func (b AIProviderBedrockSettings) ResolvedProtocol() AIProviderBedrockProtocol | |
| // indicating that the operator wants the provider to authenticate via | ||
| // AWS Bedrock rather than as a bearer-token Anthropic provider. | ||
| // | ||
| // Model and SmallFastModel are intentionally excluded: they have | ||
|
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 PR deletes the rationale for why
Confirmed both default declarations are still present at those lines. This PR makes the models required at the API, which is exactly the change that invites a reader to also add them to
|
||
| // deployment-level defaults declared in codersdk/deployment.go, so | ||
| // they're always non-empty in a real deployment and cannot serve as | ||
| // a detection signal. Region and credentials have no defaults and | ||
| // therefore reliably indicate operator intent. Credentials alone are | ||
| // not required because Bedrock can also authenticate via the AWS | ||
| // environment (instance profile, AWS_PROFILE, IRSA, etc.). | ||
| // Region and credentials have no defaults and therefore reliably indicate | ||
| // operator intent. Credentials alone are not required because Bedrock can | ||
| // also authenticate via the AWS environment (instance profile, AWS_PROFILE, IRSA, etc.). | ||
| func (b AIProviderBedrockSettings) IsConfigured() bool { | ||
| if b.Region != "" { | ||
| return true | ||
|
|
||
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.
P3 [CRF-3] The comment claims the rejected PATCH left the stored provider untouched, but no assertion can show that; the check passes either way. (Netero)
A comment asserting coverage that does not exist is worse than no comment: the next reader trusts it and does not add the assertion. Either read the provider back between the rejected and the accepted PATCH and assert
Region == "us-east-2"with both models at their created values, or drop the second clause of the comment.