Skip to content

feat: enforce incident trigger CEL in insert_incident - #6657

Open
ausias-armesto wants to merge 1 commit into
keephq:mainfrom
ausias-armesto:ausias/incident-trigger-cel-enforcement
Open

feat: enforce incident trigger CEL in insert_incident#6657
ausias-armesto wants to merge 1 commit into
keephq:mainfrom
ausias-armesto:ausias/incident-trigger-cel-enforcement

Conversation

@ausias-armesto

Copy link
Copy Markdown
Contributor

Fixes: #6656

Problem

WorkflowManager.insert_incident() only checked whether the incoming event
name (created / updated) was declared on the trigger. It never compiled
or evaluated the trigger's cel expression, unlike insert_events(), which
does this for alert triggers. As a result, a cel guard on an incident
trigger — e.g. !has(incident_id), meant to stop a workflow from re-running
once it has already completed and enriched the incident — had no effect at
all. The workflow ran on every matching event regardless.

Change

insert_incident() now:

  1. Finds the specific incident trigger (if any) whose events list contains
    the incoming event name, instead of only checking membership across a
    flattened list of all incident triggers' events.
  2. Merges the incident's persisted enrichments onto the IncidentDto (as
    before), so fields set by a prior successful run (e.g. incident_id) are
    visible.
  3. If the matching trigger declares a cel, compiles and evaluates it via
    the same celpy environment insert_events() uses, and skips scheduling
    the workflow when it evaluates to false. Evaluation errors are caught,
    logged, and treated as "don't run" rather than raised.

incident.dict() leaves UUID fields (like incident.id) as native Python
objects, which celpy.json_to_cel rejects. The activation payload is built
from json.loads(incident.json()) instead, so pydantic's own JSON encoders
handle that conversion first.

insert_incident() only checked whether the trigger's event name matched
(created/updated) but never compiled or evaluated the trigger's "cel"
expression, unlike insert_events() which enforces it for alert triggers.
This meant any cel on an incident trigger (e.g. a guard like
`!has(incident_id)` to prevent re-running after a workflow already
succeeded) was silently ignored and the workflow ran on every matching
event regardless.
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. Bug Something isn't working labels Jul 29, 2026
@ausias-armesto ausias-armesto changed the title fix: enforce incident trigger CEL in insert_incident feat: enforce incident trigger CEL in insert_incident Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[➕ Feature]: Evaluate cel in incident-type triggers

1 participant