On this page
Sommatic Docs
Open portal

Read State

Retrieves a persistent value from the workflow state store.

View as Markdown
Open in
Operations Partial ops.state.read Version 1.0.0 Execution: sync

Reads a value by key. The global and case scopes read the workflow key-value state (kv_state); the instance scope always returns miss in the current runtime.

This operator is used to access data saved in previous steps or even from other workflows (using Global/Case scope). It provides a way to maintain context across long-running or distributed executions.

Behavior:

  • Attempts to find the key in the specified scope.
  • If found, returns the value.
  • If not found, triggers the 'miss' port to allow for fallback logic.

Use Cases:

  • Retrieving a cached user profile.
  • Validating if a previous step completed via a state flag.

How it works

  1. Merges the input item with the resolved config (config wins).
  2. Uses scope (default instance) and leaves through error with Missing 'key' when key is empty.
  3. global: looks up <key> in $input.$kv_state. case: looks up case:<key> in the same store.
  4. instance: reads the worker context state, which the runtime does not provide, so the value is always undefined.
  5. An undefined value leaves through miss with { key }; anything else through success with { value }.

In a workflow

The node as it appears in a workflow file (draft_nodes[]), and the envelope of a successful run.

{
  "node_id": "node-read-last-sync",
  "label": "Read last sync time",
  "operator_slug": "ops.state.read",
  "operator_version": "1.0.0",
  "config": {
    "scope": "global",
    "key": "last_sync_at"
  }
}

Configuration

scope string Required

Visibility level to read from (Instance, Case, or Global system-wide).

Default: instance

Allowed values: instancecaseglobal

Its configuration shows the shared execution settings, but this node does not apply retries (retryOnFail, maxTries) yet. continueOnFail is not applied by any node.

Behaviour in the code

What the implementation does with these keys beyond what the schema says.

key
Not in the config schema (only in the input contract), but read from the node config or, when unset there, from the input item: key.
scope
case is not isolated per case: it only prefixes the key with case: in the same per-workflow store as global. global is per workflow, not system-wide.

Output ports

success default

The key exists in kv_state (global or case scope).

Data
{
  "value": "2026-11-25T23:00:00.000Z"
}
miss

The key is not in kv_state, the run received no kv_state, or the scope is instance.

Data
{
  "key": "last_sync_at"
}
error

key is empty. The output is the whole returned object, { port, error }.

Data
{
  "port": "error",
  "error": "Missing 'key'"
}

In expressions

What a later node can read from this node's output with $("Read State").item.json.<path> (write your node's label instead of Read State). Editor marks the paths the workflow editor suggests under Previous Nodes (the output contract); Worker marks the paths the worker really returns through success, from the output shown in Ports.

ExpressionEditorWorker
$("Read State").item.json.valueany= "2026-11-25T23:00:00.000Z"The stored data.

Errors

Message Port Cause and fix
Missing 'key' error key is set neither on the node nor in the input item.

Input contract

key string Required

The unique key of the state variable.

Output contract

value any Optional

The stored data.

Contracts (JSON Schema)

The definition exactly as the orchestrator declares it. All is the whole *.definition.js; compare it with the sections above to spot differences between the documentation and the schema. Use it to validate a node before you publish.

{
  "slug": "ops.state.read",
  "name": "Read State",
  "category": "ops",
  "version": "1.0.0",
  "description": "Retrieves a persistent value from the workflow state store.\n\n  This operator is used to access data saved in previous steps or even from other workflows (using Global/Case scope). It provides a way to maintain context across long-running or distributed executions.\n\n  **Behavior:**\n  - Attempts to find the key in the specified scope.\n  - If found, returns the value.\n  - If not found, triggers the 'miss' port to allow for fallback logic.\n\n  **Use Cases:**\n  - Retrieving a cached user profile.\n  - Validating if a previous step completed via a state flag.",
  "capabilities": [
    "state",
    "persistence",
    "read",
    "store"
  ],
  "config_schema": {
    "type": "object",
    "required": [
      "scope"
    ],
    "properties": {
      "scope": {
        "type": "string",
        "enum": [
          "instance",
          "case",
          "global"
        ],
        "default": "instance",
        "title": "State Scope",
        "description": "Visibility level to read from (Instance, Case, or Global system-wide)."
      },
      "execution": {
        "type": "object",
        "title": "Execution Settings",
        "properties": {
          "alwaysOutputData": {
            "type": "boolean",
            "title": "Always Output Data",
            "description": "Always output data, even on error (if configured).",
            "default": false
          },
          "retryOnFail": {
            "type": "boolean",
            "title": "Retry On Fail",
            "description": "Retry the execution if it fails.",
            "default": false
          },
          "maxTries": {
            "type": "integer",
            "title": "Max Retries",
            "description": "Number of retries.",
            "default": 3,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "waitBetweenTries": {
            "type": "integer",
            "title": "Wait Between Retries (ms)",
            "default": 1000,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "continueOnFail": {
            "type": "boolean",
            "title": "Continue On Fail",
            "description": "Do not crash workflow on error.",
            "default": false
          },
          "timeout_ms": {
            "type": "integer",
            "title": "Timeout (ms)",
            "description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
            "default": 300000
          }
        }
      }
    }
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "key": {
        "type": "string",
        "description": "The unique key of the state variable."
      }
    },
    "required": [
      "key"
    ]
  },
  "output_contract_schema": {
    "type": "object",
    "description": "The retrieved value.",
    "properties": {
      "value": {
        "type": "any",
        "description": "The stored data."
      }
    }
  },
  "ports": [
    {
      "port_id": "success",
      "label": "Found",
      "is_default": true,
      "description": "Value retrieved successfully."
    },
    {
      "port_id": "miss",
      "label": "Not Found",
      "description": "Keys does not exist or has expired."
    },
    {
      "port_id": "error",
      "label": "Error",
      "description": "Storage connectivity error."
    }
  ],
  "execution_mode": "sync",
  "tags": [
    "state",
    "database",
    "persistence",
    "read"
  ],
  "is_stateful": true,
  "publisher": {
    "identity": "org_link_loom",
    "profile": {
      "name": "Link Loom",
      "verified": true,
      "url": "https://me.veripass.com/link-loom",
      "logo_url": null
    }
  }
}

Execution

Execution
sync
Stateful
Yes
Retries (retryOnFail)
No
Capabilities
statepersistencereadstore
Tags
statedatabasepersistenceread

Notes and limits

  • Key-value state lives in the workflow definition metadata (kv_state), shared by every run of that workflow. The backend injects it at run start as $input.$kv_state only when the run uses the draft graph; runs of a published version receive none. Writes (meta.kv_state of each step) are merged into the metadata after the run ends, so later nodes of the same run do not see them. There is no expiry.
  • Values are only written by ops.dedupe, ops.checkpoint and ops.state.write, which all fail in the current runtime, so kv_state only holds what was stored earlier.
  • Leaving through error does not fail the run: the engine follows the edges wired to error, and if there are none the branch simply ends.
  • The execution settings (retryOnFail, maxTries, waitBetweenTries, continueOnFail, timeout_ms) are accepted, but neither this worker nor the engine applies them.

Reviewed against the orchestrator code · 31e874b · 2026-11-26

Install agent tools

Give your coding agent the official Sommatic AI docs: skills, the docs MCP server and Markdown pages, so it never has to scrape the site.

Skills only. They do not update by themselves; run it again to refresh.

npx skills add https://docs.sommatic.ai
How agents read these docs