Build web URLs for group-level Duo sessions
What does this MR do and why?
Sessions that belong to a group have no URL. This includes every session started from GitLab Duo for Slack. The group page /groups/<top-level-group>/-/automate/agent-sessions/<id> can already show these sessions, but nothing builds that URL. So the REST API and GraphQL return null, and Slack, MCP, and emails have no link to give the user.
This MR builds that URL in Gitlab::UrlBuilder:
- Project sessions: unchanged,
/<project>/-/automate/agent-sessions/<id>. - Group sessions:
/groups/<top-level-group>/-/automate/agent-sessions/<id>. Subgroup sessions also use the top-level group, becauseGroups::DuoAgentsPlatformControlleronly serves top-level groups (ensure_root_group). - Personal namespace sessions: still
nil, because there's no page for them.
It also:
- Adds a named group route,
group_automate_agent_session, next to the existing project route, so the URL helper exists. The existingautomate/*vueroutecatch-all still serves the page. The generated JS path helpers and the cells routing snapshot are regenerated. - Adds a
webPathfield to theDuoWorkflowGraphQL type, and preloads the routes thatwebUrlandwebPathneed.
These places use workflow.web_url and get a URL for group sessions without further changes: the REST web_url field, GraphQL webUrl, the MCP list_duo_sessions and get_duo_session tools, the Duo session email, duo_session_url on notes, the @GitLabDuo note reply, and the private session link in Slack.
Why the frontend is a separate MR
The UI changes that use webPath are in !258934 (merged), stacked on this MR. The frontend must not use a GraphQL field before the release that adds it has shipped (Backwards compatibility across updates), so that MR waits for 19.6. This MR has no frontend changes and can merge in 19.5.
This MR needs to merge in 19.5 (milestone ends 2026-10-09). If it slips into 19.6, the frontend MR moves to 19.7.
References
- Issue: #631621 (closed)
- Frontend MR (merges after this one, in 19.6): !258934 (merged)
- Related: !258011 (merged)
What changes in the API
The same three sessions on master and on this branch (GET /api/v4/ai/duo_workflows/workflows/:id):
| Session | project_id |
namespace_id |
web_url on master |
web_url on this branch |
|---|---|---|---|---|
| Project session | 1000000 |
null |
…/gitlab-duo/test/-/automate/agent-sessions/3332 |
unchanged |
Group session (gitlab-duo) |
null |
1000000 |
null |
…/groups/gitlab-duo/-/automate/agent-sessions/3354 |
Subgroup session (a subgroup of gitlab-duo) |
null |
1385 |
null |
…/groups/gitlab-duo/-/automate/agent-sessions/3349 |
GraphQL returns the same URL in webUrl, and the new webPath field returns it without the host:
{
"webUrl": "http://gdk.test:3000/groups/gitlab-duo/-/automate/agent-sessions/3349",
"webPath": "/groups/gitlab-duo/-/automate/agent-sessions/3349"
}The subgroup session links through the top-level group gitlab-duo, not through the subgroup.
How to set up and validate locally
These steps check the URLs at the API level, so you don't need Slack. You need GDK with GitLab Duo Agent Platform available. The examples use the gitlab-duo group and the gitlab-duo/test project from the default GDK seed data. You also need a subgroup of gitlab-duo, which the seed data doesn't include: create one, for example gitlab-duo/link-test, or use an existing one. For step 1, you need an existing session in gitlab-duo/test.
export TOKEN=<personal access token with api scope>
export GDK=http://gdk.test:3000-
Project sessions are unchanged. Pick an existing project session and check its URL:
curl -s -H "PRIVATE-TOKEN: $TOKEN" "$GDK/api/v4/ai/duo_workflows/workflows/<project_session_id>" | jq '{project_id, web_url}'web_urlis$GDK/gitlab-duo/test/-/automate/agent-sessions/<id>, the same as onmaster. -
Top-level group session. Create a session in a group, without a project:
GROUP_ID=$(curl -s -H "PRIVATE-TOKEN: $TOKEN" "$GDK/api/v4/groups/gitlab-duo" | jq .id) curl -s -X POST -H "PRIVATE-TOKEN: $TOKEN" "$GDK/api/v4/ai/duo_workflows/workflows" \ --data "namespace_id=$GROUP_ID&goal=Link test&workflow_definition=slack_assistant/v1&environment=web" | jq '{id, web_url}'web_urlis$GDK/groups/gitlab-duo/-/automate/agent-sessions/<id>. Onmasterit'snull. Open the URL in the browser: the session page renders. -
Subgroup session. Repeat step 2 with your subgroup (URL-encoded path):
SUBGROUP_ID=$(curl -s -H "PRIVATE-TOKEN: $TOKEN" "$GDK/api/v4/groups/gitlab-duo%2Flink-test" | jq .id)web_urlstill uses the top-level group:$GDK/groups/gitlab-duo/-/automate/agent-sessions/<id>. The page renders. -
GraphQL matches REST. In GraphiQL (
$GDK/-/graphql-explorer), run this for the three sessions:query($id: AiDuoWorkflowsWorkflowID!) { duoWorkflowWorkflows(workflowId: $id) { nodes { webUrl webPath } } }with
{"id": "gid://gitlab/Ai::DuoWorkflows::Workflow/<id>"}.webUrlmatches the RESTweb_url, andwebPathis the same URL without the host. -
The URL doesn't expose the session. Sign in as a user who can't see the group session (another user's session) and open its URL. The page must not show the session.
-
Optional, MCP: with the GitLab MCP server connected, call
get_duo_sessionfor the group session. The response includes the URL.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Update 2026-10-13
Generated by an AI agent on Andrew's behalf; sources linked inline.
Pushed head: 97952e7e (rebased onto current master; the original commit is unchanged in content).
New commits on top of it:
- f1d9c0c2 Update specs for group-level Duo session URLs (the two stale
nilexpectations now assert the group URL) - 5cf2f366 Preload the root group's route for Duo session URLs
- 97952e7e Apply code review fixes, round 1
The stacked frontend MR !258934 (merged) is rebased onto this head.
Database
Changed in the GraphQL sessions list (duoWorkflowWorkflows) by the preload commit. Roots are
fetched once per page in share_root_ancestors,
so Gitlab::UrlBuilder#duo_workflow_url can read root_ancestor.full_path without a query per
top-level group.
Added, once per page, after the existing
SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."id" IN (<traversal_ids[1]>):
SELECT "routes".* FROM "routes" WHERE "routes"."source_type" = 'Namespace' AND "routes"."source_id" IN (<root ids>)Removed: the per-page routes query for workflow.namespace that { namespace: :route } in
WorkflowsResolver#preloads
issued. The group URL reads the root's route, never the subgroup's own.
root_ancestor's fallback Namespace.find_by(id: traversal_ids.first) is unchanged and still
single-row on every other caller.
EXPLAIN for the added routes statement, on postgres.ai (gitlab-production-main) with 20 real
top-level group ids, the worst case for a page of 20 sessions: an Index Scan on
index_routes_on_source_type_and_source_id (Index Cond on source_type and source_id = ANY(...)),
rows=20. Cold cache https://explain.depesz.com/s/6inK: 46.4 ms total (44.8 ms execution, all I/O read),
buffers shared hit=35 read=27. Warm cache https://explain.depesz.com/s/KxD3: 2.5 ms total (0.25 ms
execution), buffers shared hit=62. Verdict: a bounded index lookup, well under the 100 ms query budget.
For comparison, the removed per-page routes lookup for the subgroups themselves, same statement
with 20 real subgroup ids: same plan, same index, rows=20; cold https://explain.depesz.com/s/S5Nw
(105.6 ms, hit=36 read=60), warm https://explain.depesz.com/s/yAOw (1.7 ms, hit=96). So this replaces
an equivalent-cost lookup on the subgroup routes with one on the root routes.
This needs ~database review for the preload change.
Router sync
cells-routes:router-in-sync compares the generated routes byte for byte with the router's main
and is blocking. The two group agent-sessions/:id templates match the router's existing
/groups/*group_id/-/automate/agents rule, so the paired http-router MR only refreshes the
gitlab_routes.json snapshot. The job stays red until the router's file is byte-identical to ours,
which other in-flight router MRs make unlikely. Once the router MR merges, this MR needs
~"pipeline:skip-router-sync" with that reason in the description.
Not run locally
ee/spec/requests/api/graphql/ai/duo_workflows/workflows_spec.rb and
ee/spec/requests/api/graphql/ai/duo_workflows/workflows_n_plus_one_spec.rb — these request specs
need compiled assets (vite_helper.rb, LoadError: cannot load such file -- sass), which the local
environment does not have; the pipeline runs them. With a local-only stylesheet stub both pass
except workflows_n_plus_one_spec.rb:79, where the asserted host differs from the local instance.