# Approval Gate

> Configures the approval gate on a task created by a preceding Create Task node.

Source: https://docs.sommatic.ai/en/nodes/human.approval.gate/

- Slug: `human.approval.gate`
- Family: Human in the loop
- Version: 1.0.0
- Status: Partial. Configures the approval gate on an existing task, then returns through the `accepted` port immediately. It does not suspend the workflow or wait for the human decision; `rejected` and `timeout` are never emitted.
- Execution: sync

Configures the approval gate on a task created by a preceding Create Task node. Writes payload.hitl + execution.app_slug via PATCH to the backend.

## Configuration

- `approval_type` (object, required): Binary | Tool | Plan Review | Single-Select | Multi-Select | Review/Edit/Reject
- `title` (string, required, accepts expressions): Shown to the approver when the task is claimed. Supports expressions like {{ $json.entity_name }}.
- `description` (string, optional, accepts expressions): Context shown to the approver inside the task detail. Supports expressions and multi-line text.
- `hitl_config` (object, optional): Subtype-specific fields (tool, plan, options, content, min_selection, etc.)

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

- `accepted` (default): Emitted when the approver confirms the action (Approve / Allow / Confirm / Submit edits).
- `rejected`: Emitted when the approver denies or cancels (Reject / Deny / Cancel).
- `timeout`: Emitted when the task expires without a decision (SLA breached).
- `error`: Emitted on technical failures during approval gate configuration.

## Input contract

- `task_id` (string, optional): Propagated from preceding Create Task node
- `approval_type` (object, optional)
- `title` (string, optional)
- `description` (string, optional)
- `hitl_config` (object, optional)

## Output contract

- `task_id` (string, optional)
- `approval_type` (object, optional)
- `decision` (string, optional): The actual human decision. Populated when suspend/resume is implemented; null in the current fire-and-forget mode. Allowed values: `approved`, `rejected`, `edited`, `timeout`.
- `selected` (array, optional): Populated for single_select / multi_select approval types.
- `edited_content` (object, optional): Populated when the approver edited plan steps or review content before approving.
- `comment` (string, optional)
- `approver` (string, optional)

## In expressions

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

- `$("Approval Gate").item.json.task_id` (string) = `"task-xxxxxxxxxxxxxxx"`
- `$("Approval Gate").item.json.approval_type` (object) = `{…}`
- `$("Approval Gate").item.json.decision` (string) = `null`: The actual human decision. Populated when suspend/resume is implemented; null in the current fire-and-forget mode.
- `$("Approval Gate").item.json.selected` (array): Populated for single_select / multi_select approval types. **The worker does not return it: reads as undefined.**
- `$("Approval Gate").item.json.edited_content` (object): Populated when the approver edited plan steps or review content before approving. **The worker does not return it: reads as undefined.**
- `$("Approval Gate").item.json.comment` (string) **The worker does not return it: reads as undefined.**
- `$("Approval Gate").item.json.approver` (string) **The worker does not return it: reads as undefined.**
- `$("Approval Gate").item.json.port` (string) = `"accepted"` (Not suggested by the editor)
- `$("Approval Gate").item.json.approval_type.id` (number) = `1` (Not suggested by the editor)
- `$("Approval Gate").item.json.approval_type.name` (string) = `"binary_approval"` (Not suggested by the editor)
- `$("Approval Gate").item.json.approval_type.title` (string) = `"Binary Approval"` (Not suggested by the editor)
- `$("Approval Gate").item.json.approval_type.color` (string) = `"#1976d2"` (Not suggested by the editor)


## How it works

Partial. Attaches an approval configuration to an existing task so the Tasks inbox opens it with the human approval gate app, then continues at once through `accepted`; it does not wait for the decision.

1. Resolves the config and merges it over the incoming payload (config wins).
2. Reads `task_id` from the config or the incoming payload, normally the output of the preceding `human.task.create`.
3. Checks `task_id`, `approval_type.name` and `title`, then builds `hitl` as `{ approval_type, title, description, ...hitl_config }`.
4. Reads the task from the Work Management API; fails if it does not exist.
5. Writes the whole task back with `payload.hitl` and `execution` `{ app_slug: "human-approval-gate", launch_mode: "embedded" }` merged into the existing values.
6. Returns `{ task_id, approval_type, decision: null }` through `accepted`.

## In a workflow

### Node

```json
{
  "node_id": "node-approve-refund",
  "label": "Approve refund",
  "operator_slug": "human.approval.gate",
  "operator_version": "1.0.0",
  "config": {
    "approval_type": {
      "id": 1,
      "name": "binary_approval",
      "title": "Binary Approval",
      "color": "#1976d2"
    },
    "title": "Approve refund for {{ $json.task_title }}",
    "description": "Confirm the refund before it is issued.",
    "hitl_config": {}
  }
}
```

### Envelope

```json
{
  "ok": true,
  "port": "accepted",
  "task_id": "task-xxxxxxxxxxxxxxx",
  "approval_type": {
    "id": 1,
    "name": "binary_approval",
    "title": "Binary Approval",
    "color": "#1976d2"
  },
  "decision": null
}
```

## Output ports (behaviour in the code)

### `accepted`

The gate was configured on the task. It does not mean anyone approved.

```json
{
  "port": "accepted",
  "task_id": "task-xxxxxxxxxxxxxxx",
  "approval_type": {
    "id": 1,
    "name": "binary_approval",
    "title": "Binary Approval",
    "color": "#1976d2"
  },
  "decision": null
}
```

### `rejected`

Never emitted: the worker does not wait for the decision.

### `timeout`

Never emitted.

### `error`

Missing inputs, task not found or the backend call failed.

```json
{
  "port": "error",
  "error": "Missing 'approval_type' or invalid approval type object"
}
```

## Behaviour in the code

- `approval_type`: One of `binary_approval` (1), `tool_approval` (2), `plan_review` (3), `single_select_decision` (4), `multi_select_decision` (5), `review_edit_reject` (6), as `{ id, name, title, color }`.
- `hitl_config`: Spread into `hitl`, so its keys can override `approval_type`, `title` and `description`. Shapes per type: `tool_approval` `{ tool: { name, args, risk_level } }`; `plan_review` `{ plan: { steps: [{ id, title, detail }] } }`; select types `{ options: [{ id, name, title }] }`; `review_edit_reject` `{ content: { text, editable } }`.

## Errors

| Message | Port | Cause and fix |
| --- | --- | --- |
| `Missing 'task_id'. This node must be chained after a Human Task Create node. If you are testing with 'Execute step', run the preceding Create Task node first or provide sample data that includes task_id.` | `error` | No `task_id` in the config or the payload. |
| `Missing 'approval_type' or invalid approval type object` | `error` | `approval_type` is missing or has no `name`. |
| `Missing 'title'` | `error` | `title` is empty after resolving expressions. |
| `Task '<task_id>' not found. Cannot configure approval gate on a non-existent task.` | `error` | The task id does not exist in Work Management. |
| `Backend rejected the update` | `error` | The update answered without `success`; the backend message is used when present. |
| `Request failed with status code <status>` | `error` | The backend rejected the read or the update. |
| `services.apiManager.uri is not resolved in dependencies.config — check Link Loom Cloud environment config.` | `error` | The orchestrator has no backend address configured. This is a service configuration problem, not a node problem. |

## Notes and limits

- Not implemented: suspending the run and routing the decision. `decision` is always `null`; `selected`, `edited_content`, `comment` and `approver` from the output contract are never returned; `rejected` and `timeout` never fire.
- The update is a read-modify-write of the whole task: changes made to the task between the read and the write are overwritten. The task status is not changed.
- The worker returns its fields at the top level of the envelope, without `data`, so the engine uses the whole envelope (including the `port` key) as the payload of the next node.
- The worker does not set `ok` (the example shows `true`); the engine routes only by `port`.


## Contracts (JSON Schema)

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

```json
{
  "slug": "human.approval.gate",
  "name": "Approval Gate",
  "category": "hitl",
  "version": "1.0.0",
  "description": "Configures the approval gate on a task created by a preceding Create Task node. Writes payload.hitl + execution.app_slug via PATCH to the backend.",
  "capabilities": [
    "approval",
    "gate",
    "human"
  ],
  "config_schema": {
    "type": "object",
    "required": [
      "approval_type",
      "title"
    ],
    "properties": {
      "approval_type": {
        "type": "object",
        "title": "Approval Type",
        "ui_widget": "hitl_approval_type_picker",
        "description": "Binary | Tool | Plan Review | Single-Select | Multi-Select | Review/Edit/Reject"
      },
      "title": {
        "type": "string",
        "title": "Title",
        "format": "expression",
        "description": "Shown to the approver when the task is claimed. Supports expressions like {{ $json.entity_name }}."
      },
      "description": {
        "type": "string",
        "title": "Description",
        "format": "expression",
        "description": "Context shown to the approver inside the task detail. Supports expressions and multi-line text."
      },
      "hitl_config": {
        "type": "object",
        "title": "Approval configuration",
        "ui_widget": "hitl_config",
        "ui_options": {
          "depends_on": "approval_type"
        },
        "description": "Subtype-specific fields (tool, plan, options, content, min_selection, etc.)"
      },
      "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": {
      "task_id": {
        "type": "string",
        "description": "Propagated from preceding Create Task node"
      },
      "approval_type": {
        "type": "object"
      },
      "title": {
        "type": "string"
      },
      "description": {
        "type": "string"
      },
      "hitl_config": {
        "type": "object"
      }
    }
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "task_id": {
        "type": "string"
      },
      "approval_type": {
        "type": "object"
      },
      "decision": {
        "type": "string",
        "enum": [
          "approved",
          "rejected",
          "edited",
          "timeout"
        ],
        "description": "The actual human decision. Populated when suspend/resume is implemented; null in the current fire-and-forget mode."
      },
      "selected": {
        "type": "array",
        "description": "Populated for single_select / multi_select approval types."
      },
      "edited_content": {
        "type": "object",
        "description": "Populated when the approver edited plan steps or review content before approving."
      },
      "comment": {
        "type": "string"
      },
      "approver": {
        "type": "string"
      }
    }
  },
  "ports": [
    {
      "port_id": "accepted",
      "label": "Accepted",
      "is_default": true,
      "description": "Emitted when the approver confirms the action (Approve / Allow / Confirm / Submit edits)."
    },
    {
      "port_id": "rejected",
      "label": "Rejected",
      "description": "Emitted when the approver denies or cancels (Reject / Deny / Cancel)."
    },
    {
      "port_id": "timeout",
      "label": "Timeout",
      "description": "Emitted when the task expires without a decision (SLA breached)."
    },
    {
      "port_id": "error",
      "label": "Error",
      "description": "Emitted on technical failures during approval gate configuration."
    }
  ],
  "chain_constraints": {
    "prev": {
      "required_slug": "human.task.create",
      "message": "Human Approval Gate requires a preceding Create Task node to receive the task_id."
    }
  },
  "execution_mode": "sync",
  "tags": [
    "approval",
    "gate",
    "human",
    "hitl"
  ],
  "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",
  "required": [
    "approval_type",
    "title"
  ],
  "properties": {
    "approval_type": {
      "type": "object",
      "title": "Approval Type",
      "ui_widget": "hitl_approval_type_picker",
      "description": "Binary | Tool | Plan Review | Single-Select | Multi-Select | Review/Edit/Reject"
    },
    "title": {
      "type": "string",
      "title": "Title",
      "format": "expression",
      "description": "Shown to the approver when the task is claimed. Supports expressions like {{ $json.entity_name }}."
    },
    "description": {
      "type": "string",
      "title": "Description",
      "format": "expression",
      "description": "Context shown to the approver inside the task detail. Supports expressions and multi-line text."
    },
    "hitl_config": {
      "type": "object",
      "title": "Approval configuration",
      "ui_widget": "hitl_config",
      "ui_options": {
        "depends_on": "approval_type"
      },
      "description": "Subtype-specific fields (tool, plan, options, content, min_selection, etc.)"
    },
    "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",
  "properties": {
    "task_id": {
      "type": "string",
      "description": "Propagated from preceding Create Task node"
    },
    "approval_type": {
      "type": "object"
    },
    "title": {
      "type": "string"
    },
    "description": {
      "type": "string"
    },
    "hitl_config": {
      "type": "object"
    }
  }
}
```

### output_contract_schema

```json
{
  "type": "object",
  "properties": {
    "task_id": {
      "type": "string"
    },
    "approval_type": {
      "type": "object"
    },
    "decision": {
      "type": "string",
      "enum": [
        "approved",
        "rejected",
        "edited",
        "timeout"
      ],
      "description": "The actual human decision. Populated when suspend/resume is implemented; null in the current fire-and-forget mode."
    },
    "selected": {
      "type": "array",
      "description": "Populated for single_select / multi_select approval types."
    },
    "edited_content": {
      "type": "object",
      "description": "Populated when the approver edited plan steps or review content before approving."
    },
    "comment": {
      "type": "string"
    },
    "approver": {
      "type": "string"
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "accepted",
    "label": "Accepted",
    "is_default": true,
    "description": "Emitted when the approver confirms the action (Approve / Allow / Confirm / Submit edits)."
  },
  {
    "port_id": "rejected",
    "label": "Rejected",
    "description": "Emitted when the approver denies or cancels (Reject / Deny / Cancel)."
  },
  {
    "port_id": "timeout",
    "label": "Timeout",
    "description": "Emitted when the task expires without a decision (SLA breached)."
  },
  {
    "port_id": "error",
    "label": "Error",
    "description": "Emitted on technical failures during approval gate configuration."
  }
]
```
