Add Auto model routing setting to the Auto routing check

What does this MR do and why?

Adds the Auto model routing setting to Ai::ModelSelection::AutoRouting.enabled?. Auto routing now runs only when all of these are on:

  • The duo_developer_model_routing flag
  • Feature preview
  • The Auto model routing setting

The setting is read in the same scope as Feature preview: the top-level group on GitLab.com, the instance on GitLab Self-Managed and Dedicated. nil (never set) reads as off.

The Duo Workflow Service flag push and the model selection pages already use this check. They follow the setting with no other changes.

Note: groups and instances with no stored value lose Auto routing when this merges, including dogfooding groups. An Owner or administrator must turn the setting on.

How to set up and validate locally

  1. In a Rails console, run Feature.enable(:duo_developer_model_routing), then define the helpers for your setup. Both define the same helpers.

    GitLab.com (top-level group): GITLAB_SIMULATE_SAAS=1 bin/rails console
    group = Group.find_by_full_path('gitlab-duo')
    user = group.owners.first
    group.ai_settings.save! unless group.ai_settings.persisted?
    
    set = ->(fp_on, auto) do
      group.namespace_settings.update_column(:experiment_features_enabled, fp_on)
      group.ai_settings.update_column(:auto_model_routing_enabled, auto)
    end
    check = -> { Ai::ModelSelection::AutoRouting.enabled?(user, namespace: group.reload) }
    GitLab Self-Managed (instance): bin/rails console
    user = User.admins.first
    settings = Gitlab::CurrentSettings.current_application_settings
    
    set = ->(fp_on, auto) do
      duo = settings.reload.duo_settings.except('auto_model_routing_enabled')
      duo['auto_model_routing_enabled'] = auto unless auto.nil?
      settings.update_columns(instance_level_ai_beta_features_enabled: fp_on, duo_settings: duo)
      ApplicationSetting.expire # update_columns skips the settings cache expiry
    end
    check = -> { Ai::ModelSelection::AutoRouting.enabled?(user, namespace: nil) }
  2. Run each line.

    Case Run Returns
    Feature preview on, Auto on set.(true, true); check.() true
    Feature preview on, Auto off set.(true, false); check.() false
    Feature preview on, Auto never set set.(true, nil); check.() false
    Feature preview off, Auto on set.(false, true); check.() false
    Flag off, Feature preview on, Auto on Feature.disable(:duo_developer_model_routing); set.(true, true); check.() false

References

🤖 Generated with Claude Code, verified by @cindy-halim

Edited by Cindy Halim

Merge request reports

Loading
Loading