Let ai_workflows tokens read whether a user is human

What does this MR do and why?

Duo Agentic Chat and Duo Agent Platform flows don't know which user they work for. The agent finds out only when it happens to call get_current_user.

Without that, the agent treats the user as a third party when they appear in an issue or merge request. A common result is a reply that ends with "ask @<user> to confirm", where that user is the person in the chat.

image image

But Doctor, I am Pagliacci

https://knowyourmeme.com/memes/but-doctor-i-am-pagliacci

The agent tells the user to ask themselves

The fix

The Duo Workflow Service names the session owner in the system prompt of every agent session. It reads the owner from the duoWorkflowWorkflows query that it already runs at session start: gitlab-org/modelops/applied-ml/code-suggestions/ai-assist!8059 (merged).

The service names the owner only when they are human. It reads user { username human } with the session's ai_workflows OAuth token, but human did not accept that scope, so it came back as null. This MR adds :ai_workflows to the scopes of the human field on the user type.

  • The field only says whether a user is a regular user, not a bot or service account. GitLab already shows that as a badge in the UI.
  • It applies to every user an ai_workflows token can read, not only the session owner.
  • Before this change, the service gets null, skips the block, and keeps its current behavior.

The MR also adds the username to the context table in the GitLab Duo Agent Platform docs.

Why no Rails header

An earlier version sent the username in a gRPC header from Rails, behind a feature flag. The review on gitlab-org/modelops/applied-ml/code-suggestions/ai-assist!8059 (comment 4246520757) showed the query already carries the owner:

  • Workhorse runs that GraphQL request itself, with the token Rails issued, so the client can't see or change the answer.
  • That removes the header, its merge-order rule, a second copy of the username check, and the flag with its rollout.

How to verify

  • ee/spec/requests/api/graphql/ai/duo_workflows/workflow_session_owner_spec.rb runs the query the service sends, user { username human }, with the tokens it uses:
    • the owner's ai_workflows token returns the username and human: true;
    • a flow service account's composite identity token returns the human owner;
    • a session that a service account owns returns human: false.
  • spec/graphql/types/user_type_spec.rb checks the ai_workflows scope on human.
  • End to end, without Rails: the Duo Workflow Service from gitlab-org/modelops/applied-ml/code-suggestions/ai-assist!8059 (merged) names @jane.doe once for human: true, and not at all for human: false or null. Details are in that MR.

References

Edited by Miguel Rincon

Merge request reports

Loading
Loading