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 flowType is null, the session name falls back to the source label (for example "Claude Code (glab)"). The shared formatAgentDefinition is unchanged.
  • The audit event details panel builds its target from the session's sessionId and source. It no longer uses the hardcoded Ai::DuoWorkflows::Workflow and event.workflowId, which is null for external events. External sessions get the target type Ai::Governance::Session.
  • The Audit events column shows "—" because AiGovernanceSession has no auditEventsCount yet.

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 their gitlab.pot strings) 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 a master that contains !258897 (merged).
  • Stacked on !258505 (merged). This MR targets 630657-ai-governance-session-audit-events, because the drawer queries need auditEvents and id: on aiGovernanceSessions. Retarget to master once !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 existing skip() guard makes sure the drawer query never runs without it.
  • Rollout: rows reorder because results are sorted by session_started_at descending instead of updated_at. Pagination cursors don't carry over when the flag flips. Reads use ClickHouse only until the Postgres path in !257556 (merged) lands.

References

Screenshots or screen recordings

Not captured. No GDK with ClickHouse data was available.

Before After

How to set up and validate locally

  1. Make sure ClickHouse is set up and has siphon_ai_governance_sessions data, including at least one GitLab Duo session and one Claude Code session.
  2. Enable the flag in the Rails console: Feature.enable(:ai_governance_sessions_api).
  3. Go to a group's Settings > GitLab Duo > Governance, then the Audit events tab.
  4. Check that external sessions appear, named by their source, with "—" in the Audit events column.
  5. Open a GitLab Duo session. The URL shows ?session=<workflow id>. Reload the page and check that the drawer reopens.
  6. 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.
  7. 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.

Merge request reports

Loading
Loading