Skip to content

duo-workflow-executor sending payloads larger than 4MiB gRPC limit causing error

Problem

It seems like as we were working on gitlab-org/modelops/applied-ml/code-suggestions/ai-assist#951 (closed) we didn't account for the 4MiB limit of gRPC messages. You can see in https://gitlab.com/gitlab-org/duo-workflow/duo-workflow-executor/-/blob/1059885c426afb8d812b1ebb1907083157c6bcd0/internal/services/runner/runner.go#L217 that we were not returning any responses larger than 4MiB for the legacyResult but we're not doing the same thing for our new actionResult fields.

When I test locally any workflow in the gitlab-org/gitlab project I'm finding that the executor crashes with:

 "error": "error sending response: rpc error: code = ResourceExhausted desc = trying to send message larger than max (19057936 vs. 4194304)"

This happens reliably at the start of the workflow because the first listDirectory seems to exceed this limit.

Desired Outcome

If the payload of a ActionResponse is larger than 4 MB, the following should be returned

a. For http response

{
  "response": "Error running tool: Maximum allowed size exceeded.: Result: 5000000 bytes. Maximum allowed: 4000000 bytes"
  "httpResponse": {
    "error": "Error running tool: Maximum allowed size exceeded.: Result: 5000000 bytes. Maximum allowed: 4000000 bytes"
}

b. for non-http response

{
  "response": "Error running tool: Maximum allowed size exceeded.: Result: 5000000 bytes. Maximum allowed: 4000000 bytes"
  "plaintextResponse": {
    "error": "Error running tool: Maximum allowed size exceeded.: Result: 5000000 bytes. Maximum allowed: 4000000 bytes"
}  

Implementation Plan

Change processResult(&legacyResult) to also handle non-legacy result. Something like

  1. At the end of executeAction method, call a new processResult(&resp)
  2. If size is exceeded, in the processResult

a. write to legacy result fmt.Sprintf("Error running tool: Maximum allowed size exceeded.: Result: %d bytes. Maximum allowed: %d bytes", len(*result), client.MaxMessageSize)

b. write to plainTextResult.error or httpResult.Error fmt.Sprintf("Error running tool: Maximum allowed size exceeded.: Result: %d bytes. Maximum allowed: %d bytes", len(*result), client.MaxMessageSize)

Edited by Halil Coban