Read the AI audit report from aiGovernanceSessions behind a flag
What does this MR do and why?
The AI audit report page (Audit events tab under group or project settings > GitLab Duo > Governance) and its session details drawer read from duoWorkflowSessionArtifacts. That field only covers GitLab Duo workflows, so external sessions like Claude Code can't appear. This MR switches both to aiGovernanceSessions behind the ai_governance_sessions_api feature flag (beta, off by default).
The list and the drawer switch together. The drawer looks up the session by the ID of the list row, which is now an Ai::Governance::Session global ID passed as id:, not a workflow ID passed as workflowId:.
With the flag on:
- Four new query documents read
aiGovernanceSessions(group and project list, group and project drawer). The old queries stay in place for the flag-off path. - Old-API rows are converted to the new shape by
normalizeLegacySession, so the components only handle one shape. Removing the flag later means deleting that function and the old queries. - The Session ID column, the drawer, and the
?session=URL parameter use the source session ID (sessionId), never the global ID. For GitLab Duo sessions this is the workflow ID, so existing and bookmarked deep links keep working. - Sessions with a null
webPath(external sessions) don't show the View full session details button or the session link. - When
flowTypeis null, the session name falls back to the source label (for example "Claude Code (glab)"). The sharedformatAgentDefinitionis unchanged. - The audit event details panel builds its target from the session's
sessionIdandsource. It no longer uses the hardcodedAi::DuoWorkflows::Workflowandevent.workflowId, which is null for external events. External sessions get the target typeAi::Governance::Session. - The Audit events column shows "—" because
AiGovernanceSessionhas noauditEventsCountyet.
Things to note:
- Includes code copied from !258897 (merged). The first two commits copy the flag push in both governance controllers and
SESSION_SOURCE_LABELS(with theirgitlab.potstrings) from !258897 (merged) unchanged. The plan expected !258897 (merged) to merge first, but it's still open. Because the changes are identical, whichever MR merges second rebases cleanly. Drop these commits when rebasing onto amasterthat contains !258897 (merged). - Stacked on !258505 (merged). This MR targets
630657-ai-governance-session-audit-events, because the drawer queries needauditEventsandid:onaiGovernanceSessions. Retarget tomasteronce !258505 (merged) merges. - One change from the plan: the plan passes
formatSessionName(item)to the details panel. This MR passes the raw flow type, or the source label when there's no flow type. With the formatted name, the flag-off target text would change ("False positive detection/v1 session 1908" instead of "false_positive_detection/v1 session 1908"), and sessions without a flow would read "Agent session session 1908". This keeps flag-off output exactly as it is today. - The
id:argument stays optional on the backend. The existingskip()guard makes sure the drawer query never runs without it. - Rollout: rows reorder because results are sorted by
session_started_atdescending instead ofupdated_at. Pagination cursors don't carry over when the flag flips. Reads use ClickHouse only until the Postgres path in !257556 (merged) lands.
References
- https://gitlab.com/gitlab-org/gitlab/-/work_items/630785
- !258505 (merged) (
auditEventsandid:onaiGovernanceSessions, target branch of this MR) - !258897 (merged) (audit trail card, flag push and source labels)
- !257545 (merged) (
aiGovernanceSessions, merged) - !257556 (merged) (Postgres read path)
- #630933 (feature flag rollout)
Screenshots or screen recordings
Not captured. No GDK with ClickHouse data was available.
| Before | After |
|---|---|
How to set up and validate locally
- Make sure ClickHouse is set up and has
siphon_ai_governance_sessionsdata, including at least one GitLab Duo session and one Claude Code session. - Enable the flag in the Rails console:
Feature.enable(:ai_governance_sessions_api). - Go to a group's Settings > GitLab Duo > Governance, then the Audit events tab.
- Check that external sessions appear, named by their source, with "—" in the Audit events column.
- Open a GitLab Duo session. The URL shows
?session=<workflow id>. Reload the page and check that the drawer reopens. - Open an external session. The drawer has no View full session details button, and the session ID shows as text. Open an audit event and check the target type is
Ai::Governance::Session. - Disable the flag and check the page works as before.
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.