# Task lifecycle

> The statuses of a task, the transitions that move it between them and what each transition checks or changes, including the output validation on complete.

Source: https://docs.sommatic.ai/en/human-in-the-loop/task-lifecycle/ (updated 2026-11-26)

A task moves through a small state machine. Every move is a named transition: you never set the status by hand, you
ask for a transition and Sommatic AI checks that it is allowed from the current status.

## Statuses

| Status        | Meaning                                       |
| ------------- | --------------------------------------------- |
| `queued`      | Created, waiting for an assignee or a claim.  |
| `assigned`    | Assigned to a user or a group.                |
| `claimed`     | A specific person took ownership.             |
| `in_progress` | The person is working on it.                  |
| `completed`   | The output was provided and validated.        |
| `rejected`    | Concluded as rejected.                        |
| `invalidated` | No longer applicable (cancelled or replaced). |
| `expired`     | Its deadline passed.                          |

## Transitions

| Transition   | From                                           | To                                                 |
| ------------ | ---------------------------------------------- | -------------------------------------------------- |
| `assign`     | `queued`                                       | `assigned` (`claimed` when the assignee is a user) |
| `claim`      | `queued`, `assigned`                           | `claimed`                                          |
| `start`      | `claimed`                                      | `in_progress`                                      |
| `complete`   | `queued`, `assigned`, `claimed`, `in_progress` | `completed`                                        |
| `reject`     | `queued`, `assigned`, `claimed`, `in_progress` | `rejected`                                         |
| `invalidate` | `queued`, `assigned`, `claimed`, `in_progress` | `invalidated`                                      |
| `expire`     | `queued`, `assigned`, `claimed`, `in_progress` | `expired`                                          |
| `restart`    | `completed`, `rejected`, `invalidated`         | `queued`                                           |

A transition that is not allowed from the current status fails with
`Transition '<name>' not allowed from status '<status>'`. `GET /work-management/task/transitions` returns this table.

> **Note: Nothing moves on its own**
>
> Every transition is a request. `is_overdue` is recomputed each time a task is read, but no process moves an overdue
> task to `expired`: call `expire` when your process decides it.

## What each transition does

- **`assign`** sets `assignee` from the payload. When the assignee is a user, the task is also claimed by that user and
  goes straight to `claimed`.
- **`claim`** sets `ownership` (`is_claimed`, `claimed_by`, `claimed_at`) and, when `claimed_by` is given, makes that
  person the assignee.
- **`complete`** validates `outputs` against `required_output.schema` and saves them. Every field listed in `required`
  must be present and not empty, or the transition fails with
  `Cannot complete task: missing required outputs: <fields>`.
- **`reject`** saves `outputs`. Put the reason there (for example `outputs.reason`), which the portal shows on rejected
  tasks.
- **`complete`** and **`reject`** on a task nobody claimed: when the payload carries `claimed_by`, that person becomes
  the claimant and the assignee.
- **`restart`** returns the task to `queued`, clears its ownership and empties its `outputs`.

A task created with a user assignee starts in `claimed`, so it can be worked right away.

## Call a transition

`PATCH /work-management/task/transition/` with the task `id`, the `transition_name` and an optional `payload`.

**Complete**

```bash
curl -X PATCH https://api.sommatic.ai/work-management/task/transition/ \
  -H "Authorization: Bearer $SOMMATIC_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "id": "<task-id>",
    "transition_name": "complete",
    "payload": {
      "outputs": { "decision": "approved", "reason": "Within policy." }
    }
  }'
```

**Claim**

```bash
curl -X PATCH https://api.sommatic.ai/work-management/task/transition/ \
  -H "Authorization: Bearer $SOMMATIC_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "id": "<task-id>",
    "transition_name": "claim",
    "payload": {
      "claimed_by": { "id": "<user-identity>", "name": "Ana Ruiz" }
    }
  }'
```

**Assign**

```bash
curl -X PATCH https://api.sommatic.ai/work-management/task/transition/ \
  -H "Authorization: Bearer $SOMMATIC_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "id": "<task-id>",
    "transition_name": "assign",
    "payload": {
      "assignee": { "assignee_type": "group", "group": { "id": "<group-id>", "name": "Supervisors" } }
    }
  }'
```

The answer is the updated task in the standard envelope.

## Read tasks

`GET /work-management/task/:queryselector` with:

| Selector                                         | Returns                            |
| ------------------------------------------------ | ---------------------------------- |
| `id`                                             | One task (`?search=<task-id>`).    |
| `inbox`                                          | The tasks of a person.             |
| `all`, `list`                                    | Tasks with pagination and filters. |
| `statuses`, `types`, `priorities`, `transitions` | The catalogs on this page.         |

## Next steps

- [Notifications](https://docs.sommatic.ai/en/human-in-the-loop/notifications.md): Push new tasks to the assignee.
- [App contracts](https://docs.sommatic.ai/en/apps/contracts.md): Collect structured outputs with an app.
- [API reference](https://docs.sommatic.ai/en/api/reference/human-in-the-loop.md): Every task endpoint.
