Skip to main content

Durable state

StateAction

A persistent state operation. State is durable key/value used for things like polling cursors, dedupe sets, idempotency keys and counters — distinct from var:: variables, which are read-only config/secrets.

It is backed by a pluggable backend selected by deployment: in-memory (local single-node, ephemeral), Postgres (durable/shared, BYO via global.databases), or the AirPipe backend (managed). Redis is a planned backend.

Read state inline anywhere interpolation runs with a|state::KEY| or a|state::NAMESPACE.KEY|. The default namespace is the config name.

Example — read a cursor, fetch since it, advance it

actions:
- name: Cursor
state:
get:
key: last_seen
default: "1970-01-01T00:00:00Z"
- name: Fetch
http:
url: "https://api.example.com/items?since=a|state::last_seen|"
- name: SaveCursor
state:
advance:
key: last_seen
value: a|Fetch::max_updated_at|

One of:

  • getStateGet — Read a value by key. Output: { "value": <v>, "version": <n>, "found": <bool> }. Returns default (or null) when the key is absent or expired.
  • setStateSet — Upsert a value. Last-write-wins unless expected_version is set (optimistic concurrency — the write fails with a conflict if the stored version differs). Output: `{ "version":…
  • advanceStateSet — Monotonically advance a cursor: stores max(current, value). Numeric values are compared numerically; otherwise lexically (works for ISO-8601 timestamps). Never moves a cursor…
  • deleteStateGet — Delete a key. Output: { "deleted": <bool> }.
  • seenStateSeen — Check-and-add an id to a bounded dedupe set. Returns whether the id was new (i.e. not seen before). Output: { "was_new": <bool> }.

StateGet

FieldTypeDescription
keystringRequired. State key.
namespacestring (nullable)Optional namespace. Defaults to the config name.
defaultanyValue to return when the key is absent or expired.

StateSet

FieldTypeDescription
keystringRequired. State key.
valueanyRequired. Value to store.
namespacestring (nullable)Optional namespace. Defaults to the config name.
ttlstring (nullable)Optional time-to-live, e.g. "1h", "30m", "7d". Omit for no expiry.
expected_versionnumber (nullable)Optimistic concurrency: only write when the stored version matches this value. Use 0 to require the key not to exist yet. Ignored by advance.

StateSeen

FieldTypeDescription
keystringRequired. Key identifying the dedupe set (e.g. the trigger/source name).
idstringRequired. The id to check and record (e.g. a record id or content hash).
namespacestring (nullable)Optional namespace. Defaults to the config name.
ttlstring (nullable)Optional time-to-live for the set, e.g. "7d".