# Flow State

Source: https://openflow.run/en/docs/concepts/flow-state/
Language: en
Product version: 0.1.0-beta.77

Store explicitly written business values across Runs without changing the workflow definition.

Flow State stores business values explicitly written by Code. Values belong to a Flow and its execution source, `draft` or `live`. Draft testing therefore has a separate state scope from production execution.

## Read and write values

```javascript
export default async function (inputs, context) {
  const previous = await context.state.get("lastProcessedId");
  await context.state.set("lastProcessedId", inputs.id);
  return { previous };
}
```

`get` returns an independent JSON value or null. `set(key, null)` deletes the value. `insert` writes only when a key is absent, `delete` removes a key, and `list` returns sorted keys.

Keys contain 1–256 UTF-8 bytes. Values must be JSON. The deployment owns quotas; read its reported limits instead of assuming unlimited storage.

## Write timing

Writes persist immediately as side effects. A later Task failure or canceled Run does not roll them back. Publishing, rolling back, or editing a Revision does not copy or reset State.

State is separate from arbitrary node results, Variables, and Run logs. Use it for explicit business state, not as a secret store or an implicit channel to every past invocation.

## Inspect and clear

Use the deployment’s Flow State management interface and select `draft` or `live` explicitly. Clearing Live immediately affects later production executions. Inspect the scope and business consequences before clearing it.

See [Code](https://openflow.run/en/docs/nodes/code/index.md) for runtime capabilities and [technical contracts](https://openflow.run/en/docs/reference/contracts/index.md) for exact limits and management methods.

## Sources

*   [docs/architecture.md](https://github.com/oomol-lab/open-flow/blob/e25a738d170322734572a0b8a1323cb00b9d355a/docs/architecture.md#flow-state)
*   [docs/control/contracts/nodejs-runtime.md](https://github.com/oomol-lab/open-flow/blob/e25a738d170322734572a0b8a1323cb00b9d355a/docs/control/contracts/nodejs-runtime.md#flow-state-engine-v10)
*   [docs/control/contracts/control-api.md](https://github.com/oomol-lab/open-flow/blob/e25a738d170322734572a0b8a1323cb00b9d355a/docs/control/contracts/control-api.md#flow-state)
