Mount an uploader on Duo workflow session files

What does this MR do and why?

Create an endpoint to upload files tied to a workflow.

  • Uses the newly added table from !261463 (merged) to store the file metadata.
  • Uses direct upload to upload files faster through the websocket connection.
  • Allows download of the file metadata with the base64 file contents.

References

Persistent file upload issue: #632837

Frontend MR: !263272 (merged)

AIGW MR: gitlab-org/modelops/applied-ml/code-suggestions/ai-assist!7549 (merged)

Out of scope/followups

  1. Block files from being uploaded to archived sessions.

Database

create_session_file!

In ee/lib/api/ai/duo_workflows/workflows.rb

INSERT INTO "duo_workflows_session_files" ("created_at", "updated_at", "workflow_id", "namespace_id", "size", "file", "content_type")
    VALUES ('2026-10-20 09:42:15.329926', '2026-10-20 09:42:15.329926', 719, 1000000, 4772, 'dog_group.jpeg', 'image/jpeg')
RETURNING
    "id"

find_session_file!

In ee/lib/api/ai/duo_workflows/workflows.rb

SELECT
    "duo_workflows_workflows".*
FROM
    "duo_workflows_workflows"
WHERE
    "duo_workflows_workflows"."user_id" = 1
    AND "duo_workflows_workflows"."id" = 717
LIMIT 1
SELECT
    "duo_workflows_session_files".*
FROM
    "duo_workflows_session_files"
WHERE
    "duo_workflows_session_files"."workflow_id" = 717
    AND "duo_workflows_session_files"."id" = 22
LIMIT 1

How to set up and validate locally

  1. Checkout !263272 (merged) which contains this code + frontend changes to upload files
  2. In AIGW checkout gitlab-org/modelops/applied-ml/code-suggestions/ai-assist!7549 (merged)
  3. From the GDK dir, run:
    1. make -C gitlab/workhorse gitlab-workhorse
    2. gdk restart duo-workflow-service workhorse rails
  4. From rails console, enable:
    1. Feature.enable(:dap_web_chat_file_attachments)
    2. Feature.enable(:duo_workflow_session_file_persistent_uploads)
  5. Open Duo Agentic chat and click the + Icon in the bottom left
  6. Upload a file and confirm
    1. The file was uploaded
      1. Ai::DuoWorkflows::SessionFile.last
    2. cat log/api_json.log | grep session_files
      1. The last three should have:
"status":200,"method":"POST","path":"/api/v4/ai/duo_workflows/workflows/701/session_files/authorize"
"status":201,"method":"POST","path":"/api/v4/ai/duo_workflows/workflows/701/session_files"
"status":200,"method":"GET","path":"/api/v4/ai/duo_workflows/workflows/701/session_files/6"
  1. Disable Feature.disable(:duo_workflow_session_file_persistent_uploads)
  2. Reload the page, and send a new file
  3. No Ai::DuoWorkflows::SessionFile should be created, but Duo should still be able to view the file
    1. In the network tab you should see the Base64 instead of the session file url:
network tab with flag enabled and disabled
Flag enabled Flag disabled
image.png image.png

Note: The not found thumbnail is unrelated to this feature, and is due to reloading the page when the frontend is trying to read the base64 that is deleted from the chat log by the AIGW

Other tests - Including confirming existing functionality
Name Screenshot
Multiple images with misnamed image.png
First message image.png
Second message image.png
Too many attachments image.png
Queuing images image.png
Image download returns 500 (puts 0/0) image.png
Edited by Kaveh Nejad

Merge request reports

Loading
Loading