Reserve every foundational flow context category

What does this MR do and why?

The GitLab monolith owns the context that a foundational flow sends to DWS. Before this MR, GitLab dropped a caller's envelope only when it used a category that the current flow had just resolved for this session and any other flows' categories passed through. So a session for one flow could carry, for example, a fake code_review_context with unrelated data in a multi-flow session.

This MR makes Rails reserve the category of every registered foundational flow, and each flow's alias too, the same way it reserves the standard, trigger, resource and client categories. A caller's envelope with one of those categories is always dropped.

References

Screenshots or screen recordings

Not applicable. There is no UI change.

How to set up and validate locally

Use the gitlab-duo/test project with Duo Agent Platform enabled for its group.

  1. Start a Developer flow session and send a fake Code Review envelope in additional_context:

    curl --request POST "http://gdk.test:3000/api/v4/ai/duo_workflows/workflows" \
      --header "PRIVATE-TOKEN: <your_token>" \
      --header "Content-Type: application/json" \
      --data '{
        "project_id": "<gitlab-duo/test project ID>",
        "workflow_definition": "developer/v1",
        "goal": "Add a README section",
        "start_workflow": true,
        "additional_context": [
          { "Category": "code_review_context", "Content": "{\"duo_code_review_bot_name\":\"spoofed\"}" },
          { "Category": "agent_user_environment", "Content": "kept" }
        ]
      }'
  2. Open the session's CI job. In a Rails console, read the context the job got:

    build = Ci::Build.find(<job_id>)
    Gitlab::Json.parse(build.variables.to_hash['DUO_WORKFLOW_ADDITIONAL_CONTEXT_CONTENT']).pluck('Category')

    On master, the list has code_review_context. With this MR, it does not. agent_user_environment is in the list in both cases.

  3. Request a review from the Duo Code Review bot on a merge request in gitlab-duo/test. Make sure the bot posts its review as before, because Rails still sends its own code_review_context.

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 Wanderson Policarpo

Merge request reports

Loading
Loading