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_enabledtonamespace_ai_settings,trueby default, so nothing changes until a top-level group turns it off. Likeai_catalog_restricted_to_group_hierarchy, only top-level groups can change it. - When it is off,
Ai::DuoWorkflows::IngestAuditEventsServicereduces the details of each event from a session thatglabuploads 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 thatglabsends), 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_attributesand theai_settingsresponse), as a read-only GraphQL field onAiNamespaceSettings, and documented indoc/api/groups.md. - Changing it records an
external_agent_audit_event_content_enabled_updatedaudit 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.rbOr 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.