Worker state machine
The finite state machine of a Link Loom worker: its seven states, the nine events that move it, the hook each transition runs and what a workflow step uses.
Every worker instance, and so every node step, is driven by the WorkerStateMachine of the Link Loom SDK: a
deterministic state machine moved only by commands, with no timers or background loops. Each transition runs one hook
of the worker; if the hook throws, the instance goes to CRASHED.
States
| State | Meaning |
|---|---|
| (none) | Before CREATE: the instance does not exist yet |
INACTIVE | Created and prepared; no active work |
ACTIVE_FOREGROUND | Active with foreground semantics |
ACTIVE_BACKGROUND | Active with background semantics: where a node does its work |
SUSPENDED | Resources released, minimal footprint; can resume |
TERMINATING | Graceful shutdown in progress |
TERMINATED | Final: the instance is removed |
CRASHED | Final: a hook threw during a transition |
Events and transitions
| Event | From | To | Hook it runs |
|---|---|---|---|
CREATE | (none) | INACTIVE | setup |
ACTIVATE_BACKGROUND | INACTIVE | ACTIVE_BACKGROUND | activateBackground |
ACTIVATE_FOREGROUND | INACTIVE | ACTIVE_FOREGROUND | activateForeground |
DEACTIVATE | ACTIVE_* | INACTIVE | deactivate |
SUSPEND | INACTIVE, ACTIVE_* | SUSPENDED | suspend |
RESUME | SUSPENDED | INACTIVE | resume |
STOP | INACTIVE, ACTIVE_*, SUSPENDED | TERMINATING | terminate (skipped with force) |
STOP | TERMINATING | TERMINATED | none |
STOP | CRASHED, TERMINATED | TERMINATED | none: idempotent cleanup |
SIGNAL | any non-final state | the same state | handleSignal |
FAIL | any non-final state | CRASHED | none |
Any other event in any other state is rejected with Invalid transition from "<state>" on "<event>".
A workflow step
A node step uses a short path through the machine, always the same: CREATE, ACTIVATE_BACKGROUND, STOP and STOP again. The figure above plays it, then the same step when its worker crashes, and then the foreground and suspended states the SDK also supports.
If activateBackground throws, the path ends in CRASHED instead, and the cleanup STOP turns it into TERMINATED
without running any hook. Foreground activation, suspension, resumption and signals exist in the SDK but are not used by
workflow nodes.
Rules of the machine
- One instance, one step. The engine never reuses a worker instance: every step starts at
CREATE. - A throwing hook crashes the instance. The state becomes
CRASHED, the error is logged with the transition and thrown again to the engine (see When a node fails). - No retries inside the machine. Retrying is a policy of the node (
executionsettings), not of the state machine. - Every transition is logged as
<worker>:<alias> <from> --<event>-> <to>, which is how a step can be followed in the service logs.
Next steps
From draft to an immutable version, and which mode runs what.
Runs and their statusesThe statuses of a run and of its result.
How a node runsEach node is a Link Loom worker: spawn, activate, stop.
When a node failsError port or crash, and how each one ends the run.
Isolation and sandboxesWorkers, expression contexts and code sandboxes.