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.
Early access
Workflows is in early access, built in public. Read How early access works 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 change.
An evaluation is the engine's current read-only view of stages, activities, fields, and action verdicts. The session refreshes that evaluation as observed content changes. It writes only when your interface calls the session's tick, fireAction, or editField, each of which commits through the engine. The reactive session reference lists every session field and command.
What a session is bound to
A session is bound to one instance ID and one store observer. The observer is what an adapter supplies, so the session itself is store-agnostic: the same evaluation and the same commands appear whether the host is Sanity Studio, an App SDK application, or a custom adapter. Swapping the instance ID resets the projection, and the previous instance's evaluation never carries over into the next one.
A session covers one instance. A list, inbox, or dashboard does not open a session per row. It reads instance previews: reduced rows with the current stage, list-relevant fields, open activities, and lifecycle timestamps, without the definition snapshot or the audit history. The `useInstancePreviews` contract covers paging and live refresh, and Instance list hooks shows the hooks in use.
How the session stays current
The adapter observes the instance, the documents its conditions read, and its active guards. The session waits for all of those sources before it reports ready and produces its first evaluation, so the first evaluation already includes guard verdicts: an action rendered as allowed does not flip to denied because a guard arrived late. Later emissions recompute the evaluation automatically.
A command still commits through the engine. After tick, fireAction, or editField settles, the session evaluates the committed result immediately instead of waiting for the observer to echo the write.
The diagram shows this loop for a custom App SDK interface.
Session states
A session separates three kinds of trouble from ordinary loading. An engine-owned document can be unreadable, because it comes from a newer data model or has the wrong shape. A live read can fail. An evaluation attempt can fail. Each has its own field, and the last successful evaluation can still be present while one of them is set. Check them before treating a missing evaluation as loading. The session state table gives the exact meaning and rendering order of each state.
Preview while typing, commit on a boundary
A field preview changes the projected field value and any advisory verdicts derived from that value while a person is typing. It never changes the committed stage, activity status, or history, and it is never persisted.
A field edit, by contrast, is a real engine commit: it writes a history entry, refreshes guards, and evaluates transitions, all under a revision check. A picker such as an actor, date, or boolean fires one discrete change, so committing on change is fine there. Free text such as a string or a note body has to wait for a deliberate boundary instead: blur, Enter, or Save. A commit per keystroke writes a history entry each time and races 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 has the exact previewField, editField, and discardFieldPreview signatures.
Advisory action verdicts
Whether an action appears, and whether it can be fired, are properties of the evaluation rather than of the authored definition. The evaluated action model is described in Activities and actions. An action has one of three renderings: absent when its filter fails, an automation when it declares when and only the cascade can fire it, or a button that is enabled or disabled with a reason. The action rendering reference maps each one to the evaluation fields.
Verdicts are advisory. They exist so the interface can disable the right controls and explain why; the Content Lake still decides what a token can write. See Evaluation insights for how a verdict explains itself.
Choose a session adapter
The reactive session lives in @sanity/workflow-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 in the introduction shows how they stack:
- For Workflows in Sanity Studio, use the Studio plugin. It provides the ready-made editor and workflow interfaces.
- Use
@sanity/workflow-studiofor a custom Studio integration such as a Document Action, dialog, tool, pane, or input. - Use
@sanity/workflow-sdkin an App SDK application. It supplies the store observer the session needs. See Build a workflow interface with the App SDK for setup and resource routing. - Use
@sanity/workflow-reactdirectly for the hooks an adapter does not re-export, such asuseInstancePreviews. Its@sanity/workflow-react/observersubpath is the adapter SPI: reach for it only when building a new store adapter. The adapter contract lists what an adapter implements.
Next steps
- Build a workflow interface with the App SDK: build a custom workflow interface on the App SDK adapter.
- Reactive session and adapter reference: session states, commands, the preview-list contract, and the observer contract.
- UI components: render a session with the shared components.
Visiting agent?
Workflows includes an MCP server for inspecting, operating, authoring, validating, and deploying workflows. Ask your human to set up the MCP server.
Was this page helpful?
Feedback submitted, thanks for helping us improve the docs. Have you tried these alternatives?