Remap stale pins in code completion model metadata

What does this MR do and why?

An admin can pin code completions to a model. For the ref codestral_2501_vertex, GitLab sends that ref to the AI Gateway unchanged in model_metadata. The gateway removed that ref in March 2026 (ai-assist#1761). Its model config middleware drops unknown metadata without an error, and the gateway serves the request with its default model, which is mostly Fireworks Codestral. The admin chose Vertex, gets Fireworks, and sees a 200.

GitLab already maps the old ref to codestral_2508_vertex with MODELS_REMAPPING. That map applies to model_details and to the v2 request body, but not to model_metadata. Two paths send the raw ref: the model_metadata field of the direct_access API (added in !256435 (merged), 19.5), and the Rails-proxied v4 completions request behind code_completion_v4_endpoint, which is on for GitLab.com. A Snowflake snapshot from 2026-09-29 shows 22 GitLab.com top-level groups still pinned to codestral_2501_vertex.

This MR adds remap_model_metadata to CodeSuggestions::ModelDetails::CodeCompletion. The direct_access pinned metadata and the v4 branch of the completions task both use it. Specs cover both paths. The target milestone is 19.5, the release that adds model_metadata to direct_access.

The language server MR gitlab-org/editor-extensions/gitlab-lsp!4169 (merged) fixes the same stale pin on the client for direct connections. It takes the remapped name from model_details, so it does not depend on this MR. This MR fixes the two paths the client cannot reach.

References

Screenshots or screen recordings

Not applicable. This MR has no UI change.

How to set up and validate locally

  1. In a Rails console, pin the old ref for code completions at the instance level:
    Ai::ModelSelection::InstanceModelSelectionFeatureSetting.find_or_initialize_by(feature: :code_completions).update!(offered_model_ref: 'codestral_2501_vertex')
  2. Call GET /api/v4/code_suggestions/direct_access with a personal access token.
  3. Check that model_metadata.identifier is codestral_2508_vertex.
  4. Enable the v4 flag: Feature.enable(:code_completion_v4_endpoint).
  5. Send a code completions request and check that the body sent to the gateway carries the same identifier.

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.

Merge request reports

Loading
Loading