Move code completions to v4 suggestions endpoint
What does this MR do and why?
As part of consolidating code suggestions endpoint usage to the V4 API, code completions are the last path still calling the AI Gateway's legacy v2 completions endpoint. This MR routes completions to v4 as well, behind the code_completion_v4_endpoint feature flag.
When the flag is enabled, the completion task builds a code_editor_completion prompt component and lets the AI Gateway resolve the model server-side via model_metadata — the same mechanism generations already use — instead of the v2 flat payload with client-side model remapping. This consolidates both Code Suggestions paths onto one endpoint and one model-resolution mechanism.
With the flag disabled (the default), behavior is unchanged: completions continue to use the v2 endpoint, no new code path runs, and nothing changes for any user.
Dependency: a paired AI Gateway MR adds the response post-processing that v4 completions previously lacked (score filtering, truncation fixing, asterisk stripping, context cap), so suggestion quality and cost stay on par with v2.
References
Closes #598413
FF rollout issue: #602067
How to set up and validate locally
- In a Rails console enable the flag:
Feature.enable(:code_completion_v4_endpoint) - Open an IDE such as VS Code with the Gitlab extension that is using the local GDK account and local AI gateway
- Run a sample code completion in a supported language such as Ruby - the output should be correct and consistent with what is normally produced
- Test a variation of models by selecting a different code completion model in http://gdk.test:3000/admin/gitlab_duo/model_selection
To test directly in a rails console:
user = User.find_by_username('root')
params = {
current_file: {
file_name: 'main.py',
content_above_cursor: "def factorial(n):\n ",
content_below_cursor: ''
}
}
build = -> { CodeSuggestions::Tasks::CodeCompletion.new(current_user: user, params: params) }
t = build.call
t.endpoint # should be "http://gdk.test:5052/v4/code/suggestions"
Net::HTTP.post(URI(t.endpoint), t.body, 'Content-Type' => 'application/json').bodyMR 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.