Remove code_completion_v4_endpoint feature flag

What does this MR do and why?

The feature flag code_completion_v4_endpoint sends Rails-proxied code completions to the AI Gateway endpoint /v4/code/suggestions. With the flag off, they go to the legacy /v2/code/completions.

The flag is a gitlab_com_derisk flag. It was introduced in 19.1. This flag type has a maximum lifespan of two months, so the flag is past due.

On GitLab.com the flag has been on for all users since 2026-08-05. The flag log is at https://gitlab.com/gitlab-com/gl-infra/feature-flag-log/-/work_items/61970.

The flag reached 100% once before, on 2026-07-07. We turned it off on 2026-07-30 because the v4 response dropped the language and model telemetry (#607506 (closed)). We turned it on again on 2026-08-05, after the AI Gateway started to mirror the model field (gitlab-org/modelops/applied-ml/code-suggestions/ai-assist!6365 (merged)). We have seen no problems since.

This MR removes the flag. Code completions now always use the v4 endpoint.

Change in behaviour

  • GitLab.com: no change. It already runs on v4.
  • GitLab Self-Managed and GitLab Dedicated: the flag was off by default, so these instances used v2 until now. After this MR they use v4.
  • For self-hosted models, Amazon Q, and model selection pins, Rails now sends the provider information in the model_metadata field of the v4 request. Before, it sent v2 top-level fields. The AI Gateway handles all three on v4.
  • The AI Gateway keeps serving v2 until GitLab 21.0 (deprecation announcement: !258691 (merged)). Instances that have not upgraded are not affected.

Verified locally on GDK with a self-hosted model behind a mock OpenAI-compatible endpoint. The request that the gateway sent to the model was byte-identical on v2 and v4. The client response was also identical.

Compatibility note

GitLab Duo Self-Hosted customers who run their own AI Gateway must run the gateway image tag that matches their GitLab version. The docs already require this. A gateway change makes v4 self-hosted completions respect the context size of the model (gitlab-org/modelops/applied-ml/code-suggestions/ai-assist!6775 (merged), merged 2026-09-17). This change is not in the 19.4 self-hosted gateway tag. It ships in 19.5.

Amazon Q on v4 is not exercised on GitLab.com. A manual check on a self-managed instance with Amazon Q is still open. It does not block this MR.

Dead code removed

The v2-only prompt classes under ee/lib/code_suggestions/prompts/code_completion/ and their specs are removed. They built the request body for each provider on v2. Nothing calls them now. The unused-code linter then flagged two more items that only those classes kept alive: the file_path_info helper in the prompt base class and the GATEWAY_PROMPT_VERSION constant in the generation prompt. Both are removed too.

The incident_fail_over_completion_provider flag no longer changes the completions request body. On v4 the gateway chooses the model. The flag still disables direct access, so it stays.

Related MR

!258681 (merged) merged first and added remap_model_metadata. This MR is rebased on it, so the v4 request always remaps a stale pinned model.

References

Screenshots or screen recordings

Not applicable. This MR has no UI change.

How to set up and validate locally

  1. Run the AI Gateway locally with GDK: gdk start gitlab-ai-gateway.
  2. Send a code completion through the Rails API. For example, use curl:
    curl --request POST "http://gdk.test:3000/api/v4/code_suggestions/completions" \
      --header "PRIVATE-TOKEN: <token>" --header "Content-Type: application/json" \
      --data '{"current_file":{"file_name":"main.py","content_above_cursor":"def area(r):\n    ","content_below_cursor":""},"intent":"completion"}'
  3. In the gateway log, check that the request path is /v4/code/suggestions. Check that the body has prompt_components and has no top-level prompt_version or model_provider fields.
  4. Optional self-hosted check: in Admin > GitLab Duo > Self-hosted models, assign a self-hosted model to Code Completions. Repeat step 2. Check that the gateway request has model_metadata with provider: openai and the model endpoint.

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.

Edited by Mike Wronski

Merge request reports

Loading
Loading