Duo Chat slash commands whitespace on auto-complete, no trailing clear on submit, Duo thinks it is a question

Checklist

Summary

Duo Chat Slash commands automatically add a whitespace on auto-completion.

This is helpful for commands that allow refining the prompt, for example /explain, /refactor, /tests but causes irritations with the Chat prompt because Chat thinks this is a question, and not a slash command action.

Steps to reproduce

  1. Open Duo Chat in VS Code
  2. Ask a question to fill the history
  3. Type / and select clean
  4. Use enter to confirm the selection
  5. Press enter again to submit the chat prompt.

What is the current bug behavior?

The prompt sends /clean and not /clean and does not remove the trailing whitespace. This makes Duo Chat think that this is a question, and it responds with saying that it cannot help.

As a user, I expect it to interpret and execution on slash commands accordingly. First-time experience: Not good UX. Suggest fixing this for GA.

What is the expected correct behavior?

Strip the trailing whitespace at the end automatically on prompt submission, and ensure Chat prompt interprets this string as command action, and not a question.

The GitLab UI Chat prompt does not provide auto-complete yet and does not show this behavior with the additional whitespace.

Relevant logs and/or screenshots

gitlab_duo_chat_vs_code_trailing_whitespace_bug.mp4

Possible fixes

On prompt submission, trim all trailing white spaces (beginning, end) to ensure the prompt can be actioned in the AI framework. Suggest fixing this problem on the client side, which controls the user prompt. If the problem continues in other IDEs, find a way to sanitize the prompts in the AI framework / API gateway.

Suggestion: The regex that decides if a prompt is a Slash command is here. It currently just looks at whether the question begins with a /. We then parse the command here and use that string to see if it matches one of the slash commands defined in a def self.slash_commands method.

When we pull the command from the user input in ee/lib/gitlab/llm/chain/slash_command.rb, we should strip whitespace

/cc @tlinz @katiemacoy

Edited by Jessie Young