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.
![]() |
![]() |
But Doctor, I am Pagliacci
https://knowyourmeme.com/memes/but-doctor-i-am-pagliacci
![]() |
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_workflowstoken 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.rbruns the query the service sends,user { username human }, with the tokens it uses:- the owner's
ai_workflowstoken returns the username andhuman: true; - a flow service account's composite identity token returns the human owner;
- a session that a service account owns returns
human: false.
- the owner's
spec/graphql/types/user_type_spec.rbchecks theai_workflowsscope onhuman.- End to end, without Rails: the Duo Workflow Service from gitlab-org/modelops/applied-ml/code-suggestions/ai-assist!8059 (merged) names
@jane.doeonce forhuman: true, and not at all forhuman: falseornull. Details are in that MR.
References
- Part of #604181 (closed)
- Duo Workflow Service side: gitlab-org/modelops/applied-ml/code-suggestions/ai-assist!8059 (merged)
- Approach suggested in gitlab-org/modelops/applied-ml/code-suggestions/ai-assist!8059 (comment 4246520757)
- Replaces the flag removal in !271309 (closed) and the rollout in #640338 (closed), both closed
- Reported in Duo Chat on GitLab.com: the agent suggested asking
manuelgrabowski, whilemanuelgrabowskiwas the user in the chat.


