Expose duo_session_id on the note REST payload

What does this MR do and why?

Backend work to unblock FE: Add session link to agent reply comments (MRs) (#606457 - closed) • Allison Villa • 19.4

  • Add a scoped association in EE::Note so the serializer (EE::NoteEntity) can reach the duo_workflows_workflow_notes row linking a note to its session.
  • Preload it in inc_relations_for_view (in ee/app/models/ee/note.rb) so a notes page fetches those links in one query instead of one per comment.
  • Expose duo_session_id in EE::NoteEntity on any note with a linked session, reading note_duo_metadata or duo_workflows_workflow_notes.

No schema changes have been added (and no migrations needed), the field reads links that already exist, so it'll populate for agent comments created before this MR too

References

Related to

Screenshots or screen recordings

No UI changes in this MR

How to set up and validate locally

  1. Prerequisite: Have GitLab Duo set up in your GDK
    • Have a Duo-enabled group and project in your GDK created by the Duo setup above
  2. Prerequisite: Have GitLab Runner working
  3. @mention an agent on an MR and ask it a question
  4. In your rails console, confirm the agent's reply exposes duo_session_id, read from the duo_workflows_workflow_notes link:
note = Ai::DuoWorkflows::WorkflowNote.link_type_created.last.note
req = EntityRequest.new(current_user: note.author, noteable: note.noteable)
NoteEntity.new(note, request: req).as_json[:duo_session_id]
  1. Confirm the same for a note linked through note_duo_metadata (Duo Code Review's summary comment, or the duo_mention_started progress note):
note = Notes::NoteDuoMetadata.last.note
req = EntityRequest.new(current_user: note.author, noteable: note.noteable)
NoteEntity.new(note, request: req).as_json[:duo_session_id]
  1. Confirm an ordinary comment omits the key entirely rather than sending null:
note = Note.where(system: false).where.missing(:duo_metadata)
           .where.not(id: Ai::DuoWorkflows::WorkflowNote.pluck(:note_id)).last
req = EntityRequest.new(current_user: note.author, noteable: note.noteable)
NoteEntity.new(note, request: req).as_json.key?(:duo_session_id)
#=> false
  1. In a separate terminal, tail the log and load a merge request with agent comments in the browser:
tail -f log/development.log | grep duo_workflows_workflow_notes

The preload should issue one query with note_id IN (...), not one per comment.

Work items are unaffected b/c their notes come through GraphQL and need their own backend change (#606455 (closed)).

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 Allison Villa

Merge request reports

Loading
Loading