# Handoff to Sommatic App

> Terminal node: hands a finished workflow's result to a Sommatic AI App.

Source: https://docs.sommatic.ai/en/nodes/sommatic.app.handoff/

- Slug: `sommatic.app.handoff`
- Family: Human in the loop
- Version: 1.0.0
- Status: Available
- Execution: sync

Terminal node: hands a finished workflow's result to a Sommatic AI App. Creates a durable HITL Task carrying the open descriptor and, if a live Command Center session is subscribed, opens the app instantly. Symmetric counterpart of sommatic.app.execute (app-as-gate); this is app-as-terminal — the workflow ends and does not resume.

## Configuration

- `target` (object, required)
  - `app_slug` (string, required): Slug of the Sommatic AI App to hand off to (e.g. my-review-app).
  - `route` (string, optional): Route opened inside the app (e.g. /new-sentence). Defaults to /. Default: `/`.
  - `launch_mode` (string, optional): How the app is opened when a live session exists. Default: `command-center`.
- `input_mapping` (object, optional): Payload pre-filled into the app, resolved server-side from {{...}} expressions.
- `organization_id` (string, required): Organization that owns the created Task.
- `assignee` (string, required): Identity (email) the Task is assigned to.
- `task_title` (string, required): Title of the durable HITL Task created for the handoff.
- `task_type` (object, optional): Task type descriptor. Defaults to review.
- `task_priority` (object, optional): Task priority descriptor. Defaults to medium.

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): Handoff delivered (Task created; app opened if live session).
- `error`: Error

## Input contract

- `target` (object, optional)
- `input_mapping` (object, optional)
- `organization_id` (string, optional)
- `assignee` (string, optional)
- `task_title` (string, optional)

## Output contract

- `app_handoff_descriptor` (object, optional)
- `task_id` (string, optional)
- `task_title` (string, optional)

## In expressions

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

- `$("Handoff to Sommatic App").item.json.app_handoff_descriptor` (object) = `{…}`
- `$("Handoff to Sommatic App").item.json.task_id` (string) = `"task-xxxxxxxxxxxxxxx"`
- `$("Handoff to Sommatic App").item.json.task_title` (string) = `"Approve order ord_123"`
- `$("Handoff to Sommatic App").item.json.port` (string) = `"out"` (Not suggested by the editor)
- `$("Handoff to Sommatic App").item.json.app_handoff_descriptor.app_slug` (string) = `"sommatic-approval-desk"` (Not suggested by the editor)
- `$("Handoff to Sommatic App").item.json.app_handoff_descriptor.route_path` (string) = `"/"` (Not suggested by the editor)
- `$("Handoff to Sommatic App").item.json.app_handoff_descriptor.input_payload` (object) = `{…}` (Not suggested by the editor)
- `$("Handoff to Sommatic App").item.json.app_handoff_descriptor.launch_mode` (string) = `"command-center"` (Not suggested by the editor)


## How it works

Terminal handoff: creates a task for a user that carries an app-open descriptor (app slug, route, input, launch mode) and returns the descriptor so the run result can open the app.

1. Resolves the config and merges it over the incoming payload (config wins); `{{ }}` in `input_mapping` are resolved on the server.
2. Builds the descriptor: `app_slug` from `target.app_slug`, `route_path` from `target.route` (default `/`), `launch_mode` from `target.launch_mode` (default `command-center`) and `input_payload` from `input_mapping` (default `{}`).
3. Checks `app_slug`, `organization_id`, `assignee` and `task_title`.
4. Posts a task with a user assignee, status `queued`, `source` `workflow` and `metadata.app_handoff_descriptor`; the backend claims it for that user. `task_type` defaults to `review` and `task_priority` to `medium`.
5. Returns `{ app_handoff_descriptor, task_id, task_title }` at the top level through `out`, where the run result can pick up the descriptor; opening the task later relaunches the app pre-filled.

## In a workflow

### Node

```json
{
  "node_id": "node-handoff-approval",
  "label": "Hand off to approval desk",
  "operator_slug": "sommatic.app.handoff",
  "operator_version": "1.0.0",
  "config": {
    "target": {
      "app_slug": "sommatic-approval-desk",
      "route": "/",
      "launch_mode": "command-center"
    },
    "input_mapping": {
      "order_id": "{{ $json.order_id }}",
      "amount": "{{ $json.amount }}"
    },
    "organization_id": "<organization_id>",
    "assignee": "approver@example.com",
    "task_title": "Approve order {{ $json.order_id }}"
  }
}
```

### Envelope

```json
{
  "ok": true,
  "port": "out",
  "app_handoff_descriptor": {
    "app_slug": "sommatic-approval-desk",
    "route_path": "/",
    "input_payload": {
      "order_id": "ord_123",
      "amount": 1250
    },
    "launch_mode": "command-center"
  },
  "task_id": "task-xxxxxxxxxxxxxxx",
  "task_title": "Approve order ord_123"
}
```

## Output ports (behaviour in the code)

### `out`

The task was created. The run is meant to end here; it does not suspend.

```json
{
  "port": "out",
  "app_handoff_descriptor": {
    "app_slug": "sommatic-approval-desk",
    "route_path": "/",
    "input_payload": {
      "order_id": "ord_123",
      "amount": 1250
    },
    "launch_mode": "command-center"
  },
  "task_id": "task-xxxxxxxxxxxxxxx",
  "task_title": "Approve order ord_123"
}
```

### `error`

A required field is missing or the backend call failed.

```json
{
  "port": "error",
  "error": "Missing 'assignee'"
}
```

## Behaviour in the code

- `task_type`: The default object is `{ id: 1, name: "review", title: "Review" }`, while the backend catalog lists `review` with id 12. Set `task_type` explicitly if your inbox filters by id.
- `target`: Undeclared top-level fallbacks are also read: `app_slug`, `route`, `launch_mode`, `input_payload`, `title`, `type` and `priority`.

## Errors

| Message | Port | Cause and fix |
| --- | --- | --- |
| `Missing 'target.app_slug'` | `error` | No `target.app_slug` (nor a top-level `app_slug`). |
| `Missing 'organization_id'` | `error` | Not in the config nor in the payload. |
| `Missing 'assignee'` | `error` | The handoff always needs a user identity (email). |
| `Missing 'task_title'` | `error` | `task_title` (or `title`) is empty. |
| `Backend did not return a task id` | `error` | The backend answered without `result.id`. |
| `Request failed with status code <status>` | `error` | The backend rejected the task. |
| `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

- It does not suspend or wait: whatever is connected to `out` runs right away. Use it as the last node of the run.
- The task `context.workflow_instance_id` and `context.trace_id` are sent empty: the worker reads them from fields the runtime does not set, so the task is not linked to the run.
- Not idempotent: every execution creates a new task. There are no retries on the HTTP call.
- 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": "sommatic.app.handoff",
  "name": "Handoff to Sommatic App",
  "category": "hitl",
  "version": "1.0.0",
  "description": "Terminal node: hands a finished workflow's result to a Sommatic AI App. Creates a durable HITL Task carrying the open descriptor and, if a live Command Center session is subscribed, opens the app instantly. Symmetric counterpart of sommatic.app.execute (app-as-gate); this is app-as-terminal — the workflow ends and does not resume.",
  "capabilities": [
    "ui",
    "human",
    "terminal"
  ],
  "config_schema": {
    "type": "object",
    "required": [
      "target",
      "organization_id",
      "assignee",
      "task_title"
    ],
    "properties": {
      "target": {
        "type": "object",
        "title": "Target App",
        "required": [
          "app_slug"
        ],
        "properties": {
          "app_slug": {
            "type": "string",
            "title": "App Slug",
            "description": "Slug of the Sommatic AI App to hand off to (e.g. my-review-app)."
          },
          "route": {
            "type": "string",
            "title": "Route Path",
            "description": "Route opened inside the app (e.g. /new-sentence). Defaults to /.",
            "default": "/"
          },
          "launch_mode": {
            "type": "string",
            "title": "Launch Mode",
            "description": "How the app is opened when a live session exists.",
            "default": "command-center"
          }
        }
      },
      "input_mapping": {
        "type": "object",
        "title": "Input Payload",
        "description": "Payload pre-filled into the app, resolved server-side from {{...}} expressions."
      },
      "organization_id": {
        "type": "string",
        "title": "Organization",
        "description": "Organization that owns the created Task."
      },
      "assignee": {
        "type": "string",
        "title": "Assignee",
        "ui_widget": "user_picker",
        "description": "Identity (email) the Task is assigned to."
      },
      "task_title": {
        "type": "string",
        "title": "Task Title",
        "description": "Title of the durable HITL Task created for the handoff."
      },
      "task_type": {
        "type": "object",
        "title": "Task Type",
        "description": "Task type descriptor. Defaults to review."
      },
      "task_priority": {
        "type": "object",
        "title": "Task Priority",
        "description": "Task priority descriptor. Defaults to medium."
      },
      "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": {
      "target": {
        "type": "object"
      },
      "input_mapping": {
        "type": "object"
      },
      "organization_id": {
        "type": "string"
      },
      "assignee": {
        "type": "string"
      },
      "task_title": {
        "type": "string"
      }
    }
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "app_handoff_descriptor": {
        "type": "object"
      },
      "task_id": {
        "type": "string"
      },
      "task_title": {
        "type": "string"
      }
    }
  },
  "ports": [
    {
      "port_id": "out",
      "label": "Out",
      "is_default": true,
      "description": "Handoff delivered (Task created; app opened if live session)."
    },
    {
      "port_id": "error",
      "label": "Error"
    }
  ],
  "execution_mode": "sync",
  "tags": [
    "ui",
    "terminal",
    "handoff"
  ],
  "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": [
    "target",
    "organization_id",
    "assignee",
    "task_title"
  ],
  "properties": {
    "target": {
      "type": "object",
      "title": "Target App",
      "required": [
        "app_slug"
      ],
      "properties": {
        "app_slug": {
          "type": "string",
          "title": "App Slug",
          "description": "Slug of the Sommatic AI App to hand off to (e.g. my-review-app)."
        },
        "route": {
          "type": "string",
          "title": "Route Path",
          "description": "Route opened inside the app (e.g. /new-sentence). Defaults to /.",
          "default": "/"
        },
        "launch_mode": {
          "type": "string",
          "title": "Launch Mode",
          "description": "How the app is opened when a live session exists.",
          "default": "command-center"
        }
      }
    },
    "input_mapping": {
      "type": "object",
      "title": "Input Payload",
      "description": "Payload pre-filled into the app, resolved server-side from {{...}} expressions."
    },
    "organization_id": {
      "type": "string",
      "title": "Organization",
      "description": "Organization that owns the created Task."
    },
    "assignee": {
      "type": "string",
      "title": "Assignee",
      "ui_widget": "user_picker",
      "description": "Identity (email) the Task is assigned to."
    },
    "task_title": {
      "type": "string",
      "title": "Task Title",
      "description": "Title of the durable HITL Task created for the handoff."
    },
    "task_type": {
      "type": "object",
      "title": "Task Type",
      "description": "Task type descriptor. Defaults to review."
    },
    "task_priority": {
      "type": "object",
      "title": "Task Priority",
      "description": "Task priority descriptor. Defaults to medium."
    },
    "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": {
    "target": {
      "type": "object"
    },
    "input_mapping": {
      "type": "object"
    },
    "organization_id": {
      "type": "string"
    },
    "assignee": {
      "type": "string"
    },
    "task_title": {
      "type": "string"
    }
  }
}
```

### output_contract_schema

```json
{
  "type": "object",
  "properties": {
    "app_handoff_descriptor": {
      "type": "object"
    },
    "task_id": {
      "type": "string"
    },
    "task_title": {
      "type": "string"
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "out",
    "label": "Out",
    "is_default": true,
    "description": "Handoff delivered (Task created; app opened if live session)."
  },
  {
    "port_id": "error",
    "label": "Error"
  }
]
```
