Scheduled transitions
A transition with a schedule object fires on its own at a computed time,
driven by a background scheduler, independently of any API call or cascade.
Each armed transition is stored as a task. Tasks are durable: they live in
the storage backend and are armed, re-armed or removed in the same transaction
as the entity write that causes it.
Use a scheduled transition for deadlines and delays that belong to the domain: auto-close a ticket after 24 hours of inactivity, escalate an unpaid invoice at its due date, expire a reservation, or poll an external system on a fixed cadence.
For the rest of the workflow contract, see Workflows and processors.
Two timing modes
Section titled “Two timing modes”Exactly one of delayMs and function is required whenever schedule is
present. The modes differ only in how the scheduled time and the deadline are
determined; everything else on this page applies to both.
Static timing — the same delay for every entity
Section titled “Static timing — the same delay for every entity”delayMs fires the transition delayMs after the entity enters the source
state. In this workflow a ticket closes itself after 24 hours in Open, and a
client can close it earlier with the manual Close transition:
{ "importMode": "REPLACE", "workflows": [ { "version": "1.5", "name": "ticket-lifecycle", "initialState": "Open", "active": true, "states": { "Open": { "transitions": [ { "name": "AutoClose", "next": "Closed", "manual": false, "schedule": { "delayMs": 86400000, "timeoutMs": 600000 } }, { "name": "Close", "next": "Closed", "manual": true } ] }, "Closed": { "transitions": [] } } } ]}delayMs(integer, required in this mode) — milliseconds between source-state entry and the scheduled time. Must be greater than0.timeoutMs(integer, optional) — sets the task’s deadline: the scheduled time plustimeoutMs. It is not a second delay. Absent means no deadline; an explicit0makes the deadline the scheduled time itself. See the deadline.
Per-entity timing — a function callout
Section titled “Per-entity timing — a function callout”When the deadline lives on the entity — an expiresAt field, a per-customer
SLA, a user-chosen reminder — use function, which asks a compute node to
compute the time per entity:
{ "name": "Escalate", "next": "Escalated", "manual": false, "schedule": { "function": { "name": "compute-escalation-time", "resultKind": "Schedule", "calculationNodesTags": "escalation-service", "attachEntity": true, "retryPolicy": "FIXED", "responseTimeoutMs": 10000 } }}name(required) — the registered function name.resultKind(required) — must be"Schedule".calculationNodesTags(required) — comma-separated routing tags, as for a processor or criterion.attachEntity(optional, defaulttrue) — whether the entity payload is attached to the request.context(optional) — a string passed verbatim as the request’sparameters.responseTimeoutMs(optional) — how long to wait for one compute node’s answer.0or absent means the server’sCYODA_CALLOUT_RESPONSE_TIMEOUT_MS; must not exceedCYODA_CALLOUT_RESPONSE_TIMEOUT_MAX_MS.retryPolicy(optional) —NONEorFIXED, as on a processor; absent meansFIXED. A schedule function is always treated as safe to repeat, so after a try that got no answer another compute node is tried.
A schedule function, like a criterion, must have no effects: it may run more
than once for one arm. If it needs the current time, use the CloudEvent time
of the request, which is the platform clock. The compute-node side is in
handling function requests.
The node replies with a Schedule result:
{ "fireAfterMs": 3600000, "expireAfterMs": 600000 }- Fire time (required) — exactly one of
fireAt(absolute, epoch milliseconds) orfireAfterMs(relative to arm time). A pastfireAt, or afireAfterMsof0, is not an error; the transition is due immediately. - Expiry (optional) — at most one of
expireAt(absolute) orexpireAfterMs(relative to the resolved fire time, not to arm time). Both absent means no deadline. A resolved expiry after the fire time becomes the deadline, exactly astimeoutMsdoes.
When the arm happens inside a scheduled run — the fired transition’s cascade
ends in a state with a function-timed schedule — the same failure fails that
run, and the run is retried or ends FAILED under the rules in
Retries and failed tasks.
Import rules
Section titled “Import rules”The import refuses a schedule with 400 VALIDATION_FAILED when:
- both
delayMsandfunctionare present, or neither is. AdelayMsbesidefunctionis refused whatever its value,0andnullincluded; - the transition has
manual: true. A scheduled transition sends"manual": false, as every transition sendsmanual; timeoutMsis negative;delayMsis not greater than0;- a function has an empty
nameorcalculationNodesTags, aresultKindother than"Schedule", aretryPolicyother thanNONEorFIXED, or aresponseTimeoutMsthat is negative or above the server’s bound.
A static delayMs whose scheduled time, or deadline, would fall outside the
Unix epoch through 9999-12-31T23:59:59.999Z is refused when the task is
armed: the write fails with a 5xx and a ticket, and nothing commits.
How the timer behaves
Section titled “How the timer behaves”Arming happens on every settled write. The task is armed when the entity
enters the source state, and re-armed on every later write that leaves it in
that state, including a routine data update or a loopback. Static mode sets the
scheduled time to now plus delayMs; function mode makes a fresh callout. Every
arm starts the task afresh: its attempts, lost owners and last error are
cleared, and a FAILED task is WAITING again.
One owner per run. Every node with CYODA_SCHEDULER_ENABLED=true claims
due tasks from storage and runs them itself. A claimed task is RUNNING under
one node, and every write that node makes for the run is checked against its
claim. A node proves it is alive with a heartbeat; another node takes over its
tasks only after the heartbeats have stopped for CYODA_SCHEDULER_STALE_AFTER
(default 2m). A node that is alive keeps its tasks, even when a run hangs.
One task per entity at a time. While one scheduled transition of an entity
runs, no other scheduled transition of the same entity is claimed. If the first
one moved the entity out of the state, the other task is removed and recorded
as SCHEDULED_TRANSITION_CANCEL.
The criterion is evaluated once, at fire time. A true (or absent)
criterion fires the transition normally: processors run, the state advances,
TRANSITION_MAKE is recorded, and the task is removed. A false criterion
declines it: the entity stays in its state, the task is removed and not
retried, and TRANSITION_NOT_MATCH_CRITERION is recorded. A criterion that
cannot be evaluated — its compute node is down, for example — is a failure,
not false, and is retried.
A scheduled transition cannot be named. Naming one on a save returns
400 TRANSITION_NOT_FOUND:
TRANSITION_NOT_FOUND: transition "AutoClose" in state "Open" is scheduled and fires automatically; it is not manually fireable: transition not foundGET /entity/{entityId}/transitions does not list it. To allow early firing,
give the state an ordinary manual transition alongside the scheduled one, as
Close does above.
The deadline
Section titled “The deadline”The deadline is the scheduled time plus timeoutMs (or the function’s
resolved expiry), on the owning node’s clock. Without one, a task has no
deadline.
- A task with no prior attempt and no lost owner that is first claimed after
its deadline is expired: it is removed without evaluating the criterion,
the transition never fires, and
SCHEDULED_TRANSITION_EXPIREis recorded. - An attempt that fails after the deadline ends the task
FAILEDwithEXPIRED_AFTER_FAILED_ATTEMPTS, the first attempt included. - A task that has already failed an attempt or lost an owner is never expired.
It runs again, unless it is picked up more than
CYODA_SCHEDULER_RETRY_DELAYpast the deadline; then it endsFAILEDwithEXPIRED_AFTER_FAILED_ATTEMPTS, without running.
Retry delays are cut to the deadline, so the last retry is scheduled at or before it.
Retries and failed tasks
Section titled “Retries and failed tasks”A run that failed with nothing unsafe handed to a compute node is retried:
a criterion or function error, no compute node for the tag, a conflict with a
concurrent write, a storage error, a commit refused on a unique key, a failed
idempotent processor, or a processor that provably never reached a compute
node. The task goes back to WAITING with its attempts and last error, and is
tried again after CYODA_SCHEDULER_RETRY_DELAY (default 30s), doubling on
each failure up to CYODA_SCHEDULER_RETRY_DELAY_MAX (default 15m). With a
deadline, retries stop there. Without one, a failing task is retried without
end and stays visible as WAITING.
A processor is never repeated for one arm of a task unless it is
idempotent. Before the owner sends a processor that is not declared
idempotent: true to a compute node, it marks the task. If that processor may
have reached a compute node and the run does not commit — the node failed or
did not answer, a later step failed, or the owner crashed — the task ends
FAILED with UNSAFE_WORK_NOT_COMPLETED and is never run again. Declare
idempotent: true only on a processor that is safe to repeat everywhere it
reaches (see
repeating a processor).
Partial commit. A COMMIT_BEFORE_DISPATCH processor in a cascade step
after the fired transition commits the entity in that step’s state. If the run
stops after such a commit, the task ends FAILED with
STOPPED_AFTER_PARTIAL_COMMIT: the entity has already moved, and running the
transition again from its source state would be wrong. A
COMMIT_BEFORE_DISPATCH processor on the fired transition itself commits the
entity while it is still in the source state, so a safe failure after it is
retried.
Criteria and functions must not trigger unsafe work. They are treated as
safe to repeat and are not marked. One whose callbacks trigger a processor that
is not idempotent is not supported: that processor can run twice.
FAILED tasks
Section titled “FAILED tasks”| Reason | Meaning |
|---|---|
UNSAFE_WORK_NOT_COMPLETED |
A processor not declared idempotent may have reached a compute node and the run did not commit. |
STOPPED_AFTER_PARTIAL_COMMIT |
The run committed the entity into another state, then stopped. |
EXPIRED_AFTER_FAILED_ATTEMPTS |
The deadline passed after a failed attempt or a lost owner. |
OWNER_LOST_REPEATEDLY |
The node running the task was lost CYODA_SCHEDULER_MAX_LOST_OWNERS times (default 3). |
RUN_PANICKED |
The run panicked. The node is taken out of service. |
Treat the reason as an open set and accept a value not listed here. A FAILED
task never moves the entity and is never claimed again. It is kept, and it
shows in GET /scheduled-tasks, in the metrics, in the server log at ERROR with
a ticket, and as a SCHEDULED_TRANSITION_FAIL audit event on the entity.
A FAILED task ends when the entity is written in the source state (the task
is armed afresh), when the entity leaves that state
(SCHEDULED_TRANSITION_CANCEL), when a workflow import stops scheduling the
transition, or when the entity is deleted. There is no separate retry or
dismiss operation: an entity write does both.
Entity writes, deletes and imports
Section titled “Entity writes, deletes and imports”- An entity write re-arms or removes the entity’s tasks in its own
transaction. A task whose transition the selected workflow no longer
schedules from the entity’s current state is removed and recorded as
SCHEDULED_TRANSITION_CANCEL— including when a payload change binds the entity to a different workflow. A loopback that re-arms the same state records onlySCHEDULED_TRANSITION_ARM. - Deleting an entity — singly, by condition, or all of a model’s — removes its tasks with no audit event.
- A workflow import saves the workflows, then removes the model’s tasks whose transition no workflow of the model schedules any more.
A write can answer 409 when it races the scheduler. The scheduler writes a
task when it claims it, commits part of a run, records an attempt, ends it
FAILED or hands it back. A client write that re-arms or removes a task the
scheduler wrote after the write began fails with a retryable 409 CONFLICT, as
does a write that races the fire itself. A delete that owns its transaction and
a workflow import retry on the server, up to three more times, before
answering 409. An entity write that joined another transaction
(X-Tx-Token) is not retried on the server; the transaction’s owner decides at
commit.
Who a scheduled run acts for
Section titled “Who a scheduled run acts for”A scheduled fire runs for the principal whose write armed the task, and is
executed by system. The audit events of the fire record that principal as
actor and system as executedBy. Every callout of the fire carries the
armer in authid and authtype, and system as the executor in authexecid
and authexectype. For an on-behalf-of write, the armer is the user, not the
client that holds the token.
A processor’s callbacks join the run’s transaction, as in any transition, and
so do the callbacks of a schedule.function that the run calls to arm the
state it reaches. None of them writes or deletes the entity being fired.
Listing tasks
Section titled “Listing tasks”GET /scheduled-tasks lists the caller’s tenant’s tasks that still exist:
WAITING, RUNNING or FAILED. A task that fired, was declined, expired or
was cancelled is removed; its outcome is in the entity’s audit trail. Any token
of the tenant with ROLE_M2M may call it.
curl -s "http://localhost:8080/api/scheduled-tasks?entityId=$ENTITY_ID"{ "items": [ { "armedBy": { "id": "mock-user-001", "kind": "service" }, "armedTime": "2026-11-22T22:06:32.368Z", "attempts": 0, "entityId": "f9c40cfe-e6c0-11f1-9698-ae468cd3ed16", "expiresTime": "2026-11-22T22:16:36.368Z", "lostOwners": 0, "modelName": "ticket", "modelVersion": 1, "nextAttemptTime": "2026-11-22T22:06:36.368Z", "scheduledTime": "2026-11-22T22:06:36.368Z", "sourceState": "Open", "status": "WAITING", "taskId": "b8bb41d19c282cdabf500993385c795c", "transition": "AutoClose" } ], "pagination": { "hasNext": false }}Filter with status (repeatable: WAITING, RUNNING, FAILED), modelName,
modelVersion (only with modelName) and entityId; page with limit (1 to
1000, default 20) and the opaque cursor from pagination.nextCursor. A
FAILED task adds failureReason, failedTime and lastError; a task with a
failed attempt adds lastAttemptTime and lastError. See
cyoda help scheduled-tasks for every field.
Audit events
Section titled “Audit events”Arming, firing, expiry, cancellation and failure each record a dedicated event on the entity:
SCHEDULED_TRANSITION_ARM— with the scheduled time;SCHEDULED_TRANSITION_FIRE— alongside the ordinaryTRANSITION_MAKE;SCHEDULED_TRANSITION_EXPIRE;SCHEDULED_TRANSITION_CANCEL;SCHEDULED_TRANSITION_FAIL— with the reason, the attempts and the lost owners.
At fire time, an entity that is already gone, or has otherwise left the source
state, is removed with no audit event. A safe failure that is retried records no
audit event; it shows in the task’s attempts and last error, and in the log at
WARN. See cyoda help audit for the data of each event.
One-shot, or polling?
Section titled “One-shot, or polling?”The criterion is evaluated once per fire; there is no built-in retry-until-true. Three shapes cover the common cases:
- A deadline gate — a criterion on the scheduled transition. At the
deadline, fire if the condition holds, otherwise abandon. A
falsecriterion is a deliberate decline. - A recurring heartbeat — an unconditional scheduled cycle
(
S1 →scheduled→ S2 →scheduled→ S1), which fires everydelayMs, forever, for every entity in the cycle. - Poll until a condition holds — an unconditional scheduled tick into a state whose ordinary (non-scheduled) transitions carry the condition and exit when it is met. The retry loop lives in the workflow structure, not in the timer.
The last two are cycles, and the import rejects a cycle made only of unguarded
automated or scheduled transitions — a delayed cycle is still a cycle. A
single-state scheduled self-loop counts too. Set allowCycles: true on the
import body to accept one. It skips the cycle check only; the cascade limits
still apply at fire time.
This workflow polls a carrier every 15 minutes until a shipment is delivered.
The fetch-carrier-status processor only reads the carrier and returns the
updated delivered field, so it is declared idempotent:
{ "importMode": "REPLACE", "allowCycles": true, "workflows": [ { "version": "1.5", "name": "shipment-tracking", "initialState": "InTransit", "active": true, "states": { "InTransit": { "transitions": [ { "name": "Poll", "next": "Checking", "manual": false, "schedule": { "delayMs": 900000 }, "processors": [ { "type": "externalized", "name": "fetch-carrier-status", "executionMode": "SYNC", "config": { "calculationNodesTags": "carrier", "idempotent": true } } ] } ] }, "Checking": { "transitions": [ { "name": "Arrived", "next": "Delivered", "manual": false, "criterion": { "type": "simple", "jsonPath": "$.delivered", "operatorType": "EQUALS", "value": true } }, { "name": "KeepWaiting", "next": "InTransit", "manual": false } ] }, "Delivered": { "transitions": [] } } } ]}Without allowCycles, the import fails with 400 VALIDATION_FAILED, naming
the loop Checking -> InTransit -> Checking.
Scheduler settings
Section titled “Scheduler settings”| Variable | Default | Purpose |
|---|---|---|
CYODA_SCHEDULER_ENABLED |
true |
A node with false claims no task. |
CYODA_SCHEDULER_SCAN_INTERVAL |
1s |
How often a node claims due tasks. |
CYODA_SCHEDULER_MAX_RUNS |
8 |
Most runs one node holds at once. |
CYODA_SCHEDULER_MAX_RUNS_PER_TENANT |
4 |
Most runs of one tenant on one node. |
CYODA_SCHEDULER_HEARTBEAT_INTERVAL |
15s |
How often a node records that it is alive. |
CYODA_SCHEDULER_STALE_AFTER |
2m |
Silence after which another node takes over a node’s runs. At least 50s + 3 × HEARTBEAT_INTERVAL, and the same on every node. |
CYODA_SCHEDULER_MAX_LOST_OWNERS |
3 |
Lost owners after which a task ends FAILED with OWNER_LOST_REPEATEDLY. |
CYODA_SCHEDULER_RETRY_DELAY |
30s |
First retry delay of a safe failure; doubles on each failure. |
CYODA_SCHEDULER_RETRY_DELAY_MAX |
15m |
Upper bound of the retry delay. |
CYODA_SCHEDULER_SHUTDOWN_DRAIN |
20s |
On shutdown, how long a node waits for its runs before cutting them. |
A value outside its rule fails startup. See the
configuration reference or
cyoda help config scheduler.
Shutdown. A node that shuts down stops claiming and starts no new unsafe
dispatch. It waits CYODA_SCHEDULER_SHUTDOWN_DRAIN for its runs, then cuts the
others: a run that sent nothing unsafe and made no partial commit is handed
back and claimed by another node at once, without counting an attempt; a run
that did ends FAILED. A run with a non-idempotent processor callout in flight
is not cut, and is allowed to finish, so a node can take more than six minutes
to stop. The Helm chart sets terminationGracePeriodSeconds: 390 for this.
See cyoda help run, SHUTDOWN TIMING.
Testing scheduled transitions
Section titled “Testing scheduled transitions”A test does not need to wait for real time. With clock control enabled, a
platform operator can move the platform clock, and each due task fires at its
due time. See
Testing with digital twins and
cyoda help clock.