Workflow definition and management
Keep treats a workflow as a tenant-owned definition that turns an event or a time interval into a managed automation. Engineers can supply the definition as YAML through the API, a file, or a UI editor. Keep parses it into a runnable form, stores the raw definition with revision history, and exposes its state through API and web interfaces.
This page focuses on definition and lifecycle concerns within Workflow automation. Runtime evaluation and action dispatch are covered in Workflow execution engine.
Workflow definition
The workflow definition is the contract between authoring tools and the automation system. It gives a workflow an identity and metadata, declares at least one trigger, and describes work through steps or actions. Steps query or prepare data. Actions send or change data. Both refer to provider types and provider configurations, while shared inputs and constants provide values for the run. The accepted shape is defined by keep-ui/…/yaml.schema.ts• L71-243 and the server parser in keep/…/parser.py• L56-127.
The definition also carries control data that affects how Keep manages the workflow:
disabledprevents normal scheduling and event matching.strategycontrols whether runs with the same alert fingerprint may overlap.on-failuredescribes a response to a failed run.owners,permissions, andservicesdescribe ownership and access.debug,consts, andinputssupply run settings and values.
The definition may use the current workflow wrapper. Older alert forms remain accepted for compatibility. A YAML id or name identifies the logical workflow during parsing, but a stored workflow also has a database ID. The server uses the stored ID when it is available and falls back to the definition name for command-line use. See keep/…/parser.py• L28-54 and keep/…/workflowstore.py• L303-339.
Trigger types
Triggers connect a workflow definition to the larger alert and incident system. A workflow can start from a manual request, an alert event, selected incident events, or a time interval. Alert triggers can use the current CEL expression form. Older key-value filters are converted for compatibility. See keep-ui/…/workflows.ts• L19-44 and keep/…/workflowmanager.py• L287-373.
| Trigger | Role in the system | Main definition data |
|---|---|---|
| Manual | Lets a user or API caller start the workflow. | type: manual |
| Alert | Matches an incoming alert. | cel, or legacy filters; optional change checks |
| Incident | Matches named incident events. | events |
| Interval | Runs on a repeating time interval. | value |
Interval values are normalized to seconds. The parser accepts a number or a simple minute, hour, or day suffix. The database then uses the normalized value to decide when the workflow is due. See keep/…/parser.py• L414-449 and keep/…/db.py• L319-445.
References: keep-ui/…/yaml.schema.ts• L71-107 keep-ui/…/workflows.ts• L19-44 keep/…/parser.py• L414-449 keep/…/workflowmanager.py• L287-373
Provider and action references
Provider references connect definition data to installed integrations without placing the full integration setup in each workflow. The parser loads provider and reusable action context from tenant data and optional files or environment data. A step uses a provider that can query. An action uses one that can notify. The UI builds its YAML schema from the provider metadata available to the tenant. See keep/…/parser.py• L223-304, keep/…/parser.py• L565-602, and keep-ui/…/yaml.schema.ts• L109-168.
Provider state is part of workflow readiness rather than part of the workflow record itself. The management view reports the provider type, selected configuration, and whether that configuration is installed. A missing provider can make a workflow invalid to run even when its YAML can still be stored. See keep/…/workflowstore.py• L647-736 and keep-ui/…/validate-definition.ts• L89-125.
References: keep/…/parser.py• L223-304 keep/…/parser.py• L565-602 keep-ui/…/yaml.schema.ts• L109-168 keep/…/workflowstore.py• L647-736 keep-ui/…/validate-definition.ts• L89-125
Definition lifecycle
The lifecycle has one path for authoring and another for runtime use. Authoring stores the submitted YAML as the current record and creates a revision. Runtime later reads that stored YAML and parses it with the tenant's provider and action context. This separation lets the management API show the exact definition that was saved while the execution system creates a fresh runnable workflow for each run. See keep/…/workflowstore.py• L71-104, keep/…/workflowstore.py• L143-178, and keep/…/workflowmanager.py• L578-595.
When a definition is created or changed, Keep follows this sequence:
- The API accepts a YAML file or a request body and safely loads it.
- The store extracts metadata such as name, description, disabled state, and interval.
- The database creates or updates the tenant's workflow and records a new revision when content changes.
- A later read parses the saved YAML into triggers, steps, actions, and provider links.
- The scheduler or an event path loads that runnable form when it needs to start a run.
The create API returns whether the operation created a workflow or updated one. The update API uses the workflow ID and rejects changes to provisioned workflows. See keep/…/workflows.py• L582-716 and keep/…/workflows.py• L795-855.
flowchart LR
A[File, YAML body, or UI editor] --> B[Safe YAML load]
B --> C[Definition metadata]
C --> D[Workflow record and revision]
D --> E[Stored raw YAML]
E --> F[Runtime parser]
F --> G[Runnable workflow]
G --> H[Scheduler or event queue]
YAML and API inputs
The API supports file upload for YAML definitions and a JSON route whose body contains raw YAML content. The UI can upload one or more .yml or .yaml files, paste YAML, or begin with a template. This gives source-controlled definitions and interactive authoring the same storage path. See keep/…/workflows.py• L598-716 and keep-ui/…/upload-workflows-modal.tsx• L56-154.
The test-run API accepts a definition without first saving it as a normal workflow. It parses the submitted content, uses a tenant dummy workflow record when needed, and creates a test execution. This keeps trial runs separate from the tenant's normal workflow list. See keep/…/workflows.py• L486-579 and keep/…/db.py• L654-675.
References: keep/…/workflows.py• L486-608 keep/…/workflows.py• L611-716 keep-ui/…/upload-workflows-modal.tsx• L56-154 keep/…/db.py• L654-675
Validation boundaries
Validation protects different points in the lifecycle. YAML loading checks that the input is parseable. The UI schema checks the shape of the definition and provider-specific fields before it enables deployment. The server parser checks that the definition can become a runnable workflow and can fail when a provider type or configuration cannot be resolved. These checks are related but are not one shared validation step. See keep/…/workflows.py• L582-595, keep-ui/…/yaml.schema.ts• L246-315, and keep/…/parser.py• L146-221.
The UI reports provider and variable problems as warnings in some cases so an engineer can save a definition and repair its setup later. It still blocks structural errors such as a missing name, trigger, or work item. A server-side run request returns a client error when parsing the stored definition fails. See keep-ui/…/workflow-store.ts• L463-531 and keep/…/workflows.py• L374-394.
References: keep/…/workflows.py• L374-394 keep/…/workflows.py• L582-595 keep-ui/…/yaml.schema.ts• L246-315 keep-ui/…/workflow-store.ts• L463-531 keep/…/parser.py• L146-221
Revisions and storage
The database stores the current workflow record and its raw YAML. Each update creates a WorkflowVersion with the next revision and marks it current, while the workflow record points to the same revision. Executions keep the revision that they used. This preserves the link between a run and the definition active when the run started. See keep/…/workflow.py• L12-75 and keep/…/db.py• L483-651.
A workflow is scoped to a tenant and is hidden from normal lists when it is deleted or marked as a test workflow. Deletion is soft. Provisioned workflows are protected from direct delete and update operations because their source is managed outside the API. See keep/…/db.py• L817-919 and keep/…/workflowstore.py• L106-120.
References: keep/…/workflow.py• L12-75 keep/…/db.py• L448-651 keep/…/db.py• L817-919 keep/…/workflowstore.py• L106-120
Scheduling and provisioning
Scheduling turns stored interval metadata into periodic work. The scheduler checks enabled, non-deleted workflows with a positive interval. It creates an in-progress execution record before dispatch. The database constraint acts as a shared lock so more than one scheduler instance does not claim the same interval run. See keep/…/db.py• L319-445 and keep/…/workflowscheduler.py• L115-182.
Event-driven work follows a separate in-memory queue. Alert and incident matching place a runnable workflow in that queue. Manual API runs create their execution record at request time so the caller receives an execution ID at once. The scheduler then dispatches the work to its worker pool. See keep/…/workflowscheduler.py• L284-353 and keep/…/workflowscheduler.py• L408-642.
sequenceDiagram
participant Source as Alert, incident, manual request, or clock
participant Manager as Workflow manager
participant Store as Workflow store
participant Scheduler as Scheduler
participant DB as Workflow database
Source->>Manager: Provide event or due interval
Manager->>Store: Load and parse definition
Store-->>Manager: Runnable workflow
Manager->>Scheduler: Queue workflow
Scheduler->>DB: Create or claim execution
Scheduler->>Scheduler: Dispatch run
Scheduler->>DB: Store status and revision
Provisioned definitions
Provisioning treats YAML outside the API as the source of truth. Keep can provision one workflow from an environment value or many workflows from a directory. It records the source path and marks those workflows as provisioned. A later provisioning pass updates changed content without creating duplicates and removes records whose source is gone. Keep does not allow the normal management API to edit or delete these records. See keep/…/workflowstore.py• L341-516 and keep/…/db.py• L560-651.
The two provisioning modes are exclusive. If neither source is configured, existing provisioned workflows are removed. If both are configured, provisioning fails rather than choosing an unclear source. Directory mode only reads YAML files and removes provisioned records that no longer belong to the configured directory. See keep/…/workflowstore.py• L357-389 and keep/…/workflowstore.py• L455-516.
References: keep/…/workflowstore.py• L341-516 keep/…/db.py• L560-651 keep/…/workflows.py• L824-839
Management interfaces
The management interfaces present workflows as tenant resources rather than as raw files alone. They support list and search views, definition read and export, create and update, version lookup, enable or disable state, manual run, test run, and run history. Access checks are applied by operation, and workflow-level permissions can further restrict manual execution. See keep/…/workflows.py• L178-312, keep/…/workflows.py• L795-855, and keep/…/workflows.py• L1076-1204.
The list response combines stored metadata with trigger and provider readiness data. It also includes the latest run summary and a flag that tells the UI whether the current user can run the workflow. The web page uses this response to choose an empty state or the existing-workflow management view. See keep/…/workflows.py• L199-296, keep/…/workflow.py• L25-47, and keep-ui/…/workflows.page.tsx• L9-35.
Workflow builder and YAML editor
The UI supports two authoring views over the same definition. The builder represents the definition as nodes and edges, while the YAML editor represents it as text. The builder reconstructs a definition after graph changes and validates it before deployment. Provider metadata supplies the fields available in the schema and toolbox. See keep-ui/…/workflow-store.ts• L310-462 and keep-ui/…/workflow-store.ts• L835-909.
The builder keeps unsaved changes separate from deployment state. It does not replace the current graph when pasted YAML fails parsing or schema validation. This prevents an invalid edit from silently replacing a valid working definition. See keep-ui/…/workflow-store.ts• L400-434 and keep-ui/…/workflow-yaml-editor-store.ts• L5-56.
References: keep/…/workflows.py• L178-312 keep/…/workflows.py• L795-855 keep/…/workflows.py• L1076-1204 keep-ui/…/workflow-store.ts• L310-462 keep-ui/…/workflow-store.ts• L835-909 keep-ui/…/workflow-yaml-editor-store.ts• L5-56
Run and version views
The API exposes the current definition and any selected revision, then exposes the revision list separately. Run views return execution status, trigger source, duration, error, results, and logs. The UI can therefore compare what was authored with what ran and inspect the outcome without loading the definition from an external source. See keep/…/workflows.py• L874-975 and keep/…/workflows.py• L977-1145.
Manual runs accept an alert or incident-shaped body, or can replay an existing alert by event ID. The request first loads and checks the stored workflow, then records the triggering user and queues the run. The execution engine owns the work after that handoff; see Workflow execution engine. See keep/…/workflows.py• L315-451 and keep/…/workflowscheduler.py• L284-353.
References: keep/…/workflows.py• L874-975 keep/…/workflows.py• L977-1145 keep/…/workflows.py• L315-451 keep-ui/…/workflow-executions.ts• L9-35
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the YAML schema, parser defaults, and UI workflow types aligned when a definition field or trigger changes.
- Preserve the workflow ID and name lookup rules when changing create, update, or provisioning behavior. They serve different sources and can silently create duplicates.
- Update revision creation and execution revision capture together when changing stored definition updates.
- Keep interval normalization aligned with the database due-run query and scheduler claim logic.
- Preserve the protection boundary for provisioned workflows when adding management operations.
- Keep provider metadata and provider readiness checks aligned so the UI does not mark a workflow runnable when the server cannot resolve its provider.
- Keep test-run records separate from normal workflow and execution lists when changing list or history queries.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A definition has invalid YAML or no required workflow structure. | Upload or test-run parsing fails and no runnable workflow is produced. | Safe-load the YAML and require an ID, at least one trigger, and at least one step or action. |
| A workflow names a provider type or installed configuration that is not available. | The workflow may be stored but cannot be parsed or run. | Use provider-aware UI checks and inspect provider configuration during server parsing. |
| Both provisioning sources are configured. | Provisioning stops instead of selecting one source. | Choose either the environment definition or the directory source. |
| A provisioned workflow is changed through the normal API. | The request is rejected and the external source remains authoritative. | Change the source YAML and run provisioning again. |
| An interval run is claimed while another scheduler instance has claimed it. | The second claim is rejected and that scheduler skips the run. | Use the execution uniqueness constraint as the shared claim. |
| A workflow run stays in progress beyond the timeout window. | The execution is marked as an error or relaunched for interval work. | The scheduler checks stale executions and records a timeout outcome. |
Key files
| File | Why to read it |
|---|---|
| keep/…/workflows.py | Defines the workflow API for create, update, read, version, run, test, provisioning-facing state, and management views. |
| keep/…/parser.py | Shows how a stored definition becomes a runnable workflow and how triggers, providers, actions, and intervals are interpreted. |
| keep/…/workflowstore.py | Connects YAML input, database storage, runtime parsing, metadata, and external provisioning. |
| keep/…/workflow.py | Defines the stored workflow, revision, execution, and execution-log relationships. |
| keep/…/db.py | Shows revision persistence, tenant-scoped lookup, interval claims, soft deletion, and execution records. |
| keep/…/workflowscheduler.py | Explains how interval and event work move from storage or queues into execution. |
| keep-ui/…/yaml.schema.ts | Defines the authoring contract for workflow YAML and provider-aware fields. |
| keep-ui/…/workflow-store.ts | Shows the high-level relationship between the visual builder, YAML definition, validation, and deployment state. |
| keep-ui/…/upload-workflows-modal.tsx | Illustrates the user entry points for YAML files, pasted definitions, and templates. |