# Review Workflow Board and Reviewer Routing

Source: https://www.potatoannotator.com/docs/features/review-workflow

The review workflow is a kanban board at `/admin/review` where project admins track each item through five review states, give each item a reviewer and a priority, and move items between states. Potato keeps the board off until the config enables the `review_workflow` block. The board keeps a separate record beside the annotations, so turning the workflow on changes neither the items annotators are served nor the labels annotators save. Potato logs every state change with the user who made the change, and the Throughput tab of the [admin dashboard](/docs/features/admin-dashboard) turns the log into first-pass approval and rework rates per annotator. The board works on any project's items, and Potato's shipped example uses agent traces.

## Configuration options

The `review_workflow` block takes four options. Add the block below to an existing config to put every item on the board at startup, with two reviewers in the assignment pool and no routing rules:

```yaml
review_workflow:
  enabled: true
  reviewers: [alice, bob]
  auto_enroll: true
```

Each option and its default are listed below:

| Option | Default | What the option controls |
|---|---|---|
| `enabled` | `false` | Turns the board on. While `enabled` is false, `/admin/review` and every review API route return 503 with the hint `Set review_workflow.enabled: true`. |
| `reviewers` | none | The usernames that `round_robin` rules draw from. The board's assignee menu lists the same names. |
| `auto_enroll` | `true` | Puts every item loaded from the data files on the board when the server starts. Set to false, the board holds only items that the `enroll_review` automation action adds. |
| `routing` | none | A list of rules that set each new item's starting state, reviewer, and priority. Potato applies the first rule that matches. |

An item that matches no rule joins the board as `pending`, with no reviewer and priority 0. Potato stores the board in `project.sqlite` in the `task_dir`, in the tables `review_items` and `review_transitions`, and keys the rows by `annotation_task_name`. Review state recorded under an old task name stays under the old name. With `auto_enroll` on, the next startup after a rename enrols every item again under the new name. The board starts empty after a rename only when `auto_enroll` is false and no `enroll_review` rule adds items.

Items join the board in exactly two ways. With `auto_enroll` on, the server enrols every item at startup, once the data files have loaded. The `enroll_review` action of the `automation` block enrols an item when the item is added, for items loaded from the data files and for items that arrive while the server runs, such as traces from the webhook. The action runs only while `automation.enabled` is true. Potato has no route for enrolling an item by hand, and the move and assign routes return 404 for an item that is not on the board.

## Routing rules

A routing rule reads the fields that arrive with the item, such as a status or a score, and never reads annotations. The rules below send failed traces to review, spread across the reviewer pool at priority 10, and send low-confidence traces to a second opinion from one named reviewer at priority 5:

```yaml
review_workflow:
  enabled: true
  reviewers: [alice, bob]
  routing:
    - when:
        - {field: "status", equals: "error"}
      state: in_review
      round_robin: true
      priority: 10
    - when:
        - {field: "metadata.confidence", lt: 0.5}
      state: needs_second
      assign_to: alice
      priority: 5
```

Each rule takes five keys:

| Key | Default | What the key controls |
|---|---|---|
| `when` | matches every item | A list of conditions, all of which must match. A single condition may be written as a mapping without the list. |
| `state` | `in_review` | The state the item starts in. A rule without `state`, or with a name outside the five states, also starts the item in `in_review`. |
| `priority` | `0` | An integer. The board sorts each column by priority, highest first, then by the time the item joined, oldest first. |
| `assign_to` | none | One username to assign. `assign_to` takes precedence over `round_robin` when a rule sets both. |
| `round_robin` | `false` | Assigns the reviewer in `reviewers` with the fewest items outside `done`. The count includes `pending` items. A tie goes to the name listed first. With an empty `reviewers` list, the item stays unassigned. |

The conditions use the same grammar as the [triage queue](/docs/agent-evaluation/triage-queue) and the [automation rules](/docs/agent-evaluation/automation-rules). Each condition names a `field`, with dots for nested fields (`metadata.confidence`), and one operator:

- **`equals` and `in`** compare strings without regard to case.
- **`contains`** tests membership in a list field, or a substring in a string field, without regard to case.
- **`exists`** tests whether the field is present, with `exists: true` or `exists: false`. A field set to null counts as absent.
- **`lt`, `lte`, `gt`, and `gte`** compare numbers, and Potato converts numeric strings first.

A missing field never matches `equals`, `in`, `contains`, or a numeric operator, and a condition with no known operator never matches. Potato's key check covers the four `review_workflow` option names and stops at `routing`, so a misspelled rule key such as `asign_to` loads without a warning and does nothing.

Routing runs once, when an item joins the board. Joining is idempotent, so a restart leaves every item's state, reviewer, and priority unchanged. Editing the rules later changes only items that join after the edit.

## Adding items after startup

Items that arrive while the server runs, from the trace webhook or the [tracing SDK](/docs/agent-evaluation/tracing-sdk), join the board through the `enroll_review` action of the [`automation` block](/docs/agent-evaluation/automation-rules). The action applies the routing rules above and logs `automation` as the actor. Potato runs automation rules for items loaded from the data files as well, so `auto_enroll: false` plus a rule with a `when` condition puts only the matching items on the board. The block below adds only failed traces:

```yaml
automation:
  enabled: true
  rules:
    - name: enroll-errors
      when:
        - {field: "status", equals: "error"}
      actions:
        - type: enroll_review
```

An empty `when: []` adds every item. While `review_workflow.enabled` is false, the action records the outcome `skipped` on the automation page at `/admin/automation`.

## Review states and moves

The board shows one column per state, in a fixed order:

| State | Board column | What Potato does with the state |
|---|---|---|
| `pending` | Pending | The default starting state. The reviewer's queue leaves out `pending` items. |
| `in_review` | In review | Listed in the assigned reviewer's queue. |
| `needs_second` | Needs second | Listed in the assigned reviewer's queue. |
| `adjudication` | Adjudication | Listed in the assigned reviewer's queue, and the card links to the [adjudication page](/docs/features/adjudication). |
| `done` | Done | Left out of the reviewer's queue and of the round-robin counts. |

Potato attaches no other meaning to the states, and nothing moves a card automatically after the item joins the board. Neither an annotator saving a label nor an adjudicator submitting a decision moves the card. Admins move cards with the buttons on each card or through `POST /admin/api/review/move`. The buttons offer the neighboring states and **Done**, and the route accepts any of the five states from any state:

```bash
curl -X POST http://localhost:8000/admin/api/review/move \
  -H "X-API-Key: $POTATO_ADMIN_API_KEY" -H "Content-Type: application/json" \
  -d '{"instance_id": "rt-2", "state": "done", "note": "Fix confirmed"}'
```

The response returns the item's updated record. The `note` field is optional, available through the API only, and stored with the item. The board does not display notes. Each state change writes one row to `review_transitions` with the old state, the new state, the actor, and the time. The actor is the logged-in username, or `admin-api` for a request that carries only the admin key, and a move to the state an item is already in writes no row. Moving an item that is not on the board returns 404.

Each card shows the item ID, the first 140 characters of the item's text, a priority badge for any priority other than 0, negative values included, an assignee menu, and the move buttons. The text comes from the item's `text_key` field, or from `task_description` when the `text_key` field is empty or missing. Changing the assignee does not write a transition row. The board cannot change a priority, so a new priority goes through `POST /admin/api/review/assign` with `{"instance_id": ..., "assignee": ..., "priority": ...}`. The assign route always sets the assignee, and a request without `assignee` clears the reviewer.

## Who can see the board

The board page and the routes under `/admin/api/review/` require the `view_admin_dashboard` permission. A browser or API request has the permission in one of three ways:

- **Admin key.** The request carries the [shared admin key](/docs/core-concepts/user-management#the-shared-admin-key) in an `X-API-Key` header, or the browser entered the key on the admin dashboard at `/admin` earlier in the same session.
- **Role.** A logged-in user holds the built-in `admin` role, or a custom role with `view_admin_dashboard`, through the [`rbac` block](/docs/core-concepts/user-management#role-based-access-control).
- **Debug mode.** The server runs with `debug: true` and the request comes from the same machine.

The built-in `adjudicator` role does not include `view_admin_dashboard`, so an adjudicator without admin access can open `/adjudicate` and not the board. A request without the permission gets a 403 with the JSON body `{"error": "Admin access required"}`, on the board page as well as the API routes. While the workflow is off, every route returns the 503 before Potato checks access. With the workflow on, the admin dashboard shows a **Review board** link.

A reviewer needs no admin access to list the reviewer's own assignments. `GET /api/review/my_queue` returns the logged-in user's items in `in_review`, `needs_second`, and `adjudication`, highest priority first, and returns 401 without a login. Potato 2.14.0 ships no reviewer page that calls `/api/review/my_queue`, so a reviewer reads the queue as JSON. The `reviewers` list does not limit who can be assigned. The assign route accepts any username, and the queue route matches on the assignee alone.

## Working with the adjudication block

The `review_workflow` and `adjudication` blocks can run together, and Potato's config validator checks no rule linking the two blocks. The validator does check `adjudication.enabled` against `search.annotator_claim`. Outside Solo Mode and QDA Mode, Potato rejects a config that sets `search.annotator_claim: true` together with `adjudication.enabled: true`, whether or not the review workflow is on.

The two features keep separate records, and moving a card into the **Adjudication** column does not add the item to the adjudication queue. The adjudication block's own [queue criteria](/docs/features/adjudication#queue-criteria-and-order) decide which items enter the adjudication queue, and the board state plays no part. A decision on `/adjudicate` leaves the card in place as well. An adjudicator records the decision through the card's link, and an admin then moves the card to **Done**.

The **open** link on an Adjudication card goes to `/adjudicate?instance=<id>`, and the adjudication page selects the item when three conditions hold:

1. **Adjudication is on.** The config sets `adjudication.enabled: true`. Otherwise `/adjudicate` falls back to Potato's home page.
2. **The visitor may adjudicate.** The visitor has an ordinary login and is on `adjudicator_users`, holds a role with the `adjudicate` permission, or has the admin key in the same session. An admin who opened the board with only the admin key and no login also lands on the home page.
3. **The item is pending in the adjudication queue.** The page loads only the queue's `pending` items and selects the item from that list. Otherwise the page opens the queue with no item selected. After an adjudicator submits a decision on the item, the link selects nothing.

Without an `adjudication` block, the Adjudication column still works as a state, for items waiting on a decision made outside Potato. Setting `show_all_items: true` in the `adjudication` block drops the agreement test. The queue then takes every item with enough annotators, whatever column the item's card sits in. The card's link finds the item for as long as the item stays `pending` in the queue.

## Review outcomes and exports

While the workflow is on, the Throughput tab of the admin dashboard adds three columns per annotator, and `GET /admin/api/throughput` returns the same figures. **Reviewed** counts the items on the board that the annotator saved. Attention-check and gold items do not count. Machine annotators get no row in the table. **First-pass approval** is the share of reviewed items never sent back, counted over the reviewed items that have reached `done`. **Rework** is the share of the reviewed items sent back at least once. A send-back is any move to a state earlier in the board order, such as `needs_second` back to `in_review`.

No export format reads the board's tables, so review states, reviewers, and transitions stay in `project.sqlite` and behind the board API. For a snapshot of the board as JSON, call the board route with the admin key:

```bash
curl -H "X-API-Key: $POTATO_ADMIN_API_KEY" http://localhost:8000/admin/api/review/board
```

The response lists the five states and, under `board`, each state's items with the project name, instance ID, state, assignee, priority, note, creation and update times, and preview text. The full transition history is in the `review_transitions` table. From the `task_dir`, the command `sqlite3 project.sqlite "SELECT * FROM review_transitions"` prints the table.

## Example project

Potato ships a runnable example in [`examples/advanced/review-workflow`](https://github.com/davidjurgens/potato/tree/master/examples/advanced/review-workflow), with six short agent-trace summaries, one radio scheme for a verdict, `alice` and `bob` as reviewers, and the two routing rules from the routing section, minus the `assign_to` line. From the example's folder, start the server:

```bash
potato start config.yaml -p 8000
```

At startup the two failed traces, `rt-2` and `rt-3`, go to **In review** at priority 10, one for `alice` and one for `bob`. Trace `rt-5`, with a confidence of 0.42, goes to **Needs second** at priority 5 with no reviewer, because the example's second rule sets no reviewer. Trace `rt-2` has a confidence of 0.31, below the second rule's 0.5, and stays in **In review** because Potato applies only the first rule that matches. The other three traces stay **Pending**. Open `http://localhost:8000/admin`, enter the admin key that Potato writes to `admin_api_key.txt` in the example's folder, and then open `http://localhost:8000/admin/review` in the same browser.

## Further reading

- [Adjudication](/docs/features/adjudication), for the queue that the Adjudication column links to
- [Agent evaluation](/docs/agent-evaluation/overview), for trace review, LLM judges, and the other agent-evaluation features
- [Automation rules](/docs/agent-evaluation/automation-rules), for the `enroll_review` action and the condition grammar
- [Triage queue](/docs/agent-evaluation/triage-queue), for changing the order in which annotators see items
- [User management](/docs/core-concepts/user-management#role-based-access-control), for the roles that open the board

For implementation details, see the [source documentation](https://github.com/davidjurgens/potato/blob/master/docs/agent-evaluation/review_workflow.md).
