Parse structured findings from Duo Code Review output

What does this MR do and why?

Adds a structured JSON parser for Duo Code Review findings, alongside the existing XML parser, reusing the same review_output string parameter.

  • Adds Gitlab::Duo::CodeReview::FindingsParser, which emits the same ResponseBodyParser::Comment objects the XML parser does, so line matching, deduplication, draft notes, and publishing downstream are unchanged.
  • ProcessCommentsService#parsed_body picks the parser: when the flag is on and review_output starts with {, it uses FindingsParser. A { payload with the flag off raises, so flipping the flag off mid-review surfaces the generic review error instead of a misleading "nothing to comment on" note. Anything else falls back to the XML parser as before.
  • Extracts CodeSuggestionFormatter.suggestion_block so both parsers share the suggestion fence and its line offset arithmetic. parse output is unchanged, so this part is a pure refactor.
  • No endpoint, worker, or service signature changes; this is purely a new parsing path behind the flag defined in the parent MR.

The JSON payload removes a whole class of bugs the XML regex parser caused: it needed to defuse structural tags and dropped findings whose file paths contained quotes or angle brackets. See gitlab-org/modelops/applied-ml/code-suggestions/ai-assist!6737 (merged) for the companion change that produces this payload.

Spec placeholders in process_comments_service_spec.rb changed from JSON-shaped strings to <review></review>, since a leading { now selects the structured parser.

No changelog: behind a default-off flag.

Screenshots or screen recordings

N/A, backend-only change.

How to set up and validate locally

  1. Enable the flag in a Rails console: Feature.enable(:duo_code_review_advanced_flow, User.find_by_username('your-username'))
  2. Check out the companion ai-assist branch, then run gdk restart duo-workflow-service gitlab-ai-gateway.
  3. Request a Duo Code Review and check the inline comments plus the one-click suggestions.
  4. Run the specs: bundle exec rspec ee/spec/lib/gitlab/duo/code_review/findings_parser_spec.rb ee/spec/lib/gitlab/llm/utils/code_suggestion_formatter_spec.rb ee/spec/services/ai/duo_workflows/code_review/process_comments_service_spec.rb

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.

References

Edited by Kinshuk Singh

Merge request reports

Loading
Loading