Refactor DuoCodeReviewChatWorker to use intent-based handler classes
What does this MR do and why?
DuoCodeReviewChatWorker previously handled the code_review_request intent inline, with the routing logic spread across two private methods (code_review_intent? returning a boolean, and classify_mention_intent performing the LLM call separately). This made it harder to add new intent-based routing paths.
This MR refactors the worker in preparation for routing additional intents to dedicated handlers:
- Consolidates intent classification into a single
classify_intent(note)method that returns the raw intent string (ornilon failure/blank message), making the result available for any number of routing branches - Extracts the code review intent logic out of the worker into
Ai::DuoWorkflows::CodeReview::Mention::CodeReviewHandler, following the existingai/duo_workflows/code_review/service pattern. A sharedBaseHandlerprovides the commonduo_code_review_botaccessor andcreate_note_onhelper - Moves
INTENT_*constants to the worker (the caller) and removes them fromClassifyCodeReviewMentionIntent, which is now purely the LLM call executor with no ownership of the intent values
No behaviour changes — this is a pure refactor. The follow-up MR (for issue #585237) will add AssistantFlowHandler on top of this structure.
How to set up and validate locally
Validate code_review_request intent (bot added as reviewer)
- Set up GDK with a GitLab Duo-enabled instance and a project that has the Duo Code Review bot configured
- Open a merge request in that project
- Leave a comment mentioning
@GitLabDuowith a phrase that should trigger the code review intent, e.g.@GitLabDuo can you review this MR? - Verify that the
DuoCodeReviewChatWorkerruns (check Sidekiq logs) and thatCodeReviewHandleris invoked — the bot should be added as a reviewer on the MR rather than posting a chat reply
Validate a normal @GitLabDuo mention (classic chat reply)
- On the same or a different MR, leave a comment that is a general question, e.g.
@GitLabDuo what does this method do? - Verify the classifier does not return
code_review_requestand that the worker falls through to the classic chat path — the bot should post a reply in the discussion thread
Screenshots
code_review_request intent |
code_review_request intent (re-review) |
normal @GitLabDuo mention |
|---|---|---|
![]() |
![]() |
![]() |
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.


