> For AI agents: the complete Sanity documentation index is available at [https://www.sanity.io/docs/llms.txt](https://www.sanity.io/docs/llms.txt).

# The reactive session

How a reactive session projects one workflow instance for a UI: what keeps it current, what each session state means, and when a preview becomes a commit.

> [!WARNING]
> Early access
> Workflows is in early access, built in public. Read [How early access works](https://www.sanity.io/docs/workflows/prerelease) before you rely on it.



A reactive session is the live, UI-facing view of one workflow instance. Use it when you are building a custom Workflows surface that must stay current as the instance, referenced content, or [guards](https://www.sanity.io/docs/workflows/guards) change.

An evaluation is a read-only snapshot of an instance. It lists the current stage, its activities and fields, and whether each action can be fired. The session evaluates the instance again whenever the content it watches changes. It writes to the instance only when your interface calls one of its commands: `tick`, `fireAction`, or `editField`. Each command commits through the engine. For every session field and command, see the [reactive session reference](https://www.sanity.io/docs/workflows/custom-reactive-adapters).

## What a session is bound to

A session belongs to one instance ID. It reads documents through an observer, which an adapter supplies for its host. The session works the same way in every host, so it shows the same evaluation and commands in Sanity Studio, an App SDK application, or a custom adapter. If you change the instance ID, the session starts over. The new instance never shows the previous instance’s evaluation.

A session covers one instance, so don’t open a session for each row of a list, inbox, or dashboard. Read instance previews instead. A preview is a smaller copy of an instance. It has the current stage, the fields a list needs, the open activities, and the start and end times. It leaves out the definition snapshot and the history.

Previews come from a GROQ query, so they can miss a change made in the last second or so. See [commit visibility](https://www.sanity.io/docs/workflows/engine). The [useInstancePreviews contract](https://www.sanity.io/docs/workflows/custom-reactive-adapters) covers paging and live refresh, and [Instance list hooks](https://www.sanity.io/docs/workflows/ui-components) shows the hooks in use.

## How the session stays current

The adapter watches three sources: the instance, the documents its conditions read, and its active guards. A guard is a rule, stored in the Content Lake, that the engine and Workflows surfaces check before a write to a document; the Content Lake doesn’t enforce it. The session waits for all three sources before it reports `ready` and produces its first evaluation. So the first evaluation already accounts for guards, and an action shown as allowed doesn’t switch to denied when a guard loads late. After that, the session evaluates again each time a source changes.

Commands still commit through the engine. When `tick`, `fireAction`, or `editField` finishes, the session evaluates the committed result at once. It doesn’t wait for the observer to report the write back.

The diagram shows this loop for a custom App SDK interface.

![The App SDK adapter observes synchronized documents from the Content Lake and feeds them into a reactive session. A custom UI renders the evaluation, previews an editor's tentative field value, then invokes an engine commit and receives the settled evaluation before the observer echoes the committed documents.](https://cdn.sanity.io/images/3do82whm/next/99c20c9a138d971ad85a8800d1517ea7e093f433-2800x2068.png)

## Session states

A session reports three kinds of problems separately from loading. Each has its own field:

- `invalid`: an engine-owned document can’t be read safely, because it needs a newer engine than this one, or its shape is wrong.
- `error`: a live read failed.
- `evaluationError`: an evaluation failed.

The last successful evaluation can still be present while one of these fields is set. So check these fields before you show a missing evaluation as loading. The [session state table](https://www.sanity.io/docs/workflows/custom-reactive-adapters) gives the exact meaning of each state and the order to check them in.

## Preview while typing, commit on a boundary

A field preview shows a new field value while a person types. It also updates any action verdicts that depend on that value. A preview never changes the stage, activity statuses, or history, and the engine never saves it.

A field edit is different. `editField` commits through the engine: it writes a history entry, updates guards, and checks transitions. It also checks the instance revision, so it fails if the instance changed since the session read it. When to commit depends on the input:

- Pickers, such as an actor, date, or boolean input: commit on change. Each choice is one discrete change.
- Free text, such as a string or a note: commit on blur, on Enter, or when the person clicks **Save**. If you commit on every keystroke, each keystroke writes a history entry and can fail the revision check.

When editing ends without a commit, the interface discards the preview and the next evaluation returns to the committed value. The [command table](https://www.sanity.io/docs/workflows/custom-reactive-adapters) has the exact `previewField`, `editField`, and `discardFieldPreview` signatures.

## Advisory action verdicts

Whether an action appears, and whether it can be fired, comes from the evaluation, not from the definition alone. [Activities and actions](https://www.sanity.io/docs/workflows/activities-and-actions) describes how actions are evaluated. Render each action in one of three ways:

- Hidden: the action’s `filter` fails.
- Automation: the action declares `when`, so only the engine can fire it, during a cascade.
- Button: enabled, or disabled with a reason.

The [action rendering reference](https://www.sanity.io/docs/workflows/custom-reactive-adapters) maps each one to the evaluation fields.

Verdicts are advisory. They let your interface disable the right controls and explain why. The Content Lake still decides what a token can write. To learn how a verdict explains itself, see [Evaluation insights](https://www.sanity.io/docs/workflows/evaluation-insights).

## Choose a session adapter

The reactive session lives in `@sanity/workflows-ui/react` and sits directly on the engine. An adapter gives the session a way to watch documents in one kind of host. The Studio plugin builds its interface on top of the Studio adapter. The [package layering diagram](https://www.sanity.io/docs/workflows/introduction) in the introduction shows how they stack:

- For Workflows in Sanity Studio, use the [Studio plugin](https://www.sanity.io/docs/workflows/studio-plugin). It provides the ready-made editor and workflow interfaces.
- Use `@sanity/workflows-ui/studio` for a [custom Studio integration](https://www.sanity.io/docs/workflows/custom-studio-integrations) such as a Document Action, dialog, tool, pane, or input.
- Use `@sanity/workflows-ui/sdk` in an App SDK application. It supplies the store observer the session needs. See [Build a workflow interface with the App SDK](https://www.sanity.io/docs/workflows/app-sdk) for setup and resource routing.
- Use `@sanity/workflows-ui/react` directly for hooks that the adapters don’t re-export, such as `useInstancePreviews`. To build a new store adapter, use its `@sanity/workflows-ui/react/observer` subpath. The [adapter contract](https://www.sanity.io/docs/workflows/custom-reactive-adapters) lists what an adapter implements.

## Next steps

- [Build a workflow interface with the App SDK](https://www.sanity.io/docs/workflows/app-sdk): build a custom workflow interface on the App SDK adapter.
- [Reactive session and adapter reference](https://www.sanity.io/docs/workflows/custom-reactive-adapters): session states, commands, the preview-list contract, and the observer contract.
- [UI components](https://www.sanity.io/docs/workflows/ui-components): render a session with the shared components.

> [!NOTE]
> Visiting agent?
> Workflows has MCP tools that let an agent inspect, operate, author, validate, and deploy workflows. An agent host embeds these tools. Ask the person you work for whether your host [includes the Workflows tools](https://www.sanity.io/docs/workflows/mcp).



