Pass work item status name to flow trigger filters
What does this MR do and why?
Problem
Flow triggers for Work item > Status changed fired on every status transition, regardless of any filter the user configured.
Users could set a filter rule on the status through the API, and the API accepted and stored it, but the trigger then stopped firing at all.
The cause was in the Sidekiq worker, ExecuteWorkItemStatusChangedWorkflowTriggersWorker. It only passed { 'action' => 'status_changed' } into Ai::FlowTriggers::FilterEvaluator, so a status rule always compared against nil and never matched.
Fix
This MR fixes the data flow so a status.name rule can match. With it, a trigger can be scoped to specific statuses through the API today. The trigger form gains a matching control in the stacked frontend MR.
Changes
- Worker concern hook:
Ai::CloudEventsFlowTriggerWorkernow passes the cloud event throughexecute_flow_triggers, and merges in a new overridable hook,filter_data_extras(cloud_event), which returns{}by default. - Status data wiring:
ExecuteWorkItemStatusChangedWorkflowTriggersWorkeroverridesfilter_data_extrasto return{ 'status' => { 'name' => <new status name> } }, taken from the cloud event payload.- The
WorkItems::StatusChangedEventalready carriedstatus.name, so this only wires up data that was already available.
- The
- New allowed filter field:
Ai::FlowTrigger::ALLOWED_FILTER_FIELDSgains awork_itementry allowing the fieldsactionandstatus.name.- Field validation runs unconditionally, so this entry takes effect on merge. See "Before merging" below.
- Duplicate validation fix: Blank action values for
work_itemfilters were reported twice once both validators applied. The presence check now skips action rules thatfilter_action_values_allowedalready covers.
Filter shape
The expected filter shape adds a status.name rule alongside the existing action rule, as proposed in the issue:
{
"work_item": {
"rules": [
{ "field": "action", "operator": "in", "value": ["status_changed"] },
{ "field": "status.name", "operator": "in", "value": ["<status name>"] }
]
}
}Matching is on the status display name, for example "In progress".
Behavior change to note
Gitlab::FilterEvaluator#dig_value now returns no match when an intermediate path segment is missing from the event data, instead of raising NoMethodError and failing the whole filter.
| Before | After | |
|---|---|---|
| Missing intermediate path segment | Raises NoMethodError, failing the whole filter evaluation |
Returns no match for that rule; other rules still evaluate |
Rules in a scope are AND-ed by default. Without this fix, a status.name rule next to a created action rule made the created trigger never fire.
Under match: any, this is a behavior change for every consumer of the evaluator, including webhook and integration filters: a filter with one unresolvable rule and one matching rule now evaluates to true. A spec covers that case.
Before merging
Once merged, any existing work_item filter with a field other than action or status.name fails validation on its next save. One known shape is the bare status field from the experiment in the issue. Such filters never matched anything, so no trigger loses behavior it had, but their owners would hit a validation error when editing the trigger. Options:
- Check
ai_flow_triggersrows forwork_itemfilters with other fields and clean them up or contact the owners. - Add a compatibility mapping for the legacy
statusfield in a follow-up.
Resolves #607577 (closed)
References
- Issue: #607577 (closed)
- Stacked frontend MR (trigger form status listbox): !254848 (merged)
Screenshots or screen recordings
Not applicable, backend only. The UI is in the stacked frontend MR.
How to set up and validate locally
-
In GDK, use a project that has a flow trigger service account configured.
-
Create a work item trigger through GraphQL with this filter, replacing the status name with one that exists in the project:
{ "work_item": { "rules": [ { "field": "action", "operator": "in", "value": ["status_changed"] }, { "field": "status.name", "operator": "in", "value": ["In progress"] } ] } } -
Change a work item's status to "In progress" and confirm a flow session starts.
-
Change the work item to a different status and confirm no flow session starts.
MR acceptance checklist
This MR has been evaluated against the MR acceptance checklist.