Pass previous Duo Code Review discussions to the review flow

What does this MR do and why?

On a follow-up review Duo has no idea it has already reviewed the merge request, so it repeats findings it has already commented on. This selects a new AI gateway flow version, 2.0.0-dev, which fetches the bot's own existing discussion threads and feeds them to the prompt.

Selection is behind the duo_code_review_previous_discussions feature flag, checked against the project. With the flag off the resolver returns nil and the current 1.0.0 flow is used unchanged.

Duo Code Review posts as Users::Internal#duo_code_review_bot rather than as the flow's service account, so the flow cannot use the existing service_account_name to recognise its own comments. An additional_context_resolver on the code_review/v1 catalog entry sends the bot username in a code_review_context envelope, so only this flow receives it and StartWorkflowService is untouched.

It also adds a third no-comments message, for a case only the new flow can reach: a review that deliberately leaves no inline comments because every finding it had is already covered by an open thread. Without it that summary is published under the existing line number mismatch message, which is untrue. The new message is gated on the same flag, so output for the current flow is unchanged.

References

How to set up and validate locally

  1. Run an AI gateway with the companion merge request checked out.

  2. Enable the flag for a project:

    Feature.enable(:duo_code_review_previous_discussions, Project.find(<id>))
  3. Open a merge request and request a Duo Code Review.

  4. Push a commit that fixes one of its comments and leaves another untouched, then request a second review.

Expected: no repeat comment on the untouched code, and a summary that bullets what was fixed and what is still outstanding.

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 Phil Hughes

Merge request reports

Loading
Loading