Workflows

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

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 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.

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. The useInstancePreviews contract covers paging and live refresh, and Instance list hooks 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.

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 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 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 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 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.

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 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/workflows-ui/studio for a custom Studio integration 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 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 lists what an adapter implements.

Next steps

Visiting agent?

Was this page helpful?

Sanity logosanity.ioAll Systems Operational© Sanity 2026
Change site theme