Attribute memory distillation sessions to the MR author

What does this MR do and why?

Memory Distillation sessions triggered by a merged merge request used the user who merged the original MR as the actor and commit co-author. This incorrectly attributed commits to the merger, and could also request review from that same user — who then could not approve a merge request assigned to themselves.

This MR makes two changes so attribution lands on the original MR author:

  1. ExecuteMergeRequestMergedWorkflowTriggersWorker now resolves the session actor (current_user) to the merge request author instead of the user who merged it. The distillation session and its commits are therefore attributed to the author.
  2. Ai::Catalog::GoalTemplates::Developer::MergedMergeRequest goal template:
    • Renames merged_by_username to reviewer_username to match intent.
    • Implements resolve_reviewer_username with a three-tier priority to find a reviewer who differs from the author:
      1. The user who merged the MR (when different from the author).
      2. Any reviewer on the merged MR's reviewer list (excluding the author).
      3. No reviewer when no suitable candidate exists — the author drives the distilled MR themselves.
    • Removes the redundant "acting on behalf of" paragraph (the --assignee instruction already covers attribution).
  3. Shared example fix (cloud_events_flow_trigger_worker_shared_examples.rb): the "when the user does not exist" test now stubs resolve_current_user on the worker instance, so it correctly covers workers that override the default (e.g. this worker uses merge_request.author instead of cloud_event.current_user).

References

Screenshots or screen recordings

Now the MR author will be the author of the distilled MR and reviewer will be requested from the original MR reviewer list.

Screenshot_2026-09-18_at_15.23.48

Screenshot_2026-09-18_at_15.24.01

How to set up and validate locally

The change is covered by specs:

  • ee/spec/models/ai/catalog/goal_templates/developer_spec.rb — verifies the rendered goal attributes the author, requests review from the merger when they differ, falls back to the MR reviewer list when the author self-merged, and omits the reviewer when no suitable candidate exists.
  • ee/spec/workers/ai/catalog/flows/execute_merge_request_merged_workflow_triggers_worker_spec.rb — verifies the flow runs as the MR author.
bundle exec rspec \
  ee/spec/models/ai/catalog/goal_templates/developer_spec.rb \
  ee/spec/workers/ai/catalog/flows/execute_merge_request_merged_workflow_triggers_worker_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.

Edited by Junming Huang

Merge request reports

Loading
Loading