# Workflow Chain Receiver

> Receives execution requests from another workflow's Chain node.

Source: https://docs.sommatic.ai/en/nodes/workflow.trigger/

- Slug: `workflow.trigger`
- Family: Triggers
- Version: 1.0.0
- Status: Available
- Execution: sync

Receives execution requests from another workflow's Chain node.

This trigger acts as the entry point for a workflow that is invoked by another workflow via the `workflow.chain` node. It enables peer-to-peer workflow chaining without creating a parent-child hierarchy.

**Features:**
- **Caller Filtering:** Optionally restrict which workflows can chain into this one.
- **Payload Passthrough:** The calling workflow's payload is available as `$json` in downstream nodes.
- **Traceability:** Chain context (caller instance, node, correlation ID) is preserved for audit.

**Use Cases:**
- Modular workflow composition (e.g., shared validation workflow invoked by multiple callers).
- Event-driven chaining where Workflow A completes a phase and delegates to Workflow B.
- Reusable sub-processes that remain independently testable and deployable.

## Configuration

- `accepted_caller_ids` (array<string>, optional): Select which workflows are allowed to invoke this one. Leave empty to accept calls from any workflow. Default: `[]`.

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): Chain payload received and validated.
- `error`: Caller not authorized or validation failed.

## Output contract

- `data` (object, optional): The chain input data.
- `chain_context` (object, optional): Traceability metadata from the caller.
  - `caller_flow_definition_id` (string, optional)
  - `caller_flow_instance_id` (string, optional)
  - `caller_flow_slug` (string, optional)
  - `caller_node_id` (string, optional)
  - `correlation_id` (string, optional)

## In expressions

What a later node can read from this node's output with `$("Workflow Chain Receiver").item.json.<path>` (write your node's label instead of `Workflow Chain Receiver`). **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.

- `$("Workflow Chain Receiver").item.json.data` (object): The chain input data. **The worker does not return it: reads as undefined.**
- `$("Workflow Chain Receiver").item.json.chain_context` (object) = `{…}`: Traceability metadata from the caller.
- `$("Workflow Chain Receiver").item.json.chain_context.caller_flow_definition_id` (string) = `"<flow_definition_id>"`
- `$("Workflow Chain Receiver").item.json.chain_context.caller_flow_instance_id` (string) = `"<flow_instance_id>"`
- `$("Workflow Chain Receiver").item.json.chain_context.caller_flow_slug` (string) = `"order-intake"`
- `$("Workflow Chain Receiver").item.json.chain_context.caller_node_id` (string) = `"node-call-billing"`
- `$("Workflow Chain Receiver").item.json.chain_context.correlation_id` (string) = `"chain-8f2k1m9x0q4w7e3r5t6y"`
- `$("Workflow Chain Receiver").item.json.order_id` (string) = `"ord_123"` (Not suggested by the editor)
- `$("Workflow Chain Receiver").item.json.customer_email` (string) = `"ana@example.com"` (Not suggested by the editor)
- `$("Workflow Chain Receiver").item.json.chain_context.root_flow_instance_result_id` (string) = `"<flow_instance_result_id>"` (Not suggested by the editor)


## How it works

Entry node for sub-workflows called by `workflow.chain`. It optionally restricts which workflows may call it, then outputs the data sent by the caller together with `chain_context`.

1. What starts it: a `workflow.chain` node in another workflow. The backend runs the draft when the caller is itself a draft run (`test`) and the default published version when the caller runs a published version (`prod`); `prod` fails when this workflow has no published version. The run's input is `{ data, chain_context }`.
2. Resolves the node config. When `accepted_caller_ids` is not empty and `chain_context.caller_flow_definition_id` is not in it, returns `error`.
3. Otherwise spreads `data` at the root, adds `chain_context` and returns `meta` with the caller's definition id, slug, instance id and the chain's correlation id.

## In a workflow

### Node

```json
{
  "node_id": "node-from-parent",
  "label": "Called by order intake",
  "operator_slug": "workflow.trigger",
  "operator_version": "1.0.0",
  "config": {
    "accepted_caller_ids": [
      "<flow_definition_id>"
    ]
  }
}
```

### Envelope

```json
{
  "ok": true,
  "data": {
    "order_id": "ord_123",
    "customer_email": "ana@example.com",
    "chain_context": {
      "caller_flow_definition_id": "<flow_definition_id>",
      "caller_flow_instance_id": "<flow_instance_id>",
      "caller_flow_slug": "order-intake",
      "caller_node_id": "node-call-billing",
      "correlation_id": "chain-8f2k1m9x0q4w7e3r5t6y",
      "root_flow_instance_result_id": "<flow_instance_result_id>"
    }
  },
  "port": "out",
  "meta": {
    "caller_flow_definition_id": "<flow_definition_id>",
    "caller_flow_slug": "order-intake",
    "caller_flow_instance_id": "<flow_instance_id>",
    "correlation_id": "chain-8f2k1m9x0q4w7e3r5t6y"
  }
}
```

## Output ports (behaviour in the code)

### `out`

The caller is accepted.

```json
{
  "order_id": "ord_123",
  "customer_email": "ana@example.com",
  "chain_context": {
    "caller_flow_definition_id": "<flow_definition_id>",
    "caller_flow_instance_id": "<flow_instance_id>",
    "caller_flow_slug": "order-intake",
    "caller_node_id": "node-call-billing",
    "correlation_id": "chain-8f2k1m9x0q4w7e3r5t6y",
    "root_flow_instance_result_id": "<flow_instance_result_id>"
  }
}
```

### `error`

The caller is not in `accepted_caller_ids`. The output is the envelope `{ ok, errors, port, meta: { rejected_caller_id, rejected_caller_slug } }`.

```json
{
  "ok": false,
  "errors": [
    "Caller workflow 'order-intake' is not in the accepted callers list"
  ],
  "port": "error",
  "meta": {
    "rejected_caller_id": "<flow_definition_id>",
    "rejected_caller_slug": "order-intake"
  }
}
```

## Behaviour in the code

- `accepted_caller_ids`: Matched against `chain_context.caller_flow_definition_id` (workflow definition ids, not slugs). Empty accepts every caller.

## Errors

| Message | Port | Cause and fix |
| --- | --- | --- |
| `Caller workflow '<caller_flow_slug or caller_flow_definition_id>' is not in the accepted callers list` | `error` | Add the caller's workflow definition id to `accepted_caller_ids`, or leave the list empty to accept any caller. A run started without `chain_context` (for example by hand) is also rejected when the list is not empty. |

## Notes and limits

- The caller's data keys are spread at the root, so read them downstream as `$json.<field>`; a `data.chain_context` key would be replaced by the real `chain_context`.
- `chain_context.root_flow_instance_result_id` stays the same through every hop of a chain, so any sub-workflow can report the id of the top-level run.
- With sample data the engine skips the node and passes the sample input on `out` unchanged (without spreading `data`).


## Contracts (JSON Schema)

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

```json
{
  "slug": "workflow.trigger",
  "name": "Workflow Chain Receiver",
  "category": "triggers",
  "version": "1.0.0",
  "description": "Receives execution requests from another workflow's Chain node.\n\n  This trigger acts as the entry point for a workflow that is invoked by another workflow via the `workflow.chain` node. It enables peer-to-peer workflow chaining without creating a parent-child hierarchy.\n\n  **Features:**\n  - **Caller Filtering:** Optionally restrict which workflows can chain into this one.\n  - **Payload Passthrough:** The calling workflow's payload is available as `$json` in downstream nodes.\n  - **Traceability:** Chain context (caller instance, node, correlation ID) is preserved for audit.\n\n  **Use Cases:**\n  - Modular workflow composition (e.g., shared validation workflow invoked by multiple callers).\n  - Event-driven chaining where Workflow A completes a phase and delegates to Workflow B.\n  - Reusable sub-processes that remain independently testable and deployable.",
  "capabilities": [
    "workflow",
    "chain",
    "composition",
    "trigger"
  ],
  "config_schema": {
    "type": "object",
    "properties": {
      "accepted_caller_ids": {
        "type": "array",
        "items": {
          "type": "string"
        },
        "title": "Accepted Callers",
        "description": "Select which workflows are allowed to invoke this one. Leave empty to accept calls from any workflow.",
        "default": [],
        "x-ui-widget": "flow-definition-multi-picker"
      },
      "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": null,
  "output_contract_schema": {
    "type": "object",
    "description": "The payload sent by the calling workflow.",
    "properties": {
      "data": {
        "type": "object",
        "description": "The chain input data."
      },
      "chain_context": {
        "type": "object",
        "description": "Traceability metadata from the caller.",
        "properties": {
          "caller_flow_definition_id": {
            "type": "string"
          },
          "caller_flow_instance_id": {
            "type": "string"
          },
          "caller_flow_slug": {
            "type": "string"
          },
          "caller_node_id": {
            "type": "string"
          },
          "correlation_id": {
            "type": "string"
          }
        }
      }
    }
  },
  "ports": [
    {
      "port_id": "out",
      "label": "Received",
      "is_default": true,
      "description": "Chain payload received and validated."
    },
    {
      "port_id": "error",
      "label": "Error",
      "description": "Caller not authorized or validation failed."
    }
  ],
  "execution_mode": "sync",
  "tags": [
    "workflow",
    "chain",
    "trigger",
    "composition"
  ],
  "is_stateful": false,
  "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": {
    "accepted_caller_ids": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "title": "Accepted Callers",
      "description": "Select which workflows are allowed to invoke this one. Leave empty to accept calls from any workflow.",
      "default": [],
      "x-ui-widget": "flow-definition-multi-picker"
    },
    "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
        }
      }
    }
  }
}
```

### output_contract_schema

```json
{
  "type": "object",
  "description": "The payload sent by the calling workflow.",
  "properties": {
    "data": {
      "type": "object",
      "description": "The chain input data."
    },
    "chain_context": {
      "type": "object",
      "description": "Traceability metadata from the caller.",
      "properties": {
        "caller_flow_definition_id": {
          "type": "string"
        },
        "caller_flow_instance_id": {
          "type": "string"
        },
        "caller_flow_slug": {
          "type": "string"
        },
        "caller_node_id": {
          "type": "string"
        },
        "correlation_id": {
          "type": "string"
        }
      }
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "out",
    "label": "Received",
    "is_default": true,
    "description": "Chain payload received and validated."
  },
  {
    "port_id": "error",
    "label": "Error",
    "description": "Caller not authorized or validation failed."
  }
]
```
