Gate AI audit log writes on the storage setting

What does this MR do and why?

Ai::DuoWorkflows::ProcessAuditEventsWorker only checked ai_audit_events_storage_enabled before writing to Postgres or ClickHouse. The log step always ran, so the full event details (prompt, response and tool content) landed in audit_json.log even with storage off, which is the default.

This MR resolves the storage decision once per event in perform and feeds only the opted-in events to both the store step and the log step. Streaming still receives every event and keeps its own separate setting.

The log step now follows the same fail-closed rule as storage: events whose project or namespace cannot be resolved (for example, deleted between enqueue and perform) are no longer written to audit_json.log either.

The original storage gate (!242767 (merged)) deliberately left audit_json.log ungated. The mismatch with what we tell customers about data retention was reported internally. The AI Governance EM opened the issue describing the behaviour as unintended and asked for this fix as a priority.

Docs: the admin streaming page said GitLab "always saves these events to the database", which has been stale since the storage gate landed. Both docs now say the storage setting controls the database and the audit log.

References

Screenshots or screen recordings

Not applicable, no UI changes.

How to set up and validate locally

  1. Leave AI audit event storage off for a project (the default), and tail the audit log:

    tail -f log/audit_json.log | grep ai_
  2. Run an agent session in that project. No ai_* lines should appear.

  3. Enable storage for the project (Settings > General > expand GitLab Duo > turn on Store AI audit events, or in the Rails console):

    Project.find_by_full_path('group/project').project_setting.update!(ai_audit_events_storage_enabled: true)
  4. Run another agent session. The ai_* events now appear in audit_json.log and in ai_audit_events.

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.

Edited by Vasyl Pedak

Merge request reports

Loading
Loading