Generic Event Triggers
| Status | Authors | Coach | DRIs | Owning Stage | Created |
|---|---|---|---|---|---|
| ongoing |
squadri
ck3g
|
mnohr
kkislay
|
devops ai coding | 2026-12-01 |
Summary
This document outlines our approach to implementing Generic Event Triggers in GitLab.
DAP triggers move from one hand-built implementation per event to a single generic path, with existing webhook payloads as the event source.
This allows Premium and Ultimate customers to start a flow from any event GitLab already sends as a webhook, and to control when it runs by filtering on any field in that event’s payload. Teams can automate their own workflows, such as starting a review flow when a merge request is opened against the main branch, without waiting for GitLab to build a trigger for each event.
Delivery runs in three phases (Phase 1, Phase 2, Phase 3), starting with merge request events, including notes on merge requests, behind a feature flag and an allowlist of filterable fields. Issue events, notes on issues and wiki page events follow behind a separate flag, so each scope can get its own security review before it is exposed.
Context and problem statement
Every DAP trigger today is built by hand. About ten event types exist (merge_request_ready, merge_request_approved, work_item_status_changed and others), and each needs its own worker, event handling, CloudEvent wiring, feature flag and filter UI. GitLab emits hundreds of distinct events across 23 categories, so this does not scale.
The duplication shows up as:
- Repeated code across trigger implementations
- Heavy lifting for each new trigger, slowing delivery as the catalogue grows
- Filters that save but silently never match, with no way to test them
The Software Factory needs customers to start agents on whatever happens in their workflow, scoped by the attributes they care about. For example: when a merge request is opened against the main branch, start the review flow. Hand-building a trigger for every such combination is not viable.
An earlier direction proposed curated, enum-only pickers per event noun with no free-text matching. It reduces noise, but each new event and field still needs a hand-built control, so it does not remove the scaling problem.
Technical decision
Use existing webhook payloads as the single event source for DAP triggers, and evaluate user-defined filters on any payload field before starting a flow.
The dispatch path runs alongside webhooks, not through them.
- A service fires an event and
Project#execute_hooksruns. Webhooks and system hooks are unchanged. - Dispatch: If the project has an active trigger for the hook scope, enqueue
Ai::FlowTriggers::WebhookEventWorkerwith the project, user, scope and full payload. Filters and flow starts never run inside the web request. - Worker: Skip on an unknown scope, a missing project or user, the flag off for the project, or no active trigger. A flow-caused event runs only with
ai_flow_trigger_chainingon and an authorized parent workflow. - Resource lookup:
EventTriggerServicefinds the object the run reports on: the merge request or issue, or for a note, the merge request or issue it was left on. Lookups are scoped to the project so a payload can’t reference another project’s objects. Wiki pages and notes on commits or snippets have no resource. The flow still runs with the full payload, but there’s no progress note or session link and noAI_FLOW_CONTEXT, so foundational flows that need a merge request or issue won’t start. - Filter and run: Each trigger’s filter is evaluated, then
RunService#executeruns with any parent workflow. A failing trigger is rescued and tracked, so the rest still run and the job doesn’t retry. - Guards: Payload redaction before the flow input, and the root-namespace run budget, which starts or skips the run and shows the skip on the trigger.
Filter evaluation
Filters use typed operators with text values, AND within a group and OR between groups. Predefined events (mention, assign, assign reviewer) stay alongside custom conditions. A dry run evaluates a filter against a captured sample and reports which condition failed.
Proposed architecture (flow diagram)
flowchart TD
EV["Event fires<br/>MR, issue, note or wiki page changes"] --> EH["Project#execute_hooks<br/>Builds the webhook payload<br/>Temporary tap until the Phase 0 EventStore event"]
EH --> WH["Webhooks, system hooks<br/>Delivered as today<br/>Disabling one never disables a trigger"]
EH --> DSP["Dispatch<br/>Active trigger for scope?<br/>Enqueue job with payload<br/><i>Being implemented</i>"]
DSP --> WEW["WebhookEventWorker<br/>Flag, trigger, chaining and<br/>parent-workflow checks<br/><i>Merged</i>"]
WEW --> ETS["EventTriggerService<br/>Finds MR or issue via the project,<br/>evaluates filter<br/><i>Merged</i>"]
ETS --> RED["Redaction<br/>Strips sensitive fields before the flow input<br/><i>#642269 · planned</i>"]
RED --> RS["RunService#execute<br/>Starts the flow run<br/>Bills the service account"]
RS --> LIM{"Run budget<br/>per root namespace<br/><i>#637763 · planned</i>"}
LIM -->|under budget| WF["Workflow starts"]
LIM -->|over budget| SKIP["Skipped and logged"]
classDef merged fill:#e9f0fb,stroke:#1f75cb,stroke-width:2px
classDef planned fill:#ffffff,stroke:#89888d,stroke-dasharray:5 4
classDef review fill:#ffffff,stroke:#1f75cb,stroke-dasharray:5 4
class WEW,ETS merged
class RED,LIM planned
class DSP review
The worker, resource lookup and filter run are merged (Add webhook event types to flow triggers, Find the flow run resource from webhook payloads, Add worker that runs flow triggers for a webhook event). Dispatch is being implemented in the dispatch MR, together with the GraphQL MR, filter allowlist MR and form MR. Redaction and the run budget are still to land, so nothing reaches users yet.
Delivery phase
flowchart LR
P1["Phase 1 · &24955<br/>MR events (with MR notes) behind a flag,<br/>then issue, issue note and wiki page<br/>events behind a second flag<br/>Redaction, per-request memo<br/><br/><i>Target: end of 19.9</i>"]
GATE{"Security and<br/>Authorization review"}
P2["Phase 2 · &24956<br/>Guarded, confidential and<br/>Owner-level scopes<br/>Actor rules for no-human events"]
P3["Phase 3 · &24957<br/>Filter builder with dry run<br/>Evaluator fixes<br/>Existing triggers moved over"]
GA["Rollout to all customers<br/>Waits on per-customer run limits (#637763)"]
P1 --> GATE --> P2
P1 --> P3
P2 --> GA
P3 --> GA
classDef active fill:#e9f0fb,stroke:#1f75cb,stroke-width:2px
classDef gate fill:#f5f5f5,stroke:#89888d
class P1 active
class GATE,GA gate
Epics: Phase 1, Phase 2, Phase 3.
Within Phase 1, scopes roll out in two stages. The first is merge requests only: merge_request_hooks and note_hooks for notes on merge requests. The second adds issue_hooks, notes on issues and wiki_page_hooks, behind a second flag, so these ship together. Wiki pages are the weakest candidate because they have no resource and the use case is less clear; if they need to ship later than issues, they get a third flag. Phases 2 and 3 can run in parallel. Rollout to all customers waits on per-customer run limits.
Security considerations
Webhook scopes widen what can start an autonomous run. These risks must be resolved before the affected scopes ship. They gate phase 2 and need Security and Authorization review.
Privilege escalation
Some hooks, such as project_hooks, member_hooks and subgroup_hooks, carry Owner-level events. Today, the person who can see a trigger’s event and the person who can configure a trigger on it are roughly the same. Webhook scopes break that alignment. A Maintainer could attach a flow to Owner-level events they couldn’t have initiated, and receive payload details they may not be entitled to see.
Direction: these scopes stay out of phase 1. Phase 2 decides who may configure triggers on them.
Autonomous escalation
The trigger eligibility validator was designed for scheduled (cron) automations. Webhook categories with no human actor, such as repository_update, scheduled pipelines and member expiry, would fall to the service account path. That path skips the trigger_ai_flow check on the actor, so these runs would be autonomous with no human permission check.
Direction: these categories stay untriggerable until phase 2 defines their actor rules.
Confidential routing
Webhooks keep issue_hooks and confidential_issue_hooks as separate scopes. A trigger on issue_hooks must not receive confidential issues silently once that scope is added. Notes follow the same split: notes on confidential issues go to confidential_note_hooks (from Notes::PostProcessService and Notes::UpdateService), so a note_hooks trigger doesn’t receive them today and must not start to if that scope is added. The worker forwards the full payload to the flow as AI_FLOW_INPUT, so confidential titles, descriptions and note bodies would reach the prompt.
Direction: confidential scopes need an explicit opt-in, and payload redaction decides what’s forwarded.
Sensitive payload content
Payloads can carry sensitive values and internal content. For third-party flows, that content would leave GitLab.
Direction: redact payloads before they reach the flow (payload redaction).
Decision registry
| Decision | Why |
|---|---|
| Webhook payloads are the event source | One funnel for every webhook category, instead of an MR with schema, YAML and subscription per event. Payload improvements benefit every consumer. |
| Redact payloads before they reach the flow | Payloads can carry sensitive and confidential content that must not reach prompts, or leave GitLab for third-party flows. Tracked in payload redaction, which also covers what AI_FLOW_INPUT forwards for confidential scopes. |
Four new event types: merge_request_hooks, issue_hooks, note_hooks, wiki_page_hooks; behind the wip flag ai_flow_trigger_webhook_events (event types MR) |
One type per entity with the action as a filter. pipeline_hooks keeps its own dispatch in EE::Ci::Pipelines::HookService. |
Roll out per scope: merge_request_hooks and notes on merge requests stay behind ai_flow_trigger_webhook_events, and issue_hooks, notes on issues and wiki_page_hooks move behind a second flag |
The code for all four types is merged or in review, so this only gates rollout. It limits risk and leaves time to review security for each hook type before exposing it. The form already reads a flag per event type (form MR); on the backend, model validation and dispatch check one flag today, so mapping each type to its own flag is one small MR. note_hooks also fires for notes on issues, so issue content would reach flows before the issue review. Dispatch will skip those notes with a noteable_type check until the second flag is on. The check and the second flag land together in the flag MR. A trigger can also filter on noteable_type once the filter allowlist MR lands. |
| Move existing hand-built triggers onto the generic path in Phase 3, so the two implementations don’t compete long term | Some existing types become a webhook scope plus a filter, for example merge_request_ready becomes merge_request_hooks with a filter. This is the intended direction, not yet scheduled. See the open question on migrating existing triggers for the gaps. |
Trust a parent workflow only when the event’s user can update it; RunService then checks that the human who started the chain can still trigger flows |
Dispatch passes the workflow ID, and the worker checks it (caller_context.rb). RunService does the second check (run_service.rb). Flow-caused events still run only with ai_flow_trigger_chaining on. Lands with the dispatch MR. |
| Webhook-sourced chains get the same limits as other chains: depth 10, 5 children per workflow and 30 per chain | Reuses the limits in caller_context.rb, so there’s no second set of loop-protection rules. Lands with the dispatch MR. |
Dispatch enqueues the payload’s user.id |
It’s the same user CloudEvents pass as gitlab_user_id, so both paths agree. It becomes current_user for authorization and the run. Decided in the dispatch MR; see the dispatch implementation. |
| Note edits don’t run triggers for now | The payload names the note author, not the person who edited the note. New notes still run. Edits can come back later with the editing user. Decided in the dispatch MR. |
Keep the _hooks names |
They’re already one type per entity. Filters are keyed by type name, so a later rename needs a migration of every stored filter’s top-level key. |
Allowlist the filter-field values for the four webhook types, scalar fields only (see discussion) |
The types must not be exposed without an allowlist or the evaluator work, or rules on arrays would save and never match. The filter allowlist MR adds the allowlist with only the scalar fields the evaluator can match, such as object_attributes.action and target_branch. Labels stay out until array matching works. |
| Webhook types bill the service account | Matches pipeline_hooks and work_item triggers. Not every existing trigger does: merge_request and merge_request_ready are in PERSON_BILLED_FOUNDATIONAL_EVENT_TYPES and bill a person. If those triggers later move onto the webhook types, their billing changes from the person to the service account unless the migration keeps them person-billed. |
Calling from execute_hooks directly is a temporary bridge (see decision) |
The Events Platform plans a thin EventStore event at every execute_hooks call site (Phase 0). Triggers move to it once it exists, so flow triggers keep riding EventStore. |
Run triggers in a Sidekiq job, Ai::FlowTriggers::WebhookEventWorker |
Webhooks often fire inside a web request, where filters and flow starts shouldn’t run. |
| The job carries the full payload; only IDs and the scope are logged | Filters read fields like changes that exist only at event time, so the payload can’t be rebuilt from IDs. Enqueueing only for projects with an active trigger keeps Redis load low. |
| The worker isn’t idempotent; a failing trigger is rescued and tracked instead of retried | A retry would restart the triggers that already ran. The per-trigger rescue lets the rest continue. |
Check registered_for? before parent-workflow authorization |
Skips authorization work when no trigger is registered. This order differs from the CloudEvents worker on purpose. |
Dispatch runs next to WebHookService in its own worker, not through it |
Webhook delivery semantics (auto-disable, HTTP rate limit) don’t fit starting an agent session. A disabled webhook must not silently disable a trigger. |
Resource lookup is a case with one branch per resource type, not a scope-to-resource registry |
A branch is added only for scopes whose runs post a progress note on a new kind of object. Most likely next scopes, such as wiki pages, push and tags, have no resource and add nothing. Move to a mapping when a third new resource type is added. |
Check registered_for? before enqueueing; memoizing it per request is planned |
This bulkhead analysis measured ~298k no-op jobs/day before the guard. Projects without triggers now get zero jobs; projects with triggers get one per event. Today each execute_hooks call runs one query, and only after the flag check, so projects with the flag off pay nothing. The per-request memo (Phase 1) removes the repeat queries. |
Keep the CloudEvents path open with a tracking issue mapping each webhook scope to a future CloudEvent |
Lets scopes migrate to CloudEvents once Events Platform Phase 2 lands, without blocking current delivery. |
| Typed operators with text values; reuse the 8 existing operators and add 6 (starts with, ends with, their negations, is set, is not set) | The operator carries the type, so values stay simple. The engine is already shared with webhooks, so one builder serves both. |
| Discover fields from captured samples, not a maintained schema | Samples reflect per-project reality such as custom statuses and labels. |
| Keep predefined events (mention, assign, assign reviewer) | They’re relative to the trigger’s service account and can’t be expressed as a static filter. |
| Replace the curated-picker model from Trigger filter configuration | Enum-only pickers still need a hand-built control per event and field, which is the scaling problem this work removes. What carries over is still open. |
Alternatives considered
Use CloudEvents as the event source
Route each category through Gitlab::EventStore::CloudEvent subclasses, with the field picker built from each event’s JSON schema.
- Pros: loop control and actor identity already exist; payloads are bounded and curated, so nothing sensitive leaks by default; aligns with Events Platform Phase 2, where Relay delivers external events as
CloudEvents. - Cons: only covers events that already have a
CloudEvent. Every new category is an MR with schema, YAML and subscription, which is the per-event work this design sets out to remove. - Rejected: but kept as a possible end state (see registry).
GitLab-hosted webhook target
Serve a webhook URL from GitLab. Users point an ordinary project webhook at it, and the receiver maps the hook token to a trigger.
- Pros: reuses the whole webhook stack unchanged (filter column, test button, logs, retries, rate limit); opens a route to external payloads without Relay.
- Cons: there’s no human actor at the receiver, so every event-driven run becomes autonomous and the service account path would need generalising. That breaks the permission model built on
trigger_ai_flowfor the acting user. It also adds an HTTP round trip to ourselves and a “create a webhook to create a trigger” UX. - Rejected.
Curated pickers per event noun
One event per noun, with enum, boolean or known-value pickers that map 1:1 to backend rules. No free text, no generic builder.
- Pros: predictable, low-noise UI; every control is valid by construction.
- Cons: each new event and field still needs a hand-built control, so it doesn’t scale to hundreds of events.
- Superseded by Generic event triggers.
Open questions
-
Payload redaction scope: Which fields are redacted for confidential issues and merge requests by default? The current tracking issue for payload redaction is open; the exact allowlist for
AI_FLOW_INPUTis not yet defined. Needs Security and Authorization review. -
Filter field discovery UX: How does a user discover filterable fields before a sample exists? The dry-run evaluator requires a captured sample, but a trigger may never have fired. A fallback schema or example payload per scope is not yet designed.
-
Array field matching: Rules on array fields (labels, assignees) are noted as a known gap. The evaluator behavior for “contains”, “does not contain” and set operators on arrays is not yet specified.
-
CloudEvents migration path: Each webhook scope has a tracking issue mapping it to a future CloudEvent, but the migration sequence and any breaking-change window for stored filters are not yet planned.
-
Per-customer run limits: Rollout to all customers is blocked on bulkhead phase 2 issue: Limit flow-triggered agent runs. The shape of the limit (per namespace, per root namespace, per day) is not yet decided.
-
Predefined event coexistence: Mention, assign and assign-reviewer events are kept alongside custom conditions. How these interact with the generic filter builder in the UI (ordering, grouping, mutual exclusivity) is not yet designed.
-
Migrating existing triggers to the generic path: Phase 3 moves hand-built triggers over so two implementations don’t stay in parallel. It isn’t solved yet. What needs deciding:
- Mapping: Which existing types become a webhook scope plus a filter, such as
merge_request_readybecomingmerge_request_hookswith a filter, and which stay as they are. - Predefined events: Mention, assign and assign reviewer can’t be written as static filters.
- Billing: Some existing types bill the person, but webhook types bill the service account.
- Stored filters: They need a data migration.
- Double-firing: Until a project migrates, one with both a
merge_request_readytrigger and amerge_request_hookstrigger could start two flows for one event.
- Mapping: Which existing types become a webhook scope plus a filter, such as
-
Group-inherited triggers on project webhook events: Should they run at all? A builder shows one project’s sample, but the trigger runs across every project in the group. To be decided in the webhook dispatch implementation; the flag stays per project until then.
-
Actor rules for events with no human (
repository_update,scheduled pipelines,member expiry): Do these categories stay untriggerable, or run on the service account path with atrigger_ai_flowcheck added? -
Owner-level and confidential scopes: Hooks such as project, member and subgroup hooks carry Owner-level events, and
issue_hooksis separate fromconfidential_issue_hooks. Who may attach a flow to these, and how does confidential opt-in work? Needs Security and Authorization review. -
Triggering on
pushevents: Thepush_hooksscope is not yet supported. The payload is large and complex, and the event is high-volume. The design is not yet specified. -
Per scope payload cost: For scopes guarded by
has_active_hooks?(e.g. push, pipeline, job, emoji, milestone), what does building the payload cost in trigger-only projects? This requires scope by scope measurement and decision. -
Sample as schema:
TestHookscovers 15 of 23 categories, and some samples are synthetic. How do we fill the gaps, and how long are captured samples kept? -
Public payload contract: Webhook payloads are documented and versioned. Adding a field a filter needs is a public API change for every webhook consumer. Is that acceptable for Software Factory needs?
-
Convergence with the Primitives Trigger Service: Do DAP triggers stay in Rails, or move onto it over time?
Resources
- Generic event triggers epic
- Composable triggers architecture investigation
- Trigger filter configuration
- PoC: webhook dispatch path
- Webhook dispatch implementation
- Webhook event types behind a flag
- Resource lookup from webhook payloads
- Webhook event worker
- Payload redaction
- Per-customer run limits
- Advanced trigger components
- Primitives Trigger requirements
- Software Factory design doc
Team
Please mention the current team in all MRs related to this document to keep everyone updated. We don’t expect everyone to approve changes.
@mnohr @squadri @ck3g @RajGurung @kkislay
a1beca57)
