Skip to content

Feature: Add @ mention support for AmazonQ bot in MR for code review and follow up comments

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

Original issue: https://gitlab.com/gitlab-com/ops-sub-department/aws-gitlab-ai-integration/integration-motion-planning/-/issues/651#note_2794729108

One of our goals with GQ (GitLab Duo powered by Amazon Q ProServe engagement) is to reach feature parity between GitLab Duo Enterprise and GitLab Duo powered by Amazon Q.

As it stands, there is a feature gap between the way users can request code reviews from GitLab Duo. Users can mention the GitLab Duo bot identity directly to ask for a review, whereas with Amazon Q, they must use quick actions. With GitLab Duo Enterprise, this interaction style also allows for threaded conversations (allowing the user to follow-up on the AI’s comments), while the quick actions does not.

Current State

  • Users must use quick actions /q review to request review from AmazonQ
  • Users cannot reply directly to suggestions from AmazonQ

Desired State

  • Users see @amazonq in autocomplete and can mention it directly
  • /assign_reviewer @AmazonQ works identically to GitLabDuo
  • Users can respond to AmazonQ’s suggestions by mentioning it in the comment thread (same experience as GitLabDuo)
  • If the user is not onboarded, return an error message that directs the user to onboard

There are two parts to the design:

  1. Adding the initial review support
  2. Added threaded comments support

1. Adding Initial Review Support

To support initial reviews, modify the existing bot identity provider to use license parsing to determine which bot identity (GitLabDuo or AmazonQ) to return. Then, rely on the existing ReviewMergeRequestService to provide the AI-powered code review.

  1. License-based routing - Return the correct bot identity (AmazonQ or GitLabDuo) depending on the user’s license
  2. Service provider - Use existing Llm::ReviewMergeRequestService for the AI-powered code review

Details for license-based routing:

Customer License Bot Available Powered By
Amazon Q @amazonq Amazon Q APIs
Duo Enterprise @GitLabDuo GitLab Duo

Key Changes Required

  1. Bot Identity Logic (lib/users/internal.rb)
    1. Upgrade the duo_code_review_bot method to perform license-based routing:
      1. Check Ai::AmazonQ.enabled? for instance-level availability (license + configuration)
      2. Return AmazonQ bot if enabled, GitLabDuo bot otherwise
      3. Single method serves as source of truth for all assignment types (auto and manual)
  2. LLM Integration (ee/app/services/llm/review_merge_request_service.rb)
    1. Perform an AmazonQ review via. AmazonQ Trigger Service if AmazonQ is enabled instead of queuing a completion worker
    2. This will use send_event
  3. Permission Integration (ee/app/policies/ee/project_policy.rb)
    1. Extend :access_ai_review_mr permission to include AmazonQ licensing: (ai_review_mr_enabled | amazon_q_integration_enabled) & user_allowed_to_use_ai_review_mr
    2. Namespace-level validation: reuse existing Gitlab::Llm::FeatureAuthorizer validation chain for GitLab Duo users, with project.duo_features_enabled
  4. Service Compatibility (No Changes Required)
    1. AmazonQ bot works automatically with existing Llm::ReviewMergeRequestService
    2. Both bots share user_type: :duo_code_review_bot for consistent permission handling
    3. Existing Llm::BaseService.valid? validation pattern works for both providers
  5. Auto-complete (ee/app/finders/ee/autocomplete/users_finder.rb)
    1. Return appropriate bot based on license-based routing from Users::Internal.duo_code_review_bot
    2. Single bot returned based on current licensing state
  6. Auto-assign Reviews (No Changes Required)
    1. Existing assign_duo_as_reviewer calls Users::Internal.duo_code_review_bot → gets correct bot automatically
    2. Same permission validation through ai_review_merge_request_allowed?
    3. License-based routing happens transparently in bot selection
  7. Error Handling Integration (Leverages Existing Patterns)
    1. Same Llm::BaseService validation and error message patterns
    2. Cascading duo_features_enabled validation works for both providers
    3. Standard error message: "AI features are not enabled or resource is not permitted to be sent."
    4. AmazonQ licensing errors handled by Ai::AmazonQ.enabled? check

Control Flow Comparison

  1. AmazonQ Quick Actions
    1. /q review → Quick Actions parser → AmazonQTriggerService → AI Gateway → Prompt Resolution → SendEvent → Model
  2. /assign_reviewer @amazonq
    1. Add @amazonq as reviewer → ReviewMergeRequestService → AmazonQTriggerService → AI Gateway
  3. /assign_reviewer @GitLabDuo
    1. Add @GitLabDuo as reviewer → ReviewMergeRequestService → CompletionWorker → CompletionService → AI Gateway

Error Handling

Error Cases

  1. Instance-level: AmazonQ integration not enabled (::Ai::AmazonQ.enabled? returns false - license + configuration)
  2. Cascading Settings: duo_features_enabled disabled at instance → group → project levels (reuses existing cascade)
  3. User Permission: User lacks developer access or appropriate license for AmazonQ
  4. Validation Chain: Same Llm::BaseService.valid? pattern with standard error messages

Solution

  1. The instance does not have the AmazonQ license
    1. The user will not be available, so we do not have to return a specific error
  2. The instance has the AmazonQ license but has not onboarded
    1. If the instance has the correct license for @amazonq but isn’t onboarded, return an error that directs to contact administrator for onboarding.
    2. “AmazonQ has not been onboarded. Please contact your administrator or see the following setup guide [Link] to onboard.
  3. AmazonQ is not enabled on the project or group
    1. AmazonQ leverages the existing cascading permission system through duo_features_enabled settings. The unified permission model means AmazonQ uses the same validation chain as GitLab Duo, with license-based routing determining which provider is used
    2. If AmazonQ is not enabled, then return an error that mentions this fact
    3. “AmazonQ is not enabled for the project or group. Please see the following documentation [Link] for how to enable the feature.

Technical Risks

  • License Check Performance: Ai::AmazonQ.feature_available? should be cached/efficient
  • Performance Parity: Need to ensure the new model provider implementation for the Merge Request Review has the same performance as the quick actions. Ensure that the request is resolved by the same model providers as the existing implementation.

2. Adding Thread Comment Support

Create a dedicated worker to route @amazonq mention responses through Amazon Q SendEvent, keeping the architecture clean and separate from Duo Chat infrastructure... (or, use the existing DuoCodeReviewChatWorker and add forking logic within that worker).

SWAG Estimate

3 weeks

  • Research into supporting threaded conversation for TARS: 2 days
  • GitLab Service modifications: 3 days
  • Testing/validation: 2 days
  • Rework: 3 days
  • Testing/validation: 2 days

Architecture

Current Flow (GitLab Duo)

Note with @ GitLabDuo mention → PostProcessServiceDuoCodeReviewChatWorker → Chat

Proposed Flow

Create Note with @amazonq mention → PostProcessServiceAmazonQReviewWorker (new)AmazonQTriggerService → SendEvent

Implementation Changes

1. ee/app/workers/merge_requests/amazon_q_review_worker.rb (new)

  • Handle @amazonq mentions in merge request comments
  • Extract mention content and discussion context
  • Call AmazonQTriggerService with mention_reply command

2. ee/app/models/ee/note.rb

  • Add amazon_q_mentioned? method (similar to existing duo_bot_mentioned?)

3. ee/app/services/ee/notes/post_process_service.rb

  • Add process_amazon_q_review method
  • Trigger AmazonQReviewWorker for @amazonq mentions
  • Keep existing process_duo_code_review_chat for @GitLabDuo mentions

4. ee/app/services/ai/amazon_q/amazon_q_trigger_service.rb

  • Add support for mention_reply command
  • Handle discussion thread context
  • Create reply notes in the correct thread
  • Reuse existing SendEvent infrastructure

5. ee/app/models/ai/amazon_q/request_payload.rb

  • Add mention_reply_payload method
  • Include discussion thread as context
  • Include diff context for diff notes
  • Format user question from mention

Test Files

5. ee/spec/workers/merge_requests/amazon_q_review_worker_spec.rb (new)

  • Test mention detection and processing
  • Test error handling
  • Test discussion context extraction

6. ee/spec/services/ai/amazon_q/amazon_q_trigger_service_spec.rb

  • Add tests for mention_reply command
  • Test reply note creation

Data Flow

  1. User mentions @amazonq in comment
  2. Notes::CreateService calls PostProcessService after note creation
  3. PostProcessService detects @amazonq mention and enqueues AmazonQReviewWorker
  4. Worker extracts context and calls AmazonQTriggerService
  5. Service sends to TARS via SendEvent with discussion context
  6. TARS response creates reply note in thread

Payload Structure

{
"command": "mention_reply",
"discussion_id": "...",
"note_id": "...",
"user_question": "extracted mention text",
"discussion_context": [...],
"diff_context": {...}, // if applicable
// standard fields (project, MR, auth)\

}

Edited by 🤖 GitLab Bot 🤖