Send no model identifier for a pin AI Gateway no longer lists
What does this MR do and why?
This makes Rails send no model identifier in the agent platform model metadata when a namespace or an instance pins a model that AI Gateway no longer lists for the feature. AI Gateway then serves the feature's default model.
A pin stays in the database after AI Gateway removes the model from a feature. For example, AI Gateway removed Claude Sonnet 4.5 from Code Review (review_merge_request_dap) on 2026-08-24 (merge request), because its context window is too small for the review prompt. Some GitLab.com namespaces had pinned it, and they still send identifier: "claude_sonnet_4_5_20250929" with every Code Review run:
- AI Gateway serves the model anyway today, so large reviews can fail with
prompt is too long. - AI Gateway now checks client model metadata against the allowlist of the feature, and it logs these requests as
model_not_allowed(docs). In itsenforcemode it would reject them, so Code Review would stop working for these namespaces.
The check uses the model definitions that Rails already fetches from AI Gateway (Ai::ModelSelection::ModelDefinitions, cached for 30 minutes):
- A pin is kept when it is a default, selectable, beta or developer model of the feature (
ModelDefinitionResponseParser#listed_model_refs_for_feature). Developer models count because GitLab team members can pin them, and AI Gateway accepts them. - A pin is also kept when the definitions are not available (for eg, with an offline license, or when the request to AI Gateway fails), or when they do not have the feature. This is the same behavior as today.
- Settings on the GitLab default model don't fetch the definitions.
Both places that build this header change: the /ws connection (DuoAgentPlatformModelMetadataService) and the flows that run on CI runners (StartWorkflowService). They now pass the user, because the definitions differ by user when ai_model_release is on.
References
- Closes https://gitlab.com/gitlab-org/gitlab/-/work_items/635719
- Removal of Claude Sonnet 4.5 from Code Review in AI Gateway: gitlab-org/modelops/applied-ml/code-suggestions/ai-assist!6621 (merged)
- Feature allowlist in AI Gateway: https://gitlab.com/gitlab-org/modelops/applied-ml/code-suggestions/ai-assist/-/blob/main/docs/model_selection.md#feature-allowlist-for-gitlab-managed-models
- https://gitlab.com/groups/gitlab-org/-/work_items/23726
Screenshots or screen recordings
Not applicable, this has no UI change.
How to set up and validate locally
-
Make sure your GDK AI Gateway is running.
-
Start a Rails console that reads the model definitions from your local AI Gateway:
FETCH_MODEL_SELECTION_DATA_FROM_LOCAL=true bin/rails console -
Build the header for a Code Review pin to Claude Sonnet 4.5:
user = User.find_by(username: 'root') setting = Ai::ModelSelection::NamespaceFeatureSetting.new( namespace: Group.first, feature: :review_merge_request_dap, offered_model_ref: 'claude_sonnet_4_5_20250929' ) Gitlab::Llm::AiGateway::AgentPlatform::ModelMetadata.new(feature_setting: setting, user: user).executeExpected:
{"provider":"gitlab","feature_setting":"review_merge_request_dap","identifier":null}. Onmasterthe identifier isclaude_sonnet_4_5_20250929. -
Repeat with
offered_model_ref: 'claude_sonnet_4_6', which AI Gateway lists for Code Review. Expected:"identifier":"claude_sonnet_4_6".
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.