Introducing a new way to review your PRs.

Read the announcement

hatchet-dev / hatchet

🪓 An orchestration engine for background tasks, AI agents, and durable workflows

View on GitHub

31 documents · Updated Nov 23, 2026

docs / workflow-orchestration

Workflow orchestration

Hatchet is a durable workflow platform that turns workflow definitions and external intent into tracked work. Its API and SDKs accept workflow versions and run requests. The engine stores state, schedules eligible steps, sends work to workers, and records results so long-running runs can recover and remain visible.

Orchestration model

The orchestration model separates the desired workflow from each execution of that workflow. A workflow version describes the steps, links, triggers, and run rules. A workflow run is one execution with its own input, status, task history, and relationship to parent or child runs.

The platform joins these concepts through durable records and messages:

ConceptRole in orchestration
Workflow definitionDescribes the work that can run.
Workflow versionCaptures the definition used for a run and its step metadata.
TriggerCreates or releases work from an event, schedule, cron rule, webhook, or direct request.
Workflow runTracks one end-to-end execution and its task runs.
Task runRepresents executable step work and its current result or state.
WorkerProvides the registered code that performs task runs.
Scheduler and dispatcherSelect eligible task runs and deliver them to the right workers.

Workflow registration uses a checksum to decide whether the latest version still represents the same workflow shape. Tenant-scoped concurrency definitions are shared tenant policy rather than workflow shape, so their definition values can change in place without creating a new workflow version. The referenced strategy name and its position in a task's concurrency chain remain part of the version shape. Registration also rejects conflicting ordering of shared strategies across workflows because conflicting slot order can block work indefinitely.

When registration creates a new version, the engine also announces the tenant change so event-trigger routing on other engine instances can refresh its workflow view. An unchanged registration does not emit this version-created signal.

Workflow and run lookups also stay inside the caller's tenant. This boundary matters when the engine rebuilds workflow shape or result details for a run, because an identifier alone must not grant access to another tenant's version.

See Workflow definitions and versions for the definition contract and Run dispatch and queue execution for queue state and task selection. See Concurrency controls for shared limits and task-level scheduling policy.

References: pkg/…/workflow.go• L362-678 pkg/…/workflow.go• L704-869 pkg/…/workflow.go• L1759-1779 pkg/…/workflow.go• L1995-2092 pkg/…/workflow_checksum_test.go• L7-156 sdks/…/worker.go• L24-34

Execution lifecycle

The execution lifecycle moves a request from an API or SDK caller to a durable result. A trigger identifies a workflow and supplies input. The engine creates or finds the corresponding run, expands the selected workflow version into task work, applies scheduling rules, and sends each eligible task to a worker. Worker results return through the engine and update the run state, which allows the caller or operator to inspect progress.

Before delivery, the dispatcher prepares the task context that the worker needs. This context can include stored input, parent step output, outputs from durable DAG parents, the durable invocation count, and runtime state. If the dispatcher cannot load that context or send the task, it returns the task to task processing for another attempt. Local assignments use the same delivery rules without a queue round trip.

Assignments are grouped by the dispatcher that owns each worker. The scheduler carries the task retry count with each assignment so the dispatcher can distinguish the assigned attempt from a later attempt on the same worker. A short-lived dispatcher identity cache speeds this routing, while a worker change message updates the cache before its normal expiry.

Workers can report task progress one task at a time or as a batch. The dispatcher turns both forms into the same durable task-processing and monitoring paths. It also delivers batch-start actions and cancellation actions when a workflow uses those controls.

The engine can run these roles together or as separate service roles. Its startup path wires the scheduler, ticker, task controllers, dispatcher, event ingestor, admin services, and gRPC API to shared state and message services. In a combined deployment, the API-facing services can use the local scheduler and dispatcher for direct coordination.

This diagram shows the main path across the API-facing, engine, and worker-facing parts of the system.

flowchart LR
    A[API or SDK request] --> B[Trigger and run creation]
    B --> C[Durable workflow and task state]
    C --> D[Scheduler]
    D --> E[Dispatcher]
    E --> F[Registered worker]
    F --> G[Task result or event]
    G --> C
    C --> H[Run status and history]

The same model supports synchronous waits and asynchronous execution. A caller can wait for a final result or keep a run reference and query status and details later. A run can also create child runs, so parent-child links remain part of the execution record rather than only application-side state.

References: cmd/…/run.go• L602-829 cmd/…/run.go• L804-929 internal/…/dispatcher.go• L555-624 internal/…/dispatcher.go• L714-881 internal/…/server.go• L1041-1164 internal/…/server.go• L1166-1285 internal/…/server.go• L1779-1911 internal/…/server.go• L2291-2498 internal/…/worker_notify.go• L14-74 internal/…/dispatcher_ids.go• L13-64 internal/…/scheduler.go• L518-668 internal/…/scheduler.go• L88-106 sdks/…/workflow.go• L930-1060 sdks/…/runs.go• L16-102

Workflow registration

Workers register workflow definitions before they execute task work. Registration sends the workflow version contract to the platform and records the actions that the worker can perform. This lets the engine match a task action with a live worker while keeping the workflow shape available for scheduling and run tracking.

At the worker-facing boundary, registration also records the worker's action set, services, slot capacity, runtime data, and routing labels. The dispatcher uses this presence and session state to decide whether it can deliver work. Worker capacity can include separate limits for normal and durable task work. Worker labels add routing data for tasks that need a matching execution environment.

The platform registers a workflow version as one transaction. It validates the task graph, stores the version shape, connects its triggers, and creates the task policies used later by scheduling. A single-task workflow places workflow-level concurrency on that task. A workflow with multiple tasks or an on-failure step uses a durable DAG orchestrator task, so the limit applies to the full run. The checksum rules keep equivalent registrations stable while still creating a new version when the executable shape changes.

Tenant-scoped concurrency definitions are updated as tenant policy before the version checksum can reuse an existing workflow version. This keeps shared limits current without changing the version when only the tenant policy values change. A workflow-version lookup requires both the version identifier and tenant, so registration and later engine reads use the same tenant boundary.

After a new version commits, registration invalidates the local event-trigger view and invokes the version-created callbacks. The engine uses that callback to notify other engine instances, so a workflow added or changed on one instance becomes visible to event-key routing across the deployment.

See Worker lifecycle and listener for registration, listener sessions, heartbeats, and result reporting. See Workflow definitions and versions for the definition and version boundary used by application code.

References: pkg/…/workflow.go• L342-452 pkg/…/workflow.go• L704-869 pkg/…/workflow.go• L901-1246 pkg/…/trigger.go• L205-207 pkg/…/trigger.go• L2738-2749 pkg/…/workflow_checksum_test.go• L159-302 sdks/…/worker.go• L10-67 sdks/…/client.go• L416-434 pkg/…/worker.go• L432-441 internal/…/server.go• L34-184 cmd/…/run.go• L141-169

Trigger and scheduling paths

Triggers are the entry paths that turn intent into a workflow run. Direct run calls start work immediately. Event and webhook paths start work from incoming data. Scheduled runs wait for a time. Cron triggers create recurring run opportunities. The ticker refreshes time-based records and publishes work when their trigger time arrives.

The API treats a cron trigger as a tenant-scoped schedule that must be valid before it enters durable state. Creation resolves the workflow in the tenant, validates the cron expression before storage, and accepts supported descriptor forms such as @daily. The create, update, and delete paths publish a tenant cron-refresh message after the database change so the ticker can refresh its view. If publication fails, the API logs the error while the stored schedule remains the source of truth for a later refresh.

The trigger path preserves workflow input, metadata, and priority as the request moves into the durable run record. The scheduler then considers worker availability, requested slot capacity, concurrency, rate limits, worker affinity, priority, and pause state before it assigns task work. A durable task can also trigger child runs or wait for sleep and user-event conditions. The engine starts the ticker and scheduler only for the configured service roles, so a deployment must provide the roles needed by its trigger and dispatch path.

Schedule and cron records remain tenant-scoped resources that can be listed, changed, disabled, or removed. Their resource counts follow the enabled records on the latest live workflow version. Registration moves API-created cron and scheduled triggers to the new version, creates the new version's default cron references, and removes old default references. This prevents repeated registration from creating extra recurring work while preserving API-created schedules.

Event-key routing uses the current workflow version view for a tenant. A committed version change invalidates that view on the creating engine and sends a version-created notice for other engines to process, which keeps event delivery aligned with registration across the control plane. Concurrent cache fills use an invalidation generation so a lookup started before the change cannot restore stale routing data.

Trigger pathOrchestration result
Direct invocationCreates a run for immediate scheduling.
Event or webhookConverts an external event into a matching run request.
Scheduled runHolds one run until a specified time.
Cron triggerProduces recurring scheduled run requests.
Durable child triggerCreates a child run and releases the waiting durable task when its result is ready.

See Triggers and scheduling for the trigger-specific rules and delayed work behavior.

References: api/…/create_cron.go• L19-91 api/…/create_cron_test.go• L53-90 api/…/update_cron.go• L16-42 api/…/delete_cron.go• L15-36 sdks/…/schedules.go• L19-101 sdks/…/crons.go• L25-109 internal/…/ticker.go• L142-205 pkg/…/workflow_schedules.go• L245-324 pkg/…/workflow_schedules.go• L335-400 pkg/…/workflow_schedules.go• L761-954 pkg/…/workflow.go• L1162-1246 pkg/…/workflow_cron_cleanup_test.go• L75-170 internal/…/server_v1.go• L1041-1285 pkg/…/scheduling.go• L13-64 pkg/…/trigger.go• L2680-2749 cmd/…/run.go• L141-169

Queue and dispatch coordination

The scheduler is the engine component that turns durable task state into assignments. It consumes scheduler messages, evaluates which task runs are ready, and sends assignments to the dispatcher associated with the selected worker. The dispatcher then delivers actions over the worker connection and carries task results or control actions back into the engine.

Scheduler partitions provide durable ownership for tenant scheduling work. When a partition becomes stale, rebalancing can release its tenants and assign them again. The replacement partition must restore wake-up delivery, so newly queued tasks do not wait for a backed-off queue poll before assignment.

Each tenant has a scheduling pool that matches queue items to registered workers. The pool keeps an in-memory view of worker capacity and task actions, then refreshes that view from durable state. Assignment can require several slot types and units. Worker labels and sticky rules narrow or rank candidates, while concurrency and rate limits can hold work even when a worker has capacity. The scheduler reports these outcomes separately so the queue can retry, delay, move, or complete each item correctly.

The scheduler groups remote assignments by dispatcher identity and sends each group to that dispatcher's queue. It learns a worker's dispatcher from durable worker state when needed. A worker registration or listener move publishes a tenant-scoped update so the scheduler can replace the cached identity. If no dispatcher exists, the scheduler removes that worker from its local pool and retries the task instead of sending work to an unknown queue.

Batch-enabled tasks use a separate queue path. The scheduler moves eligible items into the batch queue instead of consuming an individual worker slot. A later batch assignment obtains capacity for the batch and the dispatcher delivers the grouped work. This keeps per-task rate-limit decisions separate from the worker capacity used to run the batch.

The dispatcher registers its own durable identity, maintains a heartbeat, and consumes its dispatcher-specific queue. For an assignment, it loads the task input and related parent or durable-event data before trying the active worker sessions. It can resolve parent outputs for ordinary steps and durable DAG children before delivery. Delivery can also reach operator-backed worker entries that the dispatcher mirrors from the operator manager. Local assignments use the same preparation and delivery rules without waiting for a queue round trip.

If delivery fails, the dispatcher requeues the task through the task-processing path. Batch-start actions are sent only after the dispatcher has assembled the batch item payload. Cancellation actions use the worker session that owns the task. When a concurrency decision releases a task that is already running, the scheduler uses the worker captured in that decision to send cancellation directly to its dispatcher. These paths keep worker actions tied to the durable task and retry state.

Dead-letter handling gives delivery failures a repair path. Failed assignment and cancellation messages return to task processing or are routed again after a fresh worker-to-dispatcher lookup. Undelivered durable callbacks use delayed redelivery with a bounded retry count, which gives a reconnecting worker time to restore its session without creating an endless message loop.

The design keeps durable state separate from delivery state. A queue or stream can be retried, delayed, or dead-lettered without losing the run record that explains what happened. The task controller handles repair work such as timeouts, sleeps, retries, reassignments, paused work, and recovery of evicted orchestration state. The task repository applies these changes in bounded transactions, including batch-wide timeout handling and durable sleep release, so the engine can process large sets without losing the task state that drives later dispatch.

See Run dispatch and queue execution for assignment, lease, retry, cancellation, and state transition details. See Concurrency controls for the limits that can delay assignment.

References: pkg/…/scheduling.go• L13-64 pkg/…/scheduler.go• L29-102 pkg/…/scheduler.go• L396-565 pkg/…/scheduler.go• L872-1094 pkg/…/scheduler.go• L1134-1344 internal/…/dispatcher_ids.go• L13-64 internal/…/scheduler.go• L229-451 internal/…/scheduler.go• L522-673 internal/…/scheduler.go• L938-1070 internal/…/scheduler.go• L1400-1673 internal/…/dispatcher.go• L354-463 internal/…/dispatcher.go• L497-535 internal/…/dispatcher.go• L555-624 internal/…/dispatcher.go• L639-706 internal/…/dispatcher.go• L714-1063 internal/…/worker_notify.go• L14-74 internal/…/scheduler.go• L88-175 internal/…/subscribed_worker_v1.go• L25-70 internal/…/controller.go• L38-73 pkg/…/task.go• L1573-1869 internal/…/partition_recreate_test.go• L60-125

Durable execution

Durability means the engine can preserve workflow progress across delays, worker loss, and service restarts. A durable task can pause for time or an external event. The dispatcher records durable event conditions and later sends completed signal data back to the listening worker session. Recovery controllers restore or requeue work when the normal execution path cannot finish it.

The task controller also repairs a narrow recovery gap for durable DAG orchestrators. It scans tenant-scoped windows of runtimes that have stayed evicted past a grace period, finds orchestrators whose durable event entries are all satisfied, and publishes a restore message. A per-tenant cursor moves through the ordered windows, so the periodic pass can cover large runtime sets without repeatedly scanning the same rows. This catches lost callbacks and prevents a ready DAG from remaining evicted forever.

Durable task sessions can run over the worker-facing gRPC stream or through an in-engine channel used by operators. Both paths share task registration, asynchronous response routing, acknowledgements, ordered completion delivery, stale-invocation checks, and cleanup behavior. An operator session can be evicted when it is blocked on unsatisfied durable events. A stalled ordered completion can also cause eviction so the task can restart rather than wait forever.

The dispatcher treats a missing active durable invocation as a recoverable delivery condition. It returns that condition to the queue so a reconnecting worker can receive the completion later instead of leaving the workflow run in a permanent running state. It also checks invocation identity before applying eviction or worker-status updates. It can combine repeated timeout extensions for one task before applying them to durable state. This keeps durable progress in the engine while the worker session remains replaceable.

Durable child runs use the same state model. A trigger records the child relation and its event-log entry. Pending child work is published before the worker receives its acknowledgement. DAG child work stays pinned to the original workflow version, and a child that needs replay returns to task processing rather than creating a second application-side state path.

Terminal task handling extends this model to the workflow boundary. Completed, failed, and cancelled orchestrator tasks update monitoring state only when the current attempt is terminal. If an orchestrator is cancelled after losing its worker, the controller also cancels unfinished children so the parent cannot finish while child work remains active.

This behavior makes a workflow more than a chain of remote calls. The stored run and task state is the source for status, retry, replay, cancellation, and later recovery. The worker performs application code, while the engine owns the decisions needed to continue the workflow.

References: internal/…/dispatcher.go• L497-535 internal/…/server_v1.go• L336-558 internal/…/server_v1.go• L566-844 internal/…/server_v1.go• L1041-1164 internal/…/server_v1.go• L1166-1285 internal/…/server_v1.go• L1339-1673 internal/…/server_v1.go• L1675-1777 internal/…/server_v1.go• L1779-1911 internal/…/controller.go• L604-790 internal/…/controller.go• L792-1125 internal/…/restore_evicted_orchestrators.go• L16-78 pkg/…/task.go• L2069-2159 pkg/…/tasks.sql.go• L1494-1562

Run tracking and control

Run tracking gives callers and operators a durable view of workflow progress. The run API exposes lists, status, details, streaming updates, replay, and cancellation. A run reference supports a wait-for-result path without requiring the caller to own task state or keep a process alive.

The run list can distinguish ordinary running work from evicted work and work that is still on a worker. It also supports tenant-scoped metadata filters and lets callers choose whether task input and output payloads are returned. The API assembles DAG runs with their task summaries, while task-only views support direct inspection of executable work. These choices let operators search execution state without changing the underlying run record.

The dispatcher also supports long-lived workflow-run subscriptions. It reads finalized run state, sends terminal results, and tracks acknowledgements so a client can receive a result after a delivery attempt fails. Its event path keeps streamed task events in order for each step. It holds the run's final signal until relevant stream data has had time to arrive, then releases the signal when the stream is complete or its wait limit is reached. Oversized result data is reduced when possible so the terminal event can still cross the stream boundary.

Durable streams persist ordered messages by tenant, namespace, and topic. Publishers provide a producer sequence so retries do not duplicate stored messages and skipped sequence numbers are rejected. Subscribers can start at the topic head or resume from a retained cursor. A shared topic poller serves long-lived subscribers and can release idle streams; a reconnecting client resumes from its last cursor.

Large stream payloads can use a tenant-scoped payload side channel. An entitled caller uploads a payload and receives a reference. An authorized reader later resolves that reference through the API. This keeps stream control events small while preserving access checks and tenant ownership for the larger data.

The dispatcher can subscribe to one run or to runs selected by additional metadata. A run subscription binds to the tenant event stream before it finishes the initial run lookup. This prevents events published during that lookup from being lost. If the run is already terminal, the subscription emits a terminal signal and closes its stream.

External run details rebuild the task view from the tenant-scoped task graph. For a DAG orchestrator, the repository adds its durable children, loads the matching workflow version shape, and combines finalized task results with the run input and metadata. The workflow version lookup uses both the version identifier and tenant, which keeps result assembly inside the run owner's tenant.

The platform also links run state to observability. Run and workflow identifiers pass through SDK and engine context so logs and traces can connect task activity to the full workflow execution. Tenant-scoped Prometheus federation can expose these signals to monitoring systems when the tenant has the required entitlement and the server has a federation endpoint.

See Run dispatch and queue execution for task control details. See Worker lifecycle and listener for worker-facing streams. See Concurrency controls for scheduling limits.

References: api/…/list.go• L21-42 api/…/list.go• L103-250 api/…/list.go• L253-395 api/…/payload.go• L19-110 api/…/get_prometheus_metrics.go• L16-70 api/…/workflow.go• L40-177 internal/…/server.go• L29-205 internal/…/server.go• L218-315 internal/…/server.go• L318-361 sdks/…/runs.go• L41-150 pkg/…/task.go• L5112-5163 internal/…/server.go• L512-650 internal/…/server.go• L721-1119 internal/…/server.go• L1121-1327 internal/…/server.go• L2291-2498 sdks/…/attributes.go• L21-40

System boundaries

The orchestration system has four useful boundaries for an engineer to keep in mind. The API and SDK boundary accepts definitions and run intent. The durable state boundary records workflow and task progress. The engine boundary makes scheduling and recovery decisions. The worker boundary runs application actions and reports their outcomes.

The API boundary also controls which parts of run state a tenant member can read or change. Viewer access includes run and task inspection, while run creation, cancellation, replay, and stream payload upload require member-level permissions. Payload viewing is a separate permission and entitlement path. This keeps execution control and potentially sensitive task data separate from basic status visibility.

The engine startup path connects these boundaries through shared repository and message services. The dispatcher is the main worker-facing bridge: it receives assignments from the engine, prepares task context, manages worker and operator sessions, turns single or batched worker events into durable task updates, and serves durable task and run subscriptions. Its startup path creates a durable dispatcher identity, starts heartbeat and operator coordination, and consumes a dispatcher-specific queue. Its shutdown path stops queue intake and drains active delivery before it closes worker-facing streams and removes its durable engine identity.

Workflow version creation also crosses engine instances through the control plane. The creating engine invalidates its tenant event-trigger view and publishes a tenant-scoped version-created notice. Other engines consume that notice and invalidate their own views, so event routing does not depend on which engine handled registration.

Changes at one boundary can affect the next boundary through workflow contracts, run identifiers, task action names, trigger payloads, durable invocation counts, parent outputs, dispatcher identities, assignment retry counts, worker listener messages, and workflow-version change notices. Tenant identity is also part of the repository contract for workflow-version, stream, and run-detail reads. Use the child pages for the detailed contract at each boundary:

This diagram shows how request intent becomes durable state, engine decisions, worker activity, and observable run results.

flowchart TB
    API[API and SDK boundary] --> STATE[Durable state boundary]
    STATE --> ENGINE[Engine boundary]
    ENGINE --> WORKER[Worker boundary]
    WORKER --> STATE
    ENGINE --> OBS[Run status and observability]
    STATE --> OBS

References: api/…/rbac.yaml• L18-109 api/…/rbac_test.go• L26-117 api/…/run.go• L60-117 api/…/run.go• L234-261 api/…/run.go• L733-815 pkg/…/workflow.go• L256-320 pkg/…/workflow.go• L704-869 pkg/…/shared.go• L64-72 pkg/…/trigger.go• L195-207 pkg/…/trigger.go• L2680-2749 cmd/…/run.go• L141-169 cmd/…/run.go• L762-985 internal/…/dispatcher.go• L43-100 internal/…/dispatcher.go• L354-463 internal/…/server.go• L34-126 internal/…/server.go• L188-496 internal/…/server.go• L1693-2094 internal/…/worker_notify.go• L14-74 internal/…/dispatcher_ids.go• L13-64 internal/…/scheduler.go• L518-668 internal/…/server.go• L29-315 sdks/…/runs.go• L41-150

Change checklist

When these files or sections are changed, remember to consider these:

  • A change to workflow version fields can alter the definition checksum or the data sent to the engine. Check the SDK dump, repository validation, checksum normalization, and engine-facing contract together.
  • A change to tenant-scoped concurrency definitions must preserve the split between tenant policy and workflow shape. Check the transactional upsert, checksum exclusion rules, task references, and ordering validation together.
  • A change to task action names or worker labels can stop an otherwise valid task from being assigned. Check registration, scheduler matching, and dispatcher action delivery together.
  • A change to trigger input, metadata, priority, or namespace handling must stay aligned across direct runs, scheduled runs, cron runs, external trigger paths, and durable child triggers.
  • A change to cron expression validation must stay aligned with the ticker parser. Check that supported descriptor forms remain accepted and invalid expressions are rejected before storage.
  • A change to cron create, update, or delete behavior must preserve both the tenant-scoped database mutation and the tenant cron-refresh message that updates the ticker's view.
  • A change to workflow-version creation must preserve the post-commit event-key invalidation and the version-created notice. Check local invalidation, cross-engine publication, subscription, and tenant scoping together.
  • A change to event-trigger cache fill or invalidation must preserve the invalidation generation. A lookup that began before a version change must not repopulate the cache with the old workflow set.
  • A change to run or task identifiers must preserve the links used by dispatch messages, worker context, parent-child runs, status queries, durable invocation routing, and telemetry.
  • A change to dispatcher assignment routing must preserve the worker-to-dispatcher update message, the scheduler cache fallback lookup, assignment retry counts, and the queue selected for each dispatcher.
  • A change to worker listener activation or heartbeat handling must preserve the session ownership rule. An old stream must not deactivate a newer stream, and a stale stream must not cause in-flight work to be reassigned too early.
  • A change to assignment payload loading must preserve durable invocation counts, runtime state, parent output resolution, and DAG parent output resolution before worker delivery.
  • A change to scheduler replenishment or assignment acknowledgements must preserve the reconciliation between in-memory capacity and durable slot state. A refresh must not lose unacknowledged assignments or strand work that missed during a refresh.
  • A change to scheduler partition ownership or wake-up subscriptions must preserve tenant reassignment after stale partitions are removed. A recreated partition must still receive wake-ups for newly queued work.
  • A change to batch configuration or batch queue routing must preserve the split between per-task rate-limit reservations, batch-queue movement, batch capacity, and dispatcher batch payload delivery.
  • A change to concurrency cancellation must preserve the worker identity captured when an in-progress runtime is released. The task controller may no longer be able to resolve that worker after the release transaction.
  • A change to dead-letter handling must preserve fresh dispatcher lookup, callback backoff, the durable callback redelivery cap, and the fallback recovery paths after the cap.
  • A change to workflow-run streaming or durable stream cursors must preserve acknowledgement tracking, producer ordering, cursor retention, tenant ownership, entitlement checks, payload limits, and final-event delivery when clients or workers disconnect.
  • A change to durable task sessions or ordered completion handling must preserve invocation registration, stale-session eviction, response ordering, duplicate handling, and cleanup for both gRPC and in-engine channel paths.
  • A change to durable child-run triggering must preserve the original workflow version, parent links, child index, replay behavior, and the publish-before-ack rule.
  • A change to workflow-version lookup or external run-detail assembly must preserve tenant scoping for both the version identifier and the task or run records being read.
  • A change to service roles or local scheduler and dispatcher wiring must preserve the path used by API trigger writes and the cleanup order used by long-lived streams.

Important failure modes

TriggerConsequenceGuard
An invalid cron expression reaches durable schedule storageThe ticker can reject or remove the schedule instead of creating recurring runsValidate the expression in the API before storage and keep validation aligned with the ticker parser.
A cron database change succeeds but its refresh message is not publishedThe ticker can keep a stale schedule view until a later refreshPersist the change first and publish the tenant refresh message on every create, update, and delete path.
A new workflow version is created without invalidating event-key views on all engine instancesAn event can use an old workflow list and miss the new versionInvalidate locally after commit, publish the tenant version-created notice off the registration request, and invalidate on every subscribed engine.
A concurrent event lookup repopulates the cache after a version changeNew events can route by an old workflow set until the cache expiresCompare the invalidation generation before storing lookup results.
A version-created notice is published before the version transaction commitsAnother engine can refresh its view before the new version is readableInvoke the version-created callback only after the version transaction commits.
A scheduler partition is recreated without restoring wake-up ownershipNewly queued work can wait for the backed-off queue poll instead of starting promptlyReassign the tenant to the recreated partition and preserve its wake-up subscription.
A scheduler uses a stale or missing worker-to-dispatcher identityAn assignment goes to the wrong queue or is held without deliveryApply worker-dispatcher change messages, use the short cache only as a fallback, and remove workers with no durable dispatcher from the scheduling pool.
A worker listener disconnects during deliveryThe task may need reassignment and the worker must no longer receive new workListener cleanup removes the session. Session-scoped deactivation prevents an older stream from changing the state of a newer stream.
A worker sends a heartbeat while its listener stream is inactiveThe engine sees process liveness but does not route new work to a streamless workerRecord the heartbeat first, then reject the heartbeat when the listener is inactive. Keep reassignment tied to the last heartbeat rather than the stale stream alone.
An assignment retry count is missing or belongs to a later attemptA dispatcher can deliver or accept an outdated attempt on the same workerCarry retry counts with task IDs and use them to filter assignment data before delivery.
A worker has no free slot of a required type or cannot satisfy a multi-unit requestThe queue item remains unassigned until capacity is restored or its scheduling timeout endsReplenish tenant scheduling pools from worker capacity and retry only when the requested capacity can be considered again.
A dispatcher cannot load task input or required parent outputThe assignment is not sent and the task is requeued for a later attemptKeep task, payload, parent-output, DAG-output, runtime, and durable-event reads on the retry path.
A batch action contains an unknown or malformed task external IDThe batch is rejected and none of its task events are appliedParse and resolve all external IDs before publishing the batch messages.
A concurrency flush releases an in-progress task before its cancellation reaches the workerThe old worker can continue application work after the engine has released the runtimeRoute cancellation with the worker ID captured by the concurrency result before relying on the normal task-cancel path.
A durable callback has no active worker sessionThe callback can loop between the dispatcher and dead-letter queue or remain pendingDelay redelivery, cap the number of attempts, and rely on session re-registration, reassignment, or reconciliation after the cap.
Durable event delivery loses its stream before acknowledgementA completed signal can remain pending for later deliveryPersist the signal match and retry delivery until the worker acknowledges it.
A durable run trigger is persisted but its follow-up task-processing message is not publishedThe durable task can wait forever for its child runPublish the follow-up message before sending the durable trigger acknowledgement.
An orchestrator is cancelled after its worker is goneIts unfinished children can remain active with no parent able to completeCancel unfinished children in batches when the released orchestrator has no worker.
A workflow-run stream receives a terminal signal before late stream chunksThe client can see completion before all task output chunksBuffer out-of-order chunks and delay the terminal signal until the quiet period or maximum wait expires.
A stream publisher skips a producer sequence numberThe stream rejects the write and the topic does not contain the intended ordered messageRequire contiguous producer sequences and treat repeated stored sequences as retries.
A subscriber resumes with an invalid or expired cursorThe subscriber cannot continue from the requested pointValidate the cursor address and tenant, then check that the cursor is still retained before joining the topic poller.
A stream payload upload has no durable-stream entitlement, no payload part, or too much dataThe payload is rejected and no reference is returnedCheck tenant entitlement, require the payload part, enforce the maximum size, and meter the tenant's stream message limit.
A durable task response comes from an older invocationA stale worker can receive or cause state changes for a replaced executionCompare the worker invocation count with the current durable count and send an eviction notice to stale sessions.
A DAG child is triggered against a newer workflow versionA mid-run deployment can change the child step that the parent expectsPin the child trigger to the parent DAG's workflow version.
A dispatcher shuts down without draining streams and queue workResults or assignments can be interrupted and the engine can retain stale delivery stateCancel long-lived streams, stop queue intake, drain active workers and operators, and remove the dispatcher record during cleanup.
A workflow version or DAG shape is read with an identifier from another tenantRun details or workflow data could cross a tenant boundaryPass the tenant with every workflow-version lookup and keep task, run, and stream reads tenant-scoped.

Key files

FileWhy to read it
cmd/…/run.goShows how the engine assembles scheduler, controllers, dispatcher, API, and trigger services and how it synchronizes workflow-version changes across engine instances.
sdks/…/workflow.goShows the user-facing split between defining a workflow and starting or waiting for a run.
sdks/…/worker.goShows how workflows, capacity, and routing labels enter a worker configuration.
pkg/…/workflow.goDefines the durable workflow version shape, checksum contract, tenant-scoped concurrency policy, trigger rollover, post-commit version notification, and tenant-safe version reads.
pkg/…/shared.goShows the tenant-scoped event-trigger view and the coordination state used when workflow versions invalidate it.
pkg/…/trigger.goShows how event-trigger workflow views are populated, invalidated, and kept tenant-scoped during concurrent version changes.
pkg/…/workflow_checksum_test.goProtects backward-compatible checksum behavior and the placement of workflow concurrency in single-task and DAG workflows.
pkg/…/trigger_event_workflows_test.goProtects event-trigger workflow refresh behavior after workflow-version creation.
pkg/…/workflow_schedules.goShows how scheduled and cron trigger records are created, changed, counted, and tied to the latest workflow version.
pkg/…/workflow_cron_cleanup_test.goProtects the rule that default cron references do not accumulate across versions while API-created crons move forward.
api/…/create_cron.goShows the API boundary for tenant cron creation, input validation, cron expression validation, persistence, and ticker refresh notification.
api/…/create_cron_test.goProtects the contract that invalid cron expressions are rejected before storage while supported descriptors are accepted.
api/…/update_cron.goShows how a cron enable change is persisted and sent to the ticker refresh path.
api/…/delete_cron.goShows how cron removal is persisted and sent to the ticker refresh path.
internal/…/ticker.goShows the time-based trigger service that refreshes schedules and emits due work.
pkg/…/scheduler.goShows tenant worker-capacity refresh, slot-aware assignment, affinity, rate-limit outcomes, batch routing, and retry timing.
internal/…/scheduler.goShows the engine boundary that selects task work, resolves dispatcher identities, routes assignments, repairs dead-lettered delivery, and signals cancellation.
internal/…/dispatcher_ids.goShows the short-lived worker-to-dispatcher cache and its durable lookup fallback.
internal/…/dispatcher_ids_test.goProtects cache replacement, miss handling, duplicate filtering, and lookup failure behavior.
internal/…/partition_recreate_test.goShows that tenant scheduling survives partition recreation and that queued work still starts from wake-up delivery.
internal/…/scheduler.goDefines assignment retry counts and worker or dispatcher notification messages shared by scheduler and dispatcher.
internal/…/dispatcher.goShows dispatcher identity, queue intake, task context preparation, worker and operator delivery, batch actions, retry, and shutdown.
internal/…/server.goShows worker registration, session-safe listener state, heartbeats, task events, run subscriptions, and connection cleanup.
internal/…/worker_notify.goShows how worker availability and dispatcher changes reach the tenant scheduler partition.
internal/…/server_v1.goShows durable event registration, durable task sessions, child-run triggering, ordered responses, replay, cancellation, and eviction.
internal/…/controller.goShows the repair and maintenance role for timeouts, retries, sleeps, reassignment, terminal orchestration events, child cancellation, and evicted-orchestrator recovery state.
pkg/…/task.goDefines durable task completion, recovery, timeout, sleep, eviction, replay, stream payload storage, and tenant-scoped run detail reads.
internal/…/server.goShows durable stream publication, producer ordering, cursor-based subscription, entitlement checks, and idle stream handling.
sdks/…/runs.goShows the client view of run status, details, replay, and cancellation.
api/…/list.goShows how API run filters map to durable run and task status, DAG summaries, metadata filters, and payload visibility.
api/…/payload.goShows the API boundary for large durable stream payload references and tenant-scoped reads.
api/…/rbac.yamlShows which tenant roles can inspect runs, control execution, and use stream payload endpoints.
api/…/run.goShows API service assembly, route registration, tenant lookup, authentication, authorization, and request middleware.