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 sameResponseBodyParser::Commentobjects the XML parser does, so line matching, deduplication, draft notes, and publishing downstream are unchanged. ProcessCommentsService#parsed_bodypicks the parser: when the flag is on andreview_outputstarts with{, it usesFindingsParser. 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_blockso both parsers share the suggestion fence and its line offset arithmetic.parseoutput 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
- Enable the flag in a Rails console:
Feature.enable(:duo_code_review_advanced_flow, User.find_by_username('your-username')) - Check out the companion ai-assist branch, then run
gdk restart duo-workflow-service gitlab-ai-gateway. - Request a Duo Code Review and check the inline comments plus the one-click suggestions.
- 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
- Tracking work item: #627566
- Parent epic: gitlab-org#21524
- Benchmark results: https://gitlab.com/gitlab-org/gitlab/-/work_items/618672#note_3770841977
- Companion ai-assist MR: gitlab-org/modelops/applied-ml/code-suggestions/ai-assist!6773 (merged)
- Rollout issue: #627796
- Stacked on: !253786 (merged)