Accept tool call policy decisions from external agents

What does this MR do and why?

Adds the AI audit event types ai_tool_call_policy_matched and ai_tool_call_policy_evaluation_failed, so GitLab stores and streams the AI tool call policy decisions that glab reports from external coding agents, and the tool calls it allowed because it could not evaluate them.

glab enforces AI tool call policies in the agent hooks on the developer's machine, and reports each decision that matches a policy as an AI audit event through the external agent audit events API. When it cannot evaluate a call, for example because its copy of the policies cannot be read, it allows the call and reports that once per session. That API drops event types that aren't in AuditEvents::AiAuditEvent::ALLOWED_EVENT_NAMES, so this MR:

  • adds both event types to ALLOWED_EVENT_NAMES
  • adds their type definitions, saved to the database and streamed, for projects
  • regenerates the audit event types documentation

The details of ai_tool_call_policy_matched carry the decision and the matched policy. The details of ai_tool_call_policy_evaluation_failed carry a reason code, the tool name, and the tool call ID, but no command or file path. The glab side is in cli!4476 (upload), cli!4477 (the Claude Code hook records its matches), and a follow-up MR for https://gitlab.com/gitlab-org/gitlab/-/work_items/641335 (the hook records when it could not evaluate a call).

A dedicated event type rather than ai_tool_invoked with an outcome, as the GitLab MCP server records blocked calls: a policy decision can also ask the developer rather than block, and it carries the policy and its version. Recording it as a separate event keeps the tool calls that the AI governance page counts to the calls that ran.

The event is project-scoped only, because the external agent audit events API only exists for projects. AI tool call policies are the security policies from https://gitlab.com/groups/gitlab-org/-/work_items/20418, not the AI tool rules (Ai::ToolRule) of the GitLab MCP server.

References

Related to https://gitlab.com/gitlab-org/gitlab/-/work_items/634683 and https://gitlab.com/gitlab-org/gitlab/-/work_items/641335

How to set up and validate locally

bundle exec rspec ee/spec/models/audit_events/ai_audit_event_spec.rb spec/lib/gitlab/audit/type/definition_spec.rb

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist.

Edited by Jean van der Walt

Merge request reports

Loading
Loading