Skip to content

Wait for explain vuln subscription ready before doing AI request

What does this MR do and why?

This MR changes the way we subscribe to AI responses for the Explain Vulnerability feature. Previously, the flow was:

  1. The AI request mutation is started.
  2. At the same time, the subscription is started.
  3. The subscription is ready and waits for messages.
  4. The AI response is received as a subscription message.

Note that it takes some time for backend to process the subscription request and respond with a subscription ready. Previously, this worked fine because the AI response always took a few seconds to complete, which gave the subscription enough time to be ready.

However, now that we are caching the AI response for 5 minutes, sometimes the AI response is sent before the subscription is ready, meaning that the AI response is lost because we weren't subscribed at the time it was sent.

This MR fixes the issue by changing the flow to:

  1. The subscription is started.
  2. The subscription is ready and waits for messages.
  3. The AI request mutation is started.
  4. The AI response is received as a subscription message.

In other words, we now wait for the subscription to be ready before running the mutation, guaranteeing that the response will be received.

How to set up and validate locally

The problem is very difficult to replicate locally because it requires that the backend be loaded down enough so that it takes longer for the subscription to be ready than it is for the cached AI response to be returned. Locally, I think the only thing we can do is verify that the Explain Vulnerability functionality still works.

MR acceptance checklist

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

Related to #420745 (closed)

Edited by Daniel Tian

Merge request reports