How the engine runs workflows
What happens between a trigger firing and a run finishing, and what WBSKT guarantees along the way: a run starts once per event, a step that changes the world runs once per attempt, waits survive restarts, and a run always ends.
From an event to a run
Every trigger is an event arriving: a client's message, a client going online or offline, a schedule coming due, a webhook, a run by hand. For each event the engine:
- first wakes any waiting run the event is for, like a Wait for signal or Wait for a call;
- then finds every enabled workflow with a trigger that matches, checks its filter, and works out its correlation key;
- applies the trigger's choice for when a run is going (queue, run both, cancel, skip);
- checks credits and run limits, and starts the run from the live version.
A run is pinned to the version it started on. Publishing a new version doesn't change runs already going.
Paths and steps
A run is one or more paths. Each path runs its steps one after another and carries its own data. Splitting a run makes more paths; a join brings them back to one.
Before each step, the engine charges its credits. After it, the step's result decides what the path does next: follow an output, split, wait, fail, or end. When the last path ends, the run gets its final status.
Up to 50 paths across all runs move at once. More wait their turn, in order.
Waiting
A path that waits, for a delay, a signal, a call, a client's answer or a retry's backoff, is parked: it holds no worker, and what it waits for is written down on the server. A timer checks every second for waits that are due; an event that matches wakes the path at once. Whichever comes first, the event or the timeout, wins, and only once.
Because waits are written down, a run can wait for days, and a restart or a failover loses nothing.
Restarts and failover
Only one engine works at a time, holding a lease it renews every 10 seconds. If it stops, the next engine to start, a standby or the same one restarting, takes the lease once it runs out, within 30 seconds. Before it accepts any new event, it:
- picks up every path that was moving, from the step it was on;
- finishes cancelling or failing runs that were being stopped;
- closes runs whose last path had ended;
- lets waits that came due while no engine ran fire now.
A schedule that came due while WBSKT was down fires once, for the latest time it missed.
Once, not twice
- A run per event. Each trigger's start is keyed by the event, so the same message delivered twice starts one run.
- A step per attempt. A step that changes something (a command, an email, a URL call, a counter) is keyed by its run, path, visit and attempt. If the engine stops mid-step and picks it up again, it gets the stored result rather than doing it again. A loop that visits the same step twice gets two keys, so both visits happen.
- A wake per wait. The event and the timer race to claim a wait; whoever claims it wakes the path, and the other finds nothing.
- An end per path. A path is ended only if it is still live, so two things trying to end it can't both succeed.
Housekeeping
| Every | The engine |
|---|---|
| Second | Fires due waits, schedules, online/offline checks and holds. |
| 10 seconds | Posts what runs spent to the month's credit count. |
| 5 minutes | Fails a path left waiting with nothing to wake it (BOOKMARK_LOST), re-sends a wake that got lost, and ends runs that have nothing left to do once they are 30 minutes old. |
| Hour | Deletes runs past the plan's history, and idempotency keys older than 24 hours. |
What happens when…
- The engine restarts while a URL call is in flight
- The step is run again when the path is picked up. If the call had finished and its result was stored, that result is used instead. A service that must never see a request twice should take an idempotency key from the run.
- The engine restarts during a 2-hour delay
- Nothing changes: the delay ends when it was due to.
- A client answers just as its wait times out
- Only one wins. The path leaves by the answer's output or by timeout, never both.
- A step crashes in a way WBSKT didn't expect
- The step fails with
EXECUTOR_CRASHand a fixed message. The details go to WBSKT's own logs, not to the run's history, which every member can read.
Rules
Final status
| Run when the last path ends | Paths | Final status |
|---|---|---|
| Cancelling, for credits | any | Out of credits |
| Cancelling | some cancelled, some completed | Partly failed |
| Cancelling | otherwise | Cancelled |
| Failing | any | Failed |
| Running | failed and completed | Partly failed |
| Running | only failed | Failed |
| Running | otherwise | Succeeded |
Run statuses in flight: Running, Failing, Cancelling. Path statuses: Active, Waiting, Completed, Failed, Cancelled.
Stopping a run
Cancel moves a run to Cancelling; Fail run, Fail the whole run and fail-fast move it to Failing. Either way its waits are deleted, its waiting paths cancelled, and its child runs cancelled. Moving paths see it at their next step and end Cancelled.
Engine codes
| Code | When |
|---|---|
EXECUTOR_CRASH | A step failed in an unexpected way. |
BRANCH_LOOP_ESCAPED | A path stopped in an unexpected way; it is ended so the run can still finish. |
BOOKMARK_LOST | A path waited with nothing that could wake it, for two 5-minute checks in a row. |
REAPER_TIMEOUT | A run with nothing left to do was ended after 30 minutes. |
History entries
A run's history records RunStarted (without the trigger's data), each step's NodeStarted, NodeCompleted or NodeFailed with its duration and credits, NodeRetrying, a path being parked, resumed or recovered, and RunFinalized. See runs.