Workflow definitions and versions
A workflow definition is the durable specification that tells Hatchet what work belongs to a workflow and how that work may run. The platform turns a client declaration into a checked, versioned record with step metadata, trigger links, and run controls that dispatchers and workers use. See Workflow orchestration for the wider run lifecycle.
Definition model
The definition model joins workflow policy with an ordered set of steps. Each step names work that a worker can perform and describes its place in the dependency graph. The definition can also set input rules, priority, concurrency, idempotency, event filters, and a failure step. The version contract in api-contracts/…/workflows.proto• L96-116 is the main public shape for this model. See Public API contracts for the wider client and service contract.
| Definition area | Purpose |
|---|---|
| Workflow identity | Names the long-lived workflow and gives it an optional description and version label. |
| Step graph | Connects readable step names to worker action IDs and parent steps. |
| Execution policy | Sets time limits, retries, retry backoff, rate limits, worker labels, slots, batching, and step concurrency. |
| Workflow policy | Sets workflow concurrency, priority, stickiness, input validation, default filters, and idempotency. |
| Version identity | Records the effective definition checksum and order so the service can reuse unchanged definitions and select the latest one. |
| Trigger links | Associates event, cron, and scheduled triggers with the registered version. |
| Failure handling | Adds a step that runs when the normal workflow fails. |
The workflow name identifies the long-lived workflow. The workflow version identifies one accepted specification for that workflow. A run keeps the version ID that supplied its steps, so later registration can change the latest definition without changing work that already exists. Worker context exposes both identities for this reason (pkg/…/context.go• L99-107).
Tenant-scoped concurrency is shared tenant policy rather than workflow shape. Its expression, limit strategy, optional input-based run-limit expression, and effective limits are kept in tenant-level strategy records that step references can use without creating a new workflow version (pkg/…/workflow.go• L345-435, pkg/…/workflow.go• L719-725, pkg/…/workflows.sql• L610-635).
References: api-contracts/…/workflows.proto• L96-116 pkg/…/workflow.go• L38-110 pkg/…/workflow.go• L345-435 pkg/…/workflows.sql• L116-156 pkg/…/workflows.sql• L610-635
Definition assembly
SDKs assemble definitions before they cross the service boundary. A declaration keeps workflow options and task declarations in memory. Its dump step creates the shared version request while keeping the handler functions available for worker registration (sdks/…/declaration.go• L712-815). This separates the durable description from the local function bodies that run the actions.
The Go SDK supports regular, durable, and batch task forms. It also supports an on-failure task. A task declaration supplies readable identity, action identity, parent steps, and runtime policy such as retries, timeouts, conditions, rate limits, labels, and slot use (sdks/…/workflow.go• L206-260, sdks/…/workflow.go• L356-459). TypeScript exposes the same high-level model through WorkflowDefinition (sdks/…/declaration.ts• L322-348).
The worker registration path sends the assembled contract through the admin client. The service maps the wire fields into repository options before it validates and stores the definition (pkg/…/worker.go• L432-440, pkg/…/admin.go• L262-277, internal/…/server.go• L846-871).
The definition assembly and registration path is summarized below.
flowchart LR
A[SDK workflow and task declarations] --> B[Version request]
B --> C[Admin service mapping]
C --> D[Validation and graph checks]
D --> E[Workflow version record]
E --> F[Steps triggers queues and policies]
F --> G[Runtime dispatch and workers]
References: sdks/…/declaration.go• L712-815 sdks/…/workflow.go• L206-260 sdks/…/workflow.go• L356-459 internal/…/server.go• L846-871
Version lifecycle
Registration is an upsert-like operation for a workflow name. The repository creates the workflow identity when needed. It locks the previous latest version during replacement and compares a normalized checksum with that version. An unchanged definition reuses the existing version. A changed definition creates a new version and stores its serialized options (pkg/…/workflow.go• L690-820, pkg/…/workflow.go• L907-937).
The stored version keeps the checksum, version order, normalized workflow options, and derived workflow shape that define its runtime contract. New-run lookups use the highest active order for the workflow, while an existing run keeps the version it selected. This separates the current definition from the definition that an in-flight run must continue to use (pkg/…/workflows.sql• L508-520, pkg/…/workflows.sql• L973-991).
Tenant-scoped concurrency definitions are upserted before the checksum decision. This allows a re-registration to update shared tenant policy even when the workflow version remains unchanged (pkg/…/workflow.go• L716-725). The explicit version label is metadata. The checksum is the platform's change test. This lets callers name a release while the platform avoids duplicate versions for the same effective definition.
When a new version replaces an old one, trigger associations that must continue move to the new trigger set. Existing run data still keeps its original version reference (pkg/…/workflow.go• L1081-1175). Registration also notifies cron and scheduler components when they must refresh (internal/…/server.go• L885-935). Trigger behavior is described in Triggers and scheduling.
Cron and scheduled trigger writes use the same latest-version boundary. Creating an API cron or scheduled run attaches it to the latest live version, while trigger changes that affect allocation first synchronize with that version. This keeps trigger ownership and resource accounting consistent while registration replaces a definition (pkg/…/workflow_schedules.go• L244-303, pkg/…/workflow_schedules.go• L334-400, pkg/…/workflow_schedules.go• L834-918).
Every multi-step or on-failure version uses the DAG operator. Registration creates the durable orchestrator step and ensures that the default DAG operator exists before the transaction commits. This keeps multi-step and on-failure workflows executable without a separate operator feature gate (pkg/…/workflow.go• L795-840, pkg/…/workflow.go• L882-918).
Workflow-level concurrency is placed on the runtime unit that represents the whole workflow. For a single-task workflow, the repository places it on that task. For a multi-step workflow that uses the DAG operator, it places it on the generated orchestrator step. The orchestrator's readable ID includes the workflow name and the declared task IDs, which prevents a user step with the workflow name from being mistaken for the synthetic step during graph checks. This keeps the concurrency contract on the unit that can limit the complete run (pkg/…/workflow.go• L851-922, pkg/…/workflows.sql• L522-600). See Concurrency controls for runtime admission behavior.
References: pkg/…/workflow.go• L693-848 pkg/…/workflow.go• L851-939 pkg/…/workflow.go• L941-1263 pkg/…/workflow_schedules.go• L244-303 pkg/…/workflow_schedules.go• L334-400 pkg/…/workflow_schedules.go• L834-918 pkg/…/workflows.sql• L472-520 pkg/…/workflows.sql• L522-600
Step metadata
Step metadata turns a named action into schedulable work. A readable ID gives operators and dependent steps a stable name. An action ID selects the worker handler. Parent IDs form the dependency graph. The remaining fields control admission and execution after the step becomes runnable (api-contracts/…/workflows.proto• L180-198).
The main metadata groups have these roles:
- Dependencies: Parent names and match conditions determine when a step can enter the run path.
- Execution limits: Timeouts, retry count, backoff, and durable mode define how the engine treats slow or failed work.
- Placement: Worker labels and slot requests constrain which worker capacity may accept the step.
- Load controls: Rate limits, concurrency entries, and batch settings shape admission when many runs compete. A dynamic run-limit expression can set a concurrency group's effective limit from task input.
- Runtime data: Inputs and user data provide values to the handler when the step runs.
The repository persists this metadata with each version's jobs and steps. It also creates action and queue links, parent links, slot requests, worker-label rules, rate-limit expressions, concurrency links, and match conditions. Runtime task records then carry the workflow version ID and step ID into dispatch and worker execution (pkg/…/workflow.go• L1266-1709). See Run dispatch and queue execution for how this metadata affects runnable work.
The persistence reads keep these records tenant-scoped and return the parent links and policy counts needed to rebuild a step's runtime view. Tenant-scoped concurrency references carry the current shared strategy values into step reads, so runtime consumers can use the same policy that registration accepted (pkg/…/workflows.sql• L1-78, pkg/…/workflows.sql• L610-671). This lets the engine load a version as one contract while still keeping step-specific controls beside the step.
References: api-contracts/…/workflows.proto• L180-198 pkg/…/workflow.go• L112-220 pkg/…/workflow.go• L1266-1709 pkg/…/workflows.sql• L1-78 pkg/…/workflows.sql• L290-440 pkg/…/workflows.sql• L610-671
Validation and normalization
Validation protects the boundary between a client declaration and a runnable version. The admin service validates the translated request before persistence. The repository then validates the option model and rejects invalid dependency graphs before it starts the version transaction (internal/…/server.go• L851-865, pkg/…/workflow.go• L690-705).
The checks cover field rules and relationships between fields. Names and action IDs must use accepted forms. Cron strings, durations, JSON values, and CEL expressions must parse. Retry, priority, slot, and concurrency values must stay in range. Step readable IDs must be unique. Parent references must point to known steps. A cycle is rejected because it cannot produce a runnable order (pkg/…/validator.go• L18-102, pkg/…/workflow.go• L2095-2211). Tenant-scoped concurrency chains are checked against each other and against other workflows. Conflicting order is rejected because it can cause a deadlock (pkg/…/workflow.go• L489-664).
After validation, the repository orders steps by dependency and normalizes values that should not change the effective definition. It assigns stable indexes to condition groups and removes the default slot request from checksum input. Tenant-scoped concurrency details are also removed from the workflow shape checksum. This includes the dynamic run-limit expression. A change to shared tenant policy therefore updates that policy in place instead of creating a workflow version (pkg/…/workflow.go• L2136-2234). A custom slot request or durable step still changes the checksum because it changes runtime behavior.
References: pkg/…/workflow.go• L489-664 pkg/…/workflow.go• L693-710 pkg/…/workflow.go• L2136-2234 pkg/…/workflow.go• L2270-2344
Runtime contracts
The version record bridges declarative configuration and runtime execution. Registration stores normalized options and creates the step records that scheduling, queue selection, concurrency, and workers read. A trigger or API run resolves a workflow name to the latest version for new work. The resulting task records retain the selected version so execution uses a fixed specification (pkg/…/workflow.go• L844-1008, pkg/…/workflows.sql.go• L1490-1569). The repository and its database queries form the persistence boundary described in Repositories, messaging, and configuration.
Workflow listings and version reads also resolve the latest active version within the caller's tenant. Listing exposes event triggers and default cron summaries from that version. API-created crons and scheduled runs attach to the latest live version, while direct version reads can return the version's trigger and concurrency associations. This keeps control-plane views aligned with the definition that new runs will use without changing older run records (pkg/…/workflows.sql• L797-868, pkg/…/workflow.go• L1716-1857, pkg/…/workflow_schedules.go• L334-400, pkg/…/workflow_schedules.go• L834-918).
The contract has two related sides:
- Control side: The version request carries workflow and step configuration into the admin service. The response returns the workflow and version IDs (api-contracts/…/workflows.proto• L96-116, api-contracts/…/workflows.proto• L209-213).
- Execution side: Worker-facing task data carries action, step, workflow, and workflow-version identity. Worker context exposes these identities to handlers and child-workflow operations. See Worker lifecycle and listener for the worker-side lifecycle (pkg/…/context.go• L90-123).
Version reads are tenant-scoped. A caller must receive a version from its own tenant before the service returns its triggers and concurrency data. This prevents a version ID from being used to read another tenant's workflow definition (pkg/…/workflow.go• L1786-1857, pkg/…/workflows.sql• L771-782).
Pause state is an operational control on the workflow, not a new definition version. While paused, new runs can remain queued or be dropped according to the queue policy. Unpausing makes retained runs eligible for requeue and execution. Trigger and pause state are cached and reconciled, so a pause change can take a short time to affect all queued, cron, and scheduled work (sdks/…/test_workflow_pause.py• L17-47, sdks/…/test_workflow_pause.py• L78-118, sdks/…/test_workflow_pause.py• L195-240).
References: pkg/…/workflow.go• L1716-1909 pkg/…/workflow_schedules.go• L334-400 pkg/…/workflow_schedules.go• L834-918 pkg/…/workflows.sql• L442-520 pkg/…/workflows.sql• L757-868 pkg/…/workflows.sql.go• L1490-1569 pkg/…/context.go• L90-123
Change checklist
When these files or sections are changed, remember to consider these:
- Keep api-contracts/…/workflows.proto aligned with the admin request mapping in internal/…/server.go and the repository option model in pkg/…/workflow.go.
- Preserve checksum normalization rules when changing serialized option fields. A field rename or default change can create new versions for existing definitions.
- Keep user step readable IDs distinct and preserve the synthetic DAG orchestrator identity across graph checks, persistence, queue creation, and worker task context.
- When version or trigger persistence changes, check trigger movement and scheduler refresh so cron and scheduled work do not point to stale definitions.
- When creating, enabling, disabling, or deleting cron and scheduled triggers, preserve the latest-version lock and the matching allocated-resource count update.
- When adding step policy, carry it through persistence and task creation so scheduling and workers receive the same contract that registration accepted.
- When changing tenant-scoped concurrency, keep the shared strategy upsert, checksum exclusion, step references, dynamic run-limit expression, and cross-workflow ordering checks consistent.
- When changing version reads, keep tenant and workflow ownership checks aligned so IDs cannot cross tenant or workflow boundaries.
- When changing workflow list or latest-version queries, keep active-version ordering, tenant scope, and latest-version trigger summaries aligned with new-run resolution.
- When changing DAG-operator-backed registration, preserve operator creation before commit so every multi-step or on-failure definition has a runnable operator.
- When changing workflow pause behavior, preserve the distinction between paused queue handling, trigger cache delay, and unpause reconciliation.
- When changing pkg/…/workflows.sql, regenerate pkg/…/workflows.sql.go so query parameters and returned runtime fields remain aligned.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A step names a missing parent | Registration fails because the dependency graph cannot be ordered. | Validate parent names and run graph checks before persistence. |
| Two steps use the same readable ID | Registration fails because step identity is ambiguous. | Reject duplicate step names before graph ordering. |
| A user step collides with the workflow name on the DAG operator path | Graph checks can treat the synthetic orchestrator and user step as the same node. | Give the generated orchestrator a readable ID based on the workflow and declared task IDs. |
| Steps contain a dependency cycle | No valid runnable order exists, so the version is rejected. | Run cycle detection during version registration. |
| An action ID is missing or invalid | The server cannot map the step to a worker action or queue. | Validate action IDs at the API boundary and when deriving queue notifications. |
| A DAG-operator-backed version is stored without its default operator | Multi-step or on-failure work can reach runtime without the operator needed to execute it. | Ensure the default DAG operator exists before registration commits. |
| A changed option is omitted from checksum input | A real definition change can reuse an old version and run with stale policy. | Update checksum input and normalization rules with the option contract. |
| A checksum-stable definition changes tenant concurrency details | The workflow version stays stable while shared tenant concurrency state changes in place. | Upsert tenant-scoped strategy definitions before the checksum reuse decision. |
| A tenant-scoped strategy reference is missing or repeated in one step | Step concurrency cannot resolve a shared strategy or cannot form a valid slot chain. | Resolve references after the tenant strategy upsert and reject missing or duplicate names. |
| A dynamic run-limit expression uses an unsupported workflow-level path | Registration fails because that path cannot pass per-slot limits to the runtime index. | Use dynamic limits on a supported task or orchestrator concurrency entry. |
| Tenant-scoped concurrency chains use conflicting order | Registration is rejected because the combined slot order could deadlock runs. | Check new chains against existing tenant chains before persistence. |
| Workflow-level concurrency is attached to child steps as well as a DAG orchestrator | A run's child work can contend with its own parent for the same slot and deadlock. | Attach the workflow-level strategy to the orchestrator only when it represents the full run. |
| A version lookup omits tenant ownership | A caller could read another tenant's version data by supplying its ID. | Scope version retrieval to the tenant and verify the workflow relationship at the service boundary. |
| A new version is stored without refreshing trigger or queue views | New runs can use stale schedules or workers can miss a newly created action queue. | Keep trigger updates and scheduler notification coupled to successful registration. |
| A latest-version query includes deleted or cross-tenant rows | Control-plane views can show the wrong definition or triggers for new work. | Filter active versions by tenant and order them by version order. |
| A cron or scheduled trigger is written without synchronizing with latest-version replacement | The trigger can attach to a stale version or resource counts can drift during registration. | Use the shared latest-version lock for trigger writes and update counts in the same transaction. |
| A paused workflow is expected to change state at once | A run or trigger can still follow the old cached pause state for a short time. | Account for cache expiry and reconciliation when changing pause state. |
Key files
| File | Why to read it |
|---|---|
| api-contracts/…/workflows.proto | Defines the workflow-version request, step metadata, concurrency, filters, and idempotency contract. |
| sdks/…/workflow.go | Shows how the Go SDK expresses workflow and task policy before serialization. |
| sdks/…/declaration.go | Shows how declarations become the shared version request and handler mappings. |
| internal/…/server.go | Shows the service boundary that maps, validates, stores, and publishes a new definition. |
| pkg/…/workflow.go | Shows version reuse, tenant-scoped concurrency state, checksum rules, graph checks, persistence, trigger movement, DAG operator setup, latest-version reads, and step metadata creation. |
| pkg/…/workflow_schedules.go | Shows how API cron and scheduled trigger records attach to the latest live version and keep resource accounting aligned with version changes. |
| pkg/…/workflows.sql | Defines the queries that create versions and steps, move trigger links, select the latest active version, summarize latest-version triggers, and enforce tenant-scoped reads. |
| pkg/…/workflows.sql.go | Shows the generated query contracts and fields returned to the repository and engine. |
| pkg/…/workflow_checksum_test.go | Defines the compatibility contract for checksum defaults and workflow concurrency placement. |
| pkg/…/context.go | Shows the workflow, version, step, and run identity available during handler execution. |
| pkg/…/worker.go | Shows how worker registration submits the SDK-produced definition. |
| sdks/…/test_workflow_pause.py | Illustrates the runtime contract for paused runs, trigger policies, cache delay, and unpause reconciliation. |