Skip to content

Adds unique request ID to AI actions

Jan Provaznik requested to merge jp-ai-request_id into master

What does this MR do and why?

Adds unique request ID to AI actions processed asycnchornously

  • for each AI mutation which is processed asynchronously it generates a unique ID (this is exposed in aiAction's mutation response)
  • internally it passes this ID together with the mutation request to the worker which executes asynchronously the AI request (the reason is we can then send this request_id together with responseBody when subscription is triggered)
  • this ID is also part of subscription message so clients can pair responses with original requests

So client can store this requestId when it gets mutation response, and then find subscription message specifically for this mutation by its request_id.

Related to #408196 (closed)

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

How to set up and validate locally

(this is a bit complicated but I'm not aware of easier way how to test websockets)

  1. Enable AI-related flags
    Feature.enable(:openai_experimentation)
    Feature.enable(:summarize_comments)
  2. include requestId in ee/app/assets/javascripts/graphql_shared/subscriptions/ai_completion_response.subscription.graphql (FE changes are not part of this MR)
  3. Open an issue page in second browser tab and observe websocket traffic (in developer console)
  4. click on "See summary" button (on top of issue's comments) - from now FE will be subscribed to these events
  5. In another tab/client, send aiAction mutation:
mutation {
  aiAction(input: {summarizeComments: {resourceId: "gid://gitlab/Issue/496"}, clientMutationId: "12346"}) {
    clientMutationId
    requestId
    errors
  }
}

-> requestId should be included in response

  1. observe websocket messages in developer console on issues show page, when aiResponse message arrives, check that it contains requestId which matches the same requestId from aiAction response

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Jan Provaznik

Merge request reports