aiChatAvailableModels GraphQL query does not include self-hosted models

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

Summary

The aiChatAvailableModels GraphQL query does not return self-hosted custom models configured via Admin > Settings > AI-Powered Features > Self-hosted models. This prevents third-party clients (e.g., opencode, VS Code extensions) from discovering and using self-hosted models for agentic chat.

Current Behavior

When a self-hosted model (e.g., a custom Claude Sonnet deployment) is configured for the duo_agent_platform_agentic_chat feature via the GitLab admin UI, the aiChatAvailableModels GraphQL query only returns cloud-managed models from the AI Gateway's /v1/models%2Fdefinitions endpoint. The self-hosted model is not included in selectableModels.

Reproduction

  1. Configure a self-hosted model in Admin > Settings > AI-Powered Features > Self-hosted models
  2. Assign it to the duo_agent_platform_agentic_chat feature
  3. Query aiChatAvailableModels:
query {
  aiChatAvailableModels(rootNamespaceId: "gid://gitlab/Group/<id>") {
    defaultModel { name ref }
    selectableModels { name ref }
    pinnedModel { name ref }
  }
}
  1. The self-hosted model does not appear in the response

Observed on

GitLab 18.10.0-ee (self-managed)

Root Cause

The resolver at ee/app/graphql/resolvers/ai/chat/available_models_resolver.rb uses Ai::ModelSelection::FetchModelDefinitionsService which fetches model definitions from the cloud AI Gateway (/v1/models%2Fdefinitions). The ModelSelection::FeatureSetting decorator then resolves selectable_models only against this cloud-managed list.

Self-hosted models are stored in Ai::SelfHostedModel and are checked by Ai::FeatureSettingSelectionService (line 30-32), but this lookup result is not reflected in the aiChatAvailableModels decorator output.

Meanwhile, the Duo Chat web UI works correctly with self-hosted models because it uses FeatureSettingSelectionService directly to route to the self-hosted AI Gateway endpoint, bypassing the aiChatAvailableModels query.

Expected Behavior

The aiChatAvailableModels query should include self-hosted models configured for the agentic_chat feature on self-managed instances. Specifically:

  • Self-hosted models from Ai::SelfHostedModel that are assigned to the agentic chat feature should appear in selectableModels
  • If a self-hosted model is configured as the default for agentic chat, it should appear as defaultModel

Relevant Code

  • Resolver: ee/app/graphql/resolvers/ai/chat/available_models_resolver.rb
  • Model definitions service: ee/app/services/ai/model_selection/fetch_model_definitions_service.rb
  • Decorator (cloud models only): ee/lib/gitlab/graphql/representation/model_selection/feature_setting.rb
  • Decorator (includes self-hosted): ee/lib/gitlab/graphql/representation/ai_feature_setting.rb — this decorator has with_self_hosted_models support but is not used by aiChatAvailableModels
  • Feature setting selection: ee/app/services/ai/feature_setting_selection_service.rb

Impact

Third-party clients that rely on aiChatAvailableModels for model discovery cannot discover or use self-hosted models. This affects:

  • opencode — uses this query for workflow model discovery
  • Any VS Code extension or IDE integration using the same GraphQL endpoint
Edited by 🤖 GitLab Bot 🤖