Back to Gitlabhq

GitLab Duo Code Review (non-agentic)

doc/user/gitlab_duo/code_review.md

19.2.012.4 KB
Original Source

{{< details >}}

  • Tier: Premium, Ultimate
  • Add-on: GitLab Duo Enterprise
  • Offering: GitLab.com, GitLab Self-Managed, GitLab Dedicated

{{< /details >}}

{{< collapsible title="Model information" >}}

{{< /collapsible >}}

{{< history >}}

  • Introduced in GitLab 17.5 as an experiment behind two feature flags named ai_review_merge_request and duo_code_review_chat, both disabled by default.
  • Feature flags ai_review_merge_request and duo_code_review_chat enabled by default on GitLab.com, GitLab Self-Managed, and GitLab Dedicated in 17.10.
  • Changed to beta in GitLab 17.10.
  • Changed to include Premium in GitLab 18.0.
  • Feature flag ai_review_merge_request removed in GitLab 18.1.
  • Feature flag duo_code_review_chat removed in GitLab 18.1.
  • Generally available in GitLab 18.1.
  • Changed to be available on GitLab Duo with self-hosted models in beta in GitLab 18.3.
  • Changed to be generally available on GitLab Duo with self-hosted models in GitLab 18.4.

{{< /history >}}

[!note] Depending on your add-on and group settings, GitLab runs one of two code review features:

  • Code Review Flow: the agentic version, part of GitLab Duo Agent Platform.
  • GitLab Duo Code Review: the non-agentic version, available only for users with the GitLab Duo Enterprise add-on.

This page describes the non-agentic version. Learn how the two features compare.

GitLab Duo Code Review helps you streamline code reviews in your projects.

Use GitLab Duo Code Review

When your merge request is ready to be reviewed, use GitLab Duo Code Review to perform an initial review:

  1. In the top bar, select Search or go to and find your project.
  2. In the left sidebar, select Code > Merge requests and find your merge request.
  3. In a comment box, enter the quick action /assign_reviewer @GitLabDuo, or assign GitLab Duo as reviewer.

<i class="fa-youtube-play" aria-hidden="true"></i> Watch an overview

Provide feedback on this feature in issue 517386.

Contextual awareness

When you use GitLab Duo Code Review, the following data is sent to the large language model:

  • Merge request title
  • Merge request description
  • File contents before changes applied (for context)
  • Merge request diffs
  • Filenames
  • Custom instructions

To specify content to exclude, see exclude context from Code Review.

Behavior on large merge requests

GitLab Duo Code Review sends the merge request diffs and the original contents of changed files to the model. The combined prompt is subject to the selected model's context window.

For large merge requests, GitLab Duo Code Review uses a fallback to improve the chance of a successful review:

  1. The initial request includes the merge request diffs and the original file contents.
  2. If that request fails, GitLab Duo Code Review automatically retries without the original file contents.
  3. If the retry also fails, GitLab Duo Code Review returns a generic error message.

The retry without file contents reduces prompt size, but also reduces the context the model has when reviewing your changes. Comments might be less specific than a review that includes the original file contents.

The AI Gateway request timeout for GitLab Duo Code Review is 120 seconds. Reviews that do not complete in this window also surface as generic errors.

To reduce the risk of failed reviews on large merge requests:

Interact with GitLab Duo in reviews

You can mention @GitLabDuo in comments to interact with GitLab Duo on your merge request. You can ask follow-up questions on its review comments, or ask questions on any discussion thread in your merge request.

Interactions with GitLab Duo can help to improve the suggestions and feedback as you work to improve your merge request.

Feedback provided to GitLab Duo does not influence later reviews of other merge requests. There is a feature request to add this functionality, see issue 560116.

Custom code review instructions

You can create custom MR review instructions to ensure consistent and specific code review standards in your project.

For more information, see customize review instructions for GitLab Duo.

Automatic reviews from GitLab Duo for a project

{{< history >}}

  • Changed to a UI setting in GitLab 18.0.

{{< /history >}}

Automatic reviews from GitLab Duo ensure that all merge requests in your project receive an initial review. After a merge request is created, GitLab Duo reviews it unless:

  • It's marked as draft. For GitLab Duo to review the merge request, mark it ready.
  • It contains no changes. For GitLab Duo to review the merge request, add changes to it.

Prerequisites:

To enable @GitLabDuo to automatically review merge requests:

  1. In the top bar, select Search or go to and find your project.
  2. In the left sidebar, select Settings > Merge requests.
  3. In the GitLab Duo Code Review section, select Enable automatic reviews by GitLab Duo.
  4. Select Save changes.

Automatic reviews from GitLab Duo for groups and applications

{{< history >}}

  • Introduced in GitLab 18.4 as a beta with a feature flag named cascading_auto_duo_code_review_settings. Disabled by default.
  • Feature flag cascading_auto_duo_code_review_settings removed in GitLab 18.7.

{{< /history >}}

Use group or application settings to enable automatic reviews for multiple projects.

Prerequisites:

  • To turn on automatic reviews for groups, have the Owner role for the group.
  • To turn on automatic reviews for all projects, be an administrator.

To enable automatic reviews for groups:

  1. In the top bar, select Search or go to and find your group.
  2. In the left sidebar, select Settings > General.
  3. Expand the Merge requests section.
  4. In the GitLab Duo Code Review section, select Enable automatic reviews by GitLab Duo.
  5. Select Save changes.

To enable automatic reviews for all projects:

  1. In the upper-right corner, select Admin.
  2. In the left sidebar, select Settings > General.
  3. In the GitLab Duo Code Review section, select Enable automatic reviews by GitLab Duo.
  4. Select Save changes.

Settings cascade from application to group to project. More specific settings override broader ones.

Exclude merge requests from automatic reviews

{{< details >}}

  • Status: Beta

{{< /details >}}

{{< history >}}

{{< /history >}}

[!flag] The availability of this feature is controlled by a feature flag. For more information, see the history.

When automatic reviews are turned on for a project, GitLab Duo reviews every eligible merge request. To exclude specific merge requests, define exclusion rules in a .gitlab/duo/mr-review-automated-rules.yaml file.

Exclusion rules only prevent automatic reviews. You can still request a review manually for any excluded merge request.

To define exclusion rules:

  1. In the root of your repository, create a .gitlab/duo directory if one doesn't already exist.

  2. In the .gitlab/duo directory, create a file named mr-review-automated-rules.yaml.

  3. Add exclusion rules using the following format:

    yaml
    exclude:
      target_branches:
        - <pattern>
      source_branches:
        - <pattern>
      authors:
        - <pattern>
    

    Each key is optional. GitLab Duo skips the automatic review when a merge request matches any pattern in any category:

    • target_branches: Matches the target branch name of the merge request.
    • source_branches: Matches the source branch name of the merge request.
    • authors: Matches the username of the merge request author.

    Patterns support wildcard (glob) matching. For example, dependabot/* matches any source branch that starts with dependabot/.

    For example, to skip automatic reviews for merge requests that target a release branch or that a bot account creates:

    yaml
    exclude:
      target_branches:
        - "release/*"
      authors:
        - "*-bot"
    
  4. Commit the file to the default branch of your repository.

GitLab Duo reads the exclusion rules from the default branch of your repository. GitLab Duo does not apply rules on other branches.

Exclude merge requests for a group

To define exclusion rules for all projects in a group and its subgroups, specify a project to use as a template. The template project must contain a .gitlab/duo/mr-review-automated-rules.yaml file.

[!note] If you use custom review instructions for a group, add your exclusion rules to the same template project. You do not need to specify the template project in the UI again. GitLab Duo automatically reads the mr-review-automated-rules.yaml file.

GitLab Duo combines the exclusion rules from the group template project with the rules defined in the individual project. If the same category is defined at both levels, the project's rules take precedence. When a group and its subgroups each set a template project, GitLab Duo combines the rules from every level.

Prerequisites:

  • The Owner role for the group.
  • A project in the group contains the exclusion rules that you want to set.

To configure exclusion rules for a group:

  1. In the top bar, select Search or go to and find your group.
  2. In the left sidebar, select Settings > General > GitLab Duo features.
  3. Under Customize code review, select the project that contains the .gitlab/duo/mr-review-automated-rules.yaml file.
  4. Select Save changes.

Troubleshooting

Review fails on a large merge request

GitLab Duo Code Review might fail to post a review on merge requests with many large changed files. Common causes include:

  • The combined size of diffs and original file contents exceeds the model's context window.
  • The AI Gateway request takes longer than 120 seconds.

For details on the retry and timeout behavior, see behavior on large merge requests.

To work around the failure:

  • Split the merge request into smaller merge requests.
  • Exclude context for files that are not relevant to the review.

For more information, see issue 596794.