Fix model test connection returning 401 when code-suggestions unpinned

What does this MR do and why?

This MR is has 2 related fixes rolled into 1:

1)

When/admin/gitlab_duo/model_selection/models/new when no code completion model is pinned, Test connection button returns 401.

This change fixes it by passing down a mocked feature setting to the cloud connector token generator.

2)

When no code completion model is pinned for code completion. The direct_access call (getting tokens to directly access the AI Gateway without the monolith middle man) does not work neither without a clear error message.

Screenshot_2026-05-22_at_16.26.49

The AIGW error raise JWTError(e)\njose.exceptions.JWTError: Not enough segments isn't much clearer.

How to set up and validate locally

Before

Test connection

  1. Make sure the code completion feature setting is unpinned in /admin/gitlab_duo/model_selection.
    • You run this command in the console to unpin the feature setting in it original state
    • ::Ai::FeatureSetting.find_by(feature: :code_completions).destroy && ::Ai::FeatureSetting.find_by(feature: :code_generations).destroy
  2. Create a new model or modify a model that you know works.
  3. Click the test connection button, It should return 401 coming from the AIGW.

Screenshot_2026-05-21_at_15.05.38

Direct access API call

  1. Make sure the code completion feature setting is unpinned in /admin/gitlab_duo/model_selection.
    • You run this command in the console to unpin the feature setting in it original state
    • ::Ai::FeatureSetting.find_by(feature: :code_completions).destroy && ::Ai::FeatureSetting.find_by(feature: :code_generations).destroy
  2. Go to a project
  3. Open you the Web IDE in this project
  4. Open your developer console in the network tab and reload
  5. You should see this call Screenshot_2026-05-22_at_16.26.49

After

Test connection

Clicking the test connection button, Should work as intended. The test should pass through the AIGW.

Direct access API call

Should give a detailed error message.

Screenshot_2026-05-22_at_16.40.52

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.

Related to #596662 (closed)

Edited by Patrick Cyiza

Merge request reports

Loading