# Wait / Delay

> Pauses the execution flow for a specified duration or until a specific timestamp.

Source: https://docs.sommatic.ai/en/nodes/flow.wait/

- Slug: `flow.wait`
- Family: Flow control
- Version: 1.0.0
- Status: Partial. `duration` mode really pauses the run, capped at 10 seconds; `timestamp` mode does not wait and continues immediately through `out`.
- Execution: async

Pauses the execution flow for a specified duration or until a specific timestamp.

This operator is used to introduce delays or schedule execution for a future time. It relies on the orchestration engine to suspend the workflow and resume it at the calculated wake-up time.

**Modes:**
- **Duration:** Waits for a relative amount of time (e.g., "5 minutes").
- **Timestamp:** Waits until a specific absolute date/time (e.g., "2025-12-31T23:59:59Z").

**Use Cases:**
- Sending a follow-up email 24 hours after sign-up.
- Waiting for a connection retry backoff.
- Pausing a workflow until a specific business date.

## Configuration

- `type` (string, optional): Default: `duration`. Allowed values: `duration`, `timestamp`.
- `duration_seconds` (integer, optional): Number of seconds to wait (used when Type is "duration"). Default: `60`.
- `timestamp_expr` (string, optional, accepts expressions): ISO-8601 Timestamp or expression evaluating to one (used when Type is "timestamp").

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

## Output ports

- `out` (default): Execution resumes here after the delay.
- `error`: Activated if the timestamp is invalid.

## Input contract

- `payload` (object, optional)

## Output contract

- `payload` (object, optional)

## In expressions

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

- `$("Wait / Delay").item.json.payload` (object) **The worker does not return it: reads as undefined.**
- `$("Wait / Delay").item.json.ticket_id` (string) = `"tk_9"` (Not suggested by the editor)
- `$("Wait / Delay").item.json.due_at` (string) = `"2026-12-01T09:00:00Z"` (Not suggested by the editor)


## How it works

Experimental. In `duration` mode it really sleeps, capped at 10 seconds, then continues; in `timestamp` mode it only computes the resume time and continues at once. The workflow is never suspended.

1. Resolves the config; `type` defaults to `duration`. When `duration_seconds` is absent the code uses 0, not the schema default 60.
2. `duration`: sets `resume_at` to now plus `duration_seconds` and sleeps `min(duration, 10 s)` inside the worker.
3. `timestamp`: if the original `timestamp_expr` contains `{{`, uses the resolved value; otherwise evaluates it as JSONata against the payload (`due_at`). Parses it with `new Date()` and computes `delay_ms`. It does not sleep.
4. Returns the payload unchanged through `out` with `meta` `{ action: "suspend", resume_at, delay_ms }`. The engine ignores `meta.action` and runs the next node right away.

## In a workflow

### Node

```json
{
  "node_id": "node-wait-due",
  "label": "Wait until due",
  "operator_slug": "flow.wait",
  "operator_version": "1.0.0",
  "config": {
    "type": "timestamp",
    "timestamp_expr": "{{ $json.due_at }}"
  }
}
```

### Envelope

```json
{
  "ok": true,
  "data": {
    "ticket_id": "tk_9",
    "due_at": "2026-12-01T09:00:00Z"
  },
  "port": "out",
  "meta": {
    "action": "suspend",
    "resume_at": "2026-12-01T09:00:00.000Z",
    "delay_ms": 410400000
  }
}
```

## Output ports (behaviour in the code)

### `out`

After the capped sleep (`duration`) or at once (`timestamp`).

```json
{
  "ticket_id": "tk_9",
  "due_at": "2026-12-01T09:00:00Z"
}
```

### `error`

Only when the worker throws unexpectedly; an invalid timestamp leaves through `out` (see errors).

```json
{
  "error": "<message>"
}
```

## Behaviour in the code

- `timestamp_expr`: Use `{{ $json.due_at }}`, a JSONata path such as `due_at`, or a quoted literal `"2026-12-01T09:00:00Z"`. Without `timestamp_expr`, `timestamp` mode returns `resume_at: null` and `delay_ms: 0`.

## Errors

| Message | Port | Cause and fix |
| --- | --- | --- |
| `Wait timestamp error: <message>` | `out` | `timestamp_expr` is not a valid date, or is a raw ISO string without `{{ }}` or quotes (JSONata cannot parse `2026-12-01T09:00:00Z`). The envelope has no port, so the engine routes it to `out` and the next node receives `{ ok: false, errors: [...] }` as its payload. |

## Notes and limits

- There is no durable timer: a wait longer than 10 seconds is cut to 10 seconds, and the node holds the run while it sleeps.
- `meta` is recorded in the run steps only: downstream nodes receive `data` as their payload and cannot read `meta` through `$json` or `$("Node")`.


## Contracts (JSON Schema)

### All (`*.definition.js`)

```json
{
  "slug": "flow.wait",
  "name": "Wait / Delay",
  "category": "flow",
  "version": "1.0.0",
  "description": "Pauses the execution flow for a specified duration or until a specific timestamp.\n\n  This operator is used to introduce delays or schedule execution for a future time. It relies on the orchestration engine to suspend the workflow and resume it at the calculated wake-up time.\n\n  **Modes:**\n  - **Duration:** Waits for a relative amount of time (e.g., \"5 minutes\").\n  - **Timestamp:** Waits until a specific absolute date/time (e.g., \"2025-12-31T23:59:59Z\").\n\n  **Use Cases:**\n  - Sending a follow-up email 24 hours after sign-up.\n  - Waiting for a connection retry backoff.\n  - Pausing a workflow until a specific business date.",
  "capabilities": [
    "delay",
    "schedule",
    "time",
    "suspend"
  ],
  "config_schema": {
    "type": "object",
    "properties": {
      "type": {
        "type": "string",
        "enum": [
          "duration",
          "timestamp"
        ],
        "default": "duration",
        "title": "Wait Type"
      },
      "duration_seconds": {
        "type": "integer",
        "title": "Duration (Seconds)",
        "default": 60,
        "description": "Number of seconds to wait (used when Type is \"duration\")."
      },
      "timestamp_expr": {
        "type": "string",
        "title": "Until (Timestamp)",
        "format": "expression",
        "description": "ISO-8601 Timestamp or expression evaluating to one (used when Type is \"timestamp\")."
      },
      "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",
    "description": "Payload passed into the wait state.",
    "properties": {
      "payload": {
        "type": "object"
      }
    }
  },
  "output_contract_schema": {
    "type": "object",
    "description": "Payload passed out after resumption (usually unchanged).",
    "properties": {
      "payload": {
        "type": "object"
      }
    }
  },
  "ports": [
    {
      "port_id": "out",
      "label": "Resume",
      "is_default": true,
      "description": "Execution resumes here after the delay."
    },
    {
      "port_id": "error",
      "label": "Error",
      "description": "Activated if the timestamp is invalid."
    }
  ],
  "execution_mode": "async",
  "tags": [
    "time",
    "sleep",
    "control-flow",
    "schedule"
  ],
  "is_stateful": true,
  "publisher": {
    "identity": "org_sommatic_ai",
    "profile": {
      "name": "Sommatic AI",
      "verified": true,
      "url": "https://me.veripass.com/sommatic",
      "logo_url": null
    }
  }
}
```

### config_schema

```json
{
  "type": "object",
  "properties": {
    "type": {
      "type": "string",
      "enum": [
        "duration",
        "timestamp"
      ],
      "default": "duration",
      "title": "Wait Type"
    },
    "duration_seconds": {
      "type": "integer",
      "title": "Duration (Seconds)",
      "default": 60,
      "description": "Number of seconds to wait (used when Type is \"duration\")."
    },
    "timestamp_expr": {
      "type": "string",
      "title": "Until (Timestamp)",
      "format": "expression",
      "description": "ISO-8601 Timestamp or expression evaluating to one (used when Type is \"timestamp\")."
    },
    "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

```json
{
  "type": "object",
  "description": "Payload passed into the wait state.",
  "properties": {
    "payload": {
      "type": "object"
    }
  }
}
```

### output_contract_schema

```json
{
  "type": "object",
  "description": "Payload passed out after resumption (usually unchanged).",
  "properties": {
    "payload": {
      "type": "object"
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "out",
    "label": "Resume",
    "is_default": true,
    "description": "Execution resumes here after the delay."
  },
  {
    "port_id": "error",
    "label": "Error",
    "description": "Activated if the timestamp is invalid."
  }
]
```
