Let a top-level group keep external agent audit events to metadata

What does this MR do and why?

Step 2 of https://gitlab.com/gitlab-org/gitlab/-/work_items/635002. glab sends the prompts, tool arguments, tool output and error text of external agent sessions in their AI audit events, and the next step adds model response text. This MR lets a top-level group keep those events to metadata only.

  • Adds external_agent_audit_event_content_enabled to namespace_ai_settings, true by default, so nothing changes until a top-level group turns it off. Like ai_catalog_restricted_to_group_hierarchy, only top-level groups can change it.
  • When it is off, Ai::DuoWorkflows::IngestAuditEventsService reduces the details of each event from a session that glab uploads to an allowlist of metadata keys (ContentRetention::KEPT_EXTERNAL_AGENT_AUDIT_FIELDS: the existing Duo Agent Platform list plus the agent, tool call ID, namespace, outcome, duration, cache token counts and truncation flag that glab sends), before the events are stored or streamed. A key that is not on the list, such as response text added later, is dropped too.
  • Exposed in the REST groups API (ai_settings_attributes and the ai_settings response), as a read-only GraphQL field on AiNamespaceSettings, and documented in doc/api/groups.md.
  • Changing it records an external_agent_audit_event_content_enabled_updated audit event, like the other AI settings.

Claude Code compliance API transcripts and MCP tool calls are stored by other services and are not affected, so the descriptions say "sessions that glab uploads". The group settings toggle is a follow-up MR.

References

Related to https://gitlab.com/gitlab-org/gitlab/-/work_items/635002

How to set up and validate locally

bundle exec rspec ee/spec/services/ai/duo_workflows/ingest_audit_events_service_spec.rb \
  ee/spec/lib/ai/duo_workflows/content_retention_spec.rb \
  ee/spec/models/ai/namespace_setting_spec.rb

Or turn it off for a top-level group through the API, sync a session with glab minder audit sync, and check that the stored events keep no content, tool_args or error_message:

curl --request PUT --header "PRIVATE-TOKEN: <token>" \
  --data "ai_settings_attributes[external_agent_audit_event_content_enabled]=false" \
  "https://gdk.test:3443/api/v4/groups/<group-id>"

Database

namespace_ai_settings is table_size: small in db/docs. The migration adds a boolean column with a constant default, which PostgreSQL stores as metadata without rewriting the table.

Up:

main: == 20261112022739 AddExternalAgentAuditEventContentEnabledToNamespaceAiSettings: migrating
main: -- add_column(:namespace_ai_settings, :external_agent_audit_event_content_enabled, :boolean, {default: true, null: false})
main: == 20261112022739 AddExternalAgentAuditEventContentEnabledToNamespaceAiSettings: migrated (0.0403s)

Down:

main: == 20261112022739 AddExternalAgentAuditEventContentEnabledToNamespaceAiSettings: reverting
main: -- remove_column(:namespace_ai_settings, :external_agent_audit_event_content_enabled, :boolean, {default: true, null: false})
main: == 20261112022739 AddExternalAgentAuditEventContentEnabledToNamespaceAiSettings: reverted (0.0536s)

The ingest service reads the setting once per request, through the session's project and its root namespace's AI settings, which are primary key lookups.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist.

Edited by Jean van der Walt

Merge request reports

Loading
Loading