# How a node runs

> Each step of a run creates a Link Loom worker for the node, activates it in the background and stops it: what the worker receives, what it returns and why no state survives the step.

Source: https://docs.sommatic.ai/en/workflows/lifecycle/node-execution/ (updated 2026-11-26)

The orchestrator that runs workflows is a service built on the [Link Loom SDK](https://docs.sommatic.ai/en/get-started/link-loom.md), and every
node operator (`io.http`, `ai.classify`, `flow.if`…) is a **Link Loom worker**: a class whose lifecycle is driven by a
finite state machine. A run does not call a node as a function; for each step, the engine creates a worker, activates
it and stops it.

### Spawn

A new instance of the node's worker is created for this step only, with its own alias (`step-<node_id>-<time>`). The
state machine receives `CREATE` and the worker enters `INACTIVE`; its `setup` hook runs.

### Activate in the background

`ACTIVATE_BACKGROUND` moves it to `ACTIVE_BACKGROUND` and runs `activateBackground(ctx)` with the node's configuration,
its input (`$json`), the run's variables and the outputs of earlier nodes. The worker resolves the `{{ }}` expressions
of its configuration, does its job and returns the envelope `{ ok, data, port, meta? }`.

### Stop

`STOP` moves it to `TERMINATING` and then to `TERMINATED`, and the instance is removed. The engine stops the worker
whether the step succeeded or failed.

No instance outlives its step: a node keeps no memory between steps or between runs. What one step must pass to the next
travels in its output, which later nodes read with `$json` or [`$('Node label')`](https://docs.sommatic.ai/en/expressions/reference/node-reference.md).

## What the worker receives

`activateBackground(ctx)` receives the context the engine builds for the step. The node's own configuration is spread
at the top of `ctx.options`, next to the run data:

| In `ctx.options`              | What it holds                                                                                       |
| ----------------------------- | --------------------------------------------------------------------------------------------------- |
| The node's configuration keys | Its `config`, as saved in the workflow (expressions not yet resolved)                               |
| `payload`, `input`            | The input of the node: the output of the node that routed to it (`$json`)                           |
| `inputs`                      | When several branches join into the node, the outputs of each one                                   |
| `node`                        | The node definition: `node_id`, `label`, `operator_slug`, `config`                                  |
| `state`                       | The run's variables: the output of every node that already ran, keyed by `node_id`, and the run ids |
| `graph`                       | The outputs of the nodes that already ran, keyed by label, for `$('Node label')`                    |

The worker resolves the `{{ }}` values of its configuration first, then works with real values.

## What the worker returns

Every node returns the same envelope, `{ ok, data, port, meta? }`: `data` becomes the input of the next node, `port`
picks the edge to follow and `meta` carries details for the run history. See [Ports and the envelope](https://docs.sommatic.ai/en/workflows/ports-and-envelope.md).

## Next steps

- [Drafts and versions](https://docs.sommatic.ai/en/workflows/lifecycle/versions.md): From draft to an immutable version, and which mode runs what.
- [Runs and their statuses](https://docs.sommatic.ai/en/workflows/lifecycle/runs.md): The statuses of a run and of its result.
- [Worker state machine](https://docs.sommatic.ai/en/workflows/lifecycle/worker-states.md): Seven states, nine events and the hook each transition runs.
- [When a node fails](https://docs.sommatic.ai/en/workflows/lifecycle/failures.md): Error port or crash, and how each one ends the run.
- [Isolation and sandboxes](https://docs.sommatic.ai/en/workflows/lifecycle/isolation.md): Workers, expression contexts and code sandboxes.
