Skip to content

Enable DCR interactions in non-diff threads & include MR context

What does this MR do and why?

Currently, Duo Code Review will only respond to @mentions in diff notes (aka comments) that DCR created as part of its review.

In this MR, we enable DCR to respond to mentions on non-diff notes. Details:

  • For diff notes: We include diffs data as context to Duo Chat. This behaviour is unchanged.
  • For non-diff notes: We include the full MR context by leveraging Duo Chat's merge_request_reader tool.
    • We provide the MR's iid in a string format recognized by MergeRequestReader::Executor::SYSTEM_PROMPT, which helps to coerce the LLM into using the MR reader tool when necessary.

Further notes

In this iteration, we pass in the MR identifier via additional_context only for non-diff notes. In a future iteration, we could consider including the MR context for both diff and non-diff notes, and perhaps take a different approach (e.g. pass the MR request object as a resource per #510161 (comment 2328846020)). But this is currently out of scope for this issue.

References

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

The following lists different places that you can mention @GitLabDuo in a comment on an MR.

Note type Old behaviour New behaviour
Diff note that DCR created Screenshot_2025-02-03_at_6.08.17_PM No change
Diff note that DCR did not create No response
Screenshot_2025-02-03_at_6.11.18_PM
DCR responds and is context aware
Screenshot_2025-02-03_at_6.20.57_PM
DCR's summary note No response
Screenshot_2025-02-03_at_6.12.14_PM
DCR responds and is context aware
Screenshot_2025-02-03_at_6.15.58_PM
New discussion note No response
Screenshot_2025-02-03_at_6.12.50_PM
DCR responds and is context aware
Screenshot_2025-02-03_at_6.19.33_PM

How to set up and validate locally

  1. Follow these instructions to set up Duo features in your local environment. Additionally:
  • DCR requires Duo Enterprise add-on.
  • Enable FFs :ai_review_merge_request and :duo_code_review_chat.
  • Currently, DCR is only available in SaaS mode, but it's possible to test this on self-managed too bypassing the stage check:
See diff
--- a/ee/lib/gitlab/llm/stage_check.rb
+++ b/ee/lib/gitlab/llm/stage_check.rb
@@ -5,6 +5,7 @@ module Llm
     class StageCheck
       class << self
         def available?(container, feature)
+          return true
           root_ancestor = container.root_ancestor
 
           return false if personal_namespace?(root_ancestor)
  1. Create a new project and open an MR request with code changes.

  2. Mention @GitLabDuo in any MR comment and it should respond (usually within 20 seconds). You can do this before or after assigning @GitLabDuo to do the code review. Observe that GitLabDuo has context about the MR.

Related to #510161 (closed)

Edited by Leaminn Ma

Merge request reports

Loading