Refuse flows with no self-hosted model offline

What does this MR do and why?

Refuse flows with no self-hosted model offline

(https://gitlab.com/gitlab-org/gitlab/-/work_items/629910)On an offline cloud license, a Duo Agent Platform flow whose feature has no self-hosted model went to the cloud workflow service. That service is unreachable offline, so the start failed with a generic token error and the instance sent a request it was never meant to.

(https://gitlab.com/gitlab-org/gitlab/-/work_items/632770) When the model was disabled, setting Agentic Chat to Disabled in Admin > GitLab Duo > Model selection does not turn Agentic Chat off. Sessions still start and are sent to the cloud-connected Duo Workflow Service (duo-workflow-¡.runway.gitlab.net:443) without model metadata, so the service answers with its default GitLab-managed model. The self-hosted AI Gateway receives no traffic.

This merge requests fixes both of those issues. Return no workflow service URL for these cases and refuse the start at each entry point with a message that names the feature to assign a model to. A service URL set in the configuration file is still used.

Changelog: fixed EE: true

References

Related to: https://gitlab.com/gitlab-org/gitlab/-/work_items/632770 https://gitlab.com/gitlab-org/gitlab/-/work_items/629910

How to set up and validate locally

Prequisite:

  • An offline cloud license

For #629910

  • You open your console gdk rails c
  • Destroy the feature setting related to DAP default feature ::Ai::FeatureSetting.find_by_feature(:duo_agent_platform_agentic_chat).destroy
  • Now check the url that the system will output in that case feature_setting = ::Ai::FeatureSetting.find_or_initialize_by_feature(:duo_agent_platform_agentic_chat) user = User.first Gitlab::DuoWorkflow::Client.url_for(feature_setting: feature_setting, user: user) should output nil
  • Now go to http://gdk.test:8080/admin/gitlab_duo/model_selection and set a model for the Agentic Chat feature.
  • Check in the console again feature_setting = ::Ai::FeatureSetting.find_or_initialize_by_feature(:duo_agent_platform_agentic_chat) Gitlab::DuoWorkflow::Client.url_for(feature_setting: feature_setting, user: user) should output the self-hosted AIGW url you've set.

For #632770

  • Got to http://gdk.test:8080/admin/gitlab_duo/model_selection
  • Disable the Agentic Chat feature through the dropdown menu
  • Now check check in console feature_setting = ::Ai::FeatureSetting.find_or_initialize_by_feature(:duo_agent_platform_agentic_chat) user = User.first Gitlab::DuoWorkflow::Client.url_for(feature_setting: feature_setting, user: user) should output nil
  • Now go to http://gdk.test:8080/admin/gitlab_duo/model_selection and set a model for the Agentic Chat feature.
  • Check in the console again feature_setting = ::Ai::FeatureSetting.find_or_initialize_by_feature(:duo_agent_platform_agentic_chat) Gitlab::DuoWorkflow::Client.url_for(feature_setting: feature_setting, user: user) should output the self-hosted AIGW url you've set.

For both cases

You can check if there is an outgoing connection being made to the staging cloud DWS Which would mean the fix don't work with the command below.

sudo tcpdump -i any -n 'dst host <STAGING-CLOUD-DWS-IP> and port 443'. You can find the IP by resolving the DNS of the URL.

You shouldn't see any traffic with the current code during your testing.

Also You can use the API to check the responses:

# Flow start, API path
curl -X POST -H "PRIVATE-TOKEN: $TOKEN" "$GITLAB/api/v4/ai/duo_workflows/workflows" \
  -d project_id=1 -d workflow_definition=developer/v1 -d goal=probe -d start_workflow=true
# Flow start, catalog path: the same call with ai_catalog_item_consumer_id=<developer/v1 consumer> in place of workflow_definition
# Workflow token request (Agents & flows); add workflow_definition=developer/v1 for Duo Developer
curl -X POST -H "PRIVATE-TOKEN: $TOKEN" "$GITLAB/api/v4/ai/duo_workflows/direct_access" -d project_id=1
# WebSocket (Agentic Chat): a GET with WebSocket upgrade headers
curl -i -H "PRIVATE-TOKEN: $TOKEN" -H "Connection: Upgrade" -H "Upgrade: websocket" \
  -H "Sec-WebSocket-Version: 13" -H "Sec-WebSocket-Key: $(openssl rand -base64 16)" \
  "$GITLAB/api/v4/ai/duo_workflows/ws?project_id=1"

The request should be refused with a error message specific to the feature being unavailable.

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 Patrick Cyiza

Merge request reports

Loading
Loading