Skip to main content

Stores

A store is where Flow State keeps what has to outlive a function call: sessions, requests and their items, user and org state, resource state and content, and what a paused or crashed run needs to continue. An app names its store once and every flow in it uses that store, so changing where data lives changes no flow code.

The shape is an adapter. An adapter fills the slots the framework reads and writes through (session, request, user, org and the rest of the registry), so a store can be a folder of files, a SQLite file or a Postgres database, or one you write. In-memory (the default), filesystem, SQLite and Postgres ship, plus a Vercel Postgres variant. This page lists what each keeps, how records are owned and keyed, what a custom store has to do, and what each operation costs. Persistence explains the model.

The examples use one app: a support desk whose support-desk flow runs for users in the organizations acme and globex.

Quick answers​

QuestionAnswer
What must a custom store do atomically?Every conditional write: scope set with expectedVersion, the delta verbs, setFieldsIfStatus, deleteIfStatus, resource-state set and delete, lease acquire, wake owe, move and clear, and resource index completeBuild. See Atomicity.
Which records carry an organization?Session, request, active-request entry and wake carry orgId. User records and user- and org-scoped resources carry it in their key. Suspensions, checkpoints, leases, runOnce results, items, events and traces carry none and are reached through the request. See Which records carry an organization.
What persists if I set no stores?Nothing. The app runs in memory and loses every session and request on restart. See The default store.
Can a client look sessions up by metadata?Not on the server. Declare the key as a .readonly() state field and filter on state. See Session lookup by metadata.
Can two processes share one store?Postgres, yes. SQLite, one writer at a time. The filesystem and in-memory stores, no. See Concurrency and sharing.

Declaring stores​

Pass stores to createFlowState. It takes one adapter, which becomes the primary slot of the default profile, or a map of named profiles.

src/flow-state.ts
import { createFlowState } from "@flow-state-dev/engine";
import { sqliteStores } from "@flow-state-dev/store-sqlite";
import { postgresStores } from "@flow-state-dev/store-postgres";
import { supportDesk } from "./flows/support-desk/flow";

export const flowState = createFlowState({
flows: [supportDesk],
stores: {
development: { primary: sqliteStores({ filename: "support-desk.sqlite" }) },
production: { primary: postgresStores({ connectionString: process.env.DATABASE_URL }) },
},
defaultProfile: "development",
});

supportDesk is a registered flow, defined in its own file. How the profile in use is chosen is in Runtime configuration.

SlotBacksIf the profile leaves it out
primary (required)Sessions, requests, users, orgs, active requests, checkpoints, content, resource state, traces, suspensions, leases, wakesNot allowed
busThe change busThe primary backs it if it declares bus (Postgres does). Otherwise an in-memory bus, for one process
blobsAttachment bytesThe primary backs it if it declares blobs (the filesystem store: <rootDir>/blobs). Otherwise .fsdev/blobs/<profile>/ under the working directory when the stores persist, and memory when they do not

There are no other slots. A registry that leaves a member out gets the in-memory one for it.

AdapterImportDeclares
inMemoryStores(options?)@flow-state-dev/engineprimary
filesystemStores({ rootDir, ... })@flow-state-dev/engineprimary, blobs
sqliteStores({ filename, ... })@flow-state-dev/store-sqliteprimary
postgresStores({ connectionString?, ... })@flow-state-dev/store-postgresprimary, bus
vercelPostgresStores({ connectionString? })@flow-state-dev/vercel/storeprimary, bus

Code that builds a registry directly imports from the /host subpaths. They and the conformance suites on @flow-state-dev/engine/testing are listed in Engine API.

The default store​

WithThe app
No storesRuns on inMemoryStores(). Nothing persists across a restart. Stderr gets one line per process per profile: [flowstate] active profile: "<name>" (no `stores` set: the app runs in memory, and nothing persists across a restart). With stores set, the same line has no parenthesis
No stores and NODE_ENV=productionAlso logs one warning per process: "createFlowState has no stores, so this production app runs in memory and loses its sessions and requests on every restart. Set stores to a persistent adapter, such as stores: postgresStores({ connectionString })." Not given when stores was set to the in-memory adapter on purpose

Whether the stores persist decides the default for durable execution (pausing and continuing a run). The durable option is in Pause, resume and replay.

What each store persists​

In-memoryFilesystemSQLitePostgres
Survives a restartNoYesYesYes
Sessions, requests, items, events, runOnce resultsProcess memoryJSON files, NDJSON for eventsTablesTables (JSONB)
User and org recordsMemoryFilesTablesTables
Resource state and contentMemoryFiles in a browsable treeTablesTables
Resource indexNone, lookups scanNone, lookups scanTablesTables
Checkpoints, suspensions, leases, wakesMemoryFilesTablesTables
Active-request registryMemoryactive-requests.jsonTableTable
TracesMemorytraces/ NDJSONTablesMemory
Attachment bytesMemory<rootDir>/blobs.fsdev/blobs/<profile>/.fsdev/blobs/<profile>/
Backs busNoNoNoYes
Registry shared across processesNoNoNoYes for connectionString and { pool }; no for { executor }

What each stored part is​

For each part: who owns it, who can see it, where it is stored, and how many exist.

Stored partOwnerWho can see itWhereHow many
Session record (state, title, description, tags, metadata, journal)One user, one organization, one tenant when the caller sent one, one flow instance. userId, orgId and flowId are stamped at creationThe owner, through the session routes. A client sees state fields the flow exposes or declares .readonly(), plus title, description, tags and metadata; never journal or resourcesstores.session; table sessionsOne per session id per tenant
Request recordThe same four owners as its session, stamped when the request startsIts owner. Another user's, tenant's or (when the record carries one) organization's request answers 404, as a missing one doesstores.request; table requestsOne per request, many per session
Request itemsThe requestThe owner, through the request and session routes, filtered per item visibility. Transient items are never storedSQLite and Postgres: request_items, one row per item. Filesystem and in-memory: inline on the request recordOne per item id per request
Request stream eventsThe requestThe owner, through the request stream routerequest_events; filesystem <id>.events.json (NDJSON)One per event
runOnce resultsThe requestNo route reads themrequest_runonce; filesystem <id>@<key>.runonceOne per distinct key per request
User record (ctx.user.state)One user in one organization, per flow when the flow isolates user stateThe user's own flows; a client sees only exposed fieldsstores.user; table usersOne per (user, org), or per (user, org, flow) when isolated
Org record (ctx.org.state)One organization, per flow when the flow isolates org stateFlows run in that orgstores.org; table orgs; filesystem directory projects/One per org, or per (org, flow) when isolated
Resource stateThe scope instance the resource is declared at: a session, a (user, org) cell, an org. A sharedToLineage session resource stores under the lineageSee Resources and collectionsstores.resourceState; table resource_stateOne per resource key per scope instance
Resource contentSame as its stateSame as its statestores.content; table resource_contentOne per resource key, or none until written
Resource index entriesThe scope instanceNobody; lookups read themresource_index, resource_index_built (SQLite and Postgres)One row per (row, index, value)
Sequencer checkpointThe requestThe engine on resume. state_snapshot items (client: false) reach DevTool and a client that asks for tracesstores.checkpoints; sequencer_checkpointsOne per (request, sequencer instance), overwritten at each step boundary. Kept after completion unless flow.request.cleanupCheckpointsOnTerminal is true
A block's recorded outputThe requestThe developer, in DevTool and traces; a client that asks for trace itemsThe request's items, as block_trace output; a placeholder over 256 KiBOne per execution of a block, including each retry attempt and each loop pass
Tool-cache entryThe store: one request, or one task-board runAny generator in that request or run that calls the same tool with the same argumentsIn memory, a least-recently-used map; not in a stores entryAt most maxEntries (default 5000) per store, one per (scope, id, tool, arguments). Dropped with the store. See Tools
Suspension recordThe request's user and flow instanceThe request's owner, who is listed their pending stops. Debug endpoints list them when debugEndpointsEnabled is onstores.suspensions; suspension_recordsOne per ctx.suspend() call, kept until pruned
Resume leaseThe requestNobodystores.leases; leasesAt most one active per request
Wake (a stored note that a session owes work by a time)The session's owner: flow kind, user, org, tenantNobodystores.wakes (optional); wakesOne per (tenant, session, entry)
Active-request entryThe requestNobody directly; it drives interrupted marking and cross-process abortstores.activeRequests; active_requestsOne per in-flight request, removed at the end
Trace eventsThe requestThe DevTool and debug readsstores.traces; see Trace storeBounded
Attachment bytesThe session, deleted with itThe session's owner, through the upload and read routesThe blobs slotOne per upload

Schedule-index rows are in Schedules and the MCP credential is in MCP server.

A session's suspension record, with its fields and statuses, is in Pause, resume and replay.

The filesystem store​

FactDetail
OptionrootDir, required, no default. Created on first write
LayoutUnder rootDir: sessions/, requests/, users/, projects/ (the org records), content/, state/, checkpoints/, traces/, suspensions/, leases/, wakes/, blobs/, active-requests.json
Resource filesThe key notes/meeting is content/<scope>/<scope id>/notes/meeting.md and state/<scope>/<scope id>/notes/meeting.json, where <scope> is session, user, org or lineage. Segments are percent-encoded and every . in a segment is escaped, so the only . is the extension
State fileOne file per resource: a JSON array ["fsdev.resource-state/1", version, lifecycle, state], committed in one rename
Request filesrequests/<id>.json holds the record with its items inline. <id>.events.json is append-only NDJSON. <id>.abort is the cancel marker. <id>@<key>.runonce is one file per runOnce key
WritesCrash-safe: a temp file, then a rename
LocksPer record and per key, held in memory on the store instance. Two store instances over one directory, in one process or two, are not coordinated
WarningWarns once per process, in any environment, unless developmentOnly: true. The flag changes no behaviour. Write cost grows with the number of items; see Cost per request
onPersistErrorCalled when a background write (requests, traces, the active-request registry) fails, before the failure is logged
Deleting a sessionContent, state and blobs first, then the session record

The SQLite store​

FactDetail
Package@flow-state-dev/store-sqlite. Depends on better-sqlite3 ^11.0.0, a native module. Node 22 or later
Optionsfilename (a path, or ":memory:"), skipSchemaInit (default false), traceStore: { maxRequests }, requestStore (live-tail options)
The fileCreated when missing. Its folder is not: a path in a folder that does not exist throws "Cannot open database because the directory does not exist"
On every openjournal_mode = WAL, busy_timeout = 5000, synchronous = NORMAL, cache_size = -20000, foreign_keys = ON, temp_store = MEMORY
WritersOne at a time. A second writer, in the same process or another, waits up to 5000 ms for the lock and then fails with SQLITE_BUSY. Readers are not blocked by a writer
SchemaCreated on open: sessions, requests, users, orgs, active_requests, request_items, request_events, request_runonce, resource_content, resource_state, resource_index, resource_index_built, sequencer_checkpoints, trace_request_roster, trace_events, schedule_index, suspension_records, leases, wakes
skipSchemaInitSkips the DDL. The database must already have every table, the resource-index tables included. The PRAGMAs are applied either way
close()createSQLiteStores returns a registry with close(). The adapter calls it on dispose
sharedAcrossProcessesAlways false. Treat a SQLite file as local to one host, even on a shared volume
Change busDoes not back bus, so each process gets its own in-memory bus, which says it crosses processes. An open session view then does no timed read, and another process's write to the file is not pushed to it. See The change bus

The Postgres store​

FactDetail
Package@flow-state-dev/store-postgres, on pg ^8.13.0
ConnectionconnectionString, then FSD_DB_URL, then DATABASE_URL. With none of these and no poolOptions host, it throws "no connection string provided". Other shapes: { pool } (your pg.Pool) and { executor } (a QueryExecutor such as PGlite; process-local)
Pool optionsmax (10), connectionTimeoutMillis (10000), idleTimeoutMillis (30000), poolOptions (merged over those, the caller wins), createPool
SchemaCreated on every createPostgresStores call, idempotent, under an advisory lock. On a connection string it tries the lock 20 times, 500 ms apart, and if it never gets it logs "could not acquire schema advisory lock; skipping init" and goes on. skipSchemaInit: true runs none, for a migration run out of band
Tail poolliveTailPool omitted: a connection-string store makes its own pool (max from LIVE_TAIL_POOL_MAX, default 10) for LISTEN. { pool } and { executor } get none unless you pass one. null turns LISTEN off
TablesThe SQLite names without the trace_* tables, since traces stay in memory. Payloads are JSONB
Item idsAn item id over 2600 characters is refused. SQLite has the same limit
close()Hands back the bus's listening connection, then ends the pools

vercelPostgresStores() connects through connectionString, then FSD_DB_URL, then DATABASE_URL. Its options and defaults are in Vercel API.

Who owns a record and what keys it​

RecordPrimary keyOwner fields on the record
Session<sessionId>, or <tenantId>:<sessionId> with a tenant. Nothing else is in the key.flowKind, flowId, userId, orgId, tenantId.
RequestThe request id.flowKind, flowId, userId, sessionId, orgId, tenantId.
User record<user>:~org:<org>, or <user>:~org:<org>:<flow id> when the flow sets isolateUserStateuserId
Org record<org>, or <org>:<flow id> when the flow sets isolateOrgStateorgId, optional userId
Resource state and content(scope, scope id, resource key), with the scope id taken from the owning session, user, org or lineage. The key forms are in Resources and collectionsnone
Checkpoint(requestId, blockInstanceId)the request
Suspension(requestId, suspensionId)userId, flowId, sessionId
LeaserequestIdnone
Wake(tenantId, sessionId, entry)flowKind, userId, orgId
Active requestrequestIdflowKind, flowId, userId, sessionId, orgId, tenantId
  • Key escaping. In user and org keys, \ and : inside an id are backslash-escaped. An id with neither keys as itself. Two different (user, flow) pairs never produce one key.
  • A user in two organizations has two records. Alice in acme and Alice in globex read and write different user records and different user-scoped resources.
  • A missing organization throws. Building a user key with a missing, blank or malformed org throws OrgRequiredError. A valid org id is a non-empty, non-whitespace string with no lone surrogate.
  • The session id is the whole key. Only the session id, behind the tenant prefix, keys a session. The user, organization and flow are fields on the record, not part of the key. Within one tenant the first create at an id gets 201 and every later one gets 409 (Session "<id>" already exists), whoever sends it. If Alice and Bob in acme both create ticket-42, Bob's create gets 409. Reading ticket-42 as Bob then returns Alice's record in an app with no authentication. With authentication on it answers 404 (Unknown session "ticket-42"), as an unused id does. Build the id from everything that tells two sessions apart: user, organization, flow and ticket, as in Session lookup by metadata.
  • Identity and tenancy. Where a session's user and organization come from, the default organization and tenant isolation are in Authentication and tenancy.
  • Listing filters. Session and request lists filter flowKind (the definition) and flowId (the exact instance; a record with no flowId never matches).
  • Records with no organization. A session or request with no orgId is refused on routes that address it and left out of ordinary listings.

Which records carry an organization​

RecordFieldRequired
SessionorgId, column org_id (nullable)Stamped on every new record
RequestorgId, org_idStamped
Active-request entryorgId, org_idStamped
WakeorgId, org_id TEXT NOT NULLRequired
Org recordorgId is the key
User recordPart of the keyRequired, throws without
User- and org-scoped resource state and contentPart of the scope_idRequired
Session-scoped resourcesNone of their own; they follow the session
Suspension, checkpoint, lease, runOnce, items, events, tracesNo org column; reached through the request

Session lookup by metadata​

FactDetail
Set at createsessionId, title, description, tags, metadata (a free-form object), state
metadataThere is no metadata filter on the route, the client or the store. A caller lists and filters metadata in memory

The list route's parameters, ordering, editing and status codes are in HTTP API.

The lookup the server does filter is readonly state. Declare the key as a .readonly() field of the session's stateSchema, set it at create, and list on it.

src/flows/support-desk/flow.ts
import { defineFlow, handler } from "@flow-state-dev/core";
import { z } from "zod";
import { findTicket } from "../../lib/tickets";

const ticketState = z.object({ ticketId: z.string().readonly() });

export const supportDesk = defineFlow({
kind: "support-desk",
session: { stateSchema: ticketState },
actions: {
loadTicket: handler({
name: "load-ticket",
sessionStateSchema: ticketState,
execute: (_input, ctx) => findTicket(ctx.session.state.ticketId),
}),
},
})();
src/lib/ticket-sessions.ts
import { createClient } from "@flow-state-dev/client";

export function ticketSessions(userId: string, orgId: string) {
const client = createClient({ userId, baseUrl: "" });
// The id is the session's whole key, so it names every part that tells two apart.
const sessionIdFor = (ticketId: string) =>
["support-desk", orgId, userId, ticketId].map(encodeURIComponent).join("|");
return {
create: (ticketId: string) =>
client.flow("support-desk").createSession({
sessionId: sessionIdFor(ticketId),
state: { ticketId },
}),
find: (ticketId: string) =>
client.sessions.list({ flowKind: "support-desk", state: { ticketId } }),
};
}
  • A list on state needs flowKind or flowId. A field that is not readonly on that flow, or a filter with no flow, is refused 400 with the reason, not ignored.
  • The filter runs in the store's query, never after it. Readonly fields are read from a z.object at the top of the state schema, also through an .optional(), .nullable(), .default(), .readonly() or refinement around it. A union, intersection or lazy schema at the top has no readonly fields.
  • Readonly fields are the only state a client can read back besides exposed fields.
  • encodeURIComponent escapes every |, so no two (org, user, ticket) triples join to one id. client.flow("support-desk").identity() returns the caller's { userId, orgId }.
  • A derived id is create-if-absent: a second create at it gets 409 and leaves the first record as it was. The status codes are in HTTP API.

What a custom store must guarantee​

A custom store is a StoreAdapter whose resolve() returns a registry, or part of one. Members it leaves out come from in-memory. StoreAdapter, StoreRegistry, CapabilitySlot and StoresConfig import from @flow-state-dev/engine, and the store interfaces from @flow-state-dev/engine/host. The contract is the doc comments on those interfaces, and the conformance suites in @flow-state-dev/engine/testing, which the built-in stores run. The member lists below name the types, and the package source is the authority for exact signatures.

MemberRequired
session, request, user, org, activeRequests, content, resourceState, checkpoints, traces, suspensions, leasesYes, in a registry you build
wakesNo. Without it the host logs once at start: [flow-state] this host keeps no wakes: debts are paid on their fast paths only. A host without wakes does not retry work owed by a time after a crash. How this affects task-board notices is in Task board
busNo. An in-memory bus fills in
blobsNo. Without it the upload and read routes answer attachments_not_configured
checkpoints.persists, suspensions.persistsSet false only when the store keeps nothing past the process. Absent means it persists. This decides durable execution's default

What must be atomic​

OperationMust be one atomic step
Scope set(id, value, expectedVersion)Compare the stored version and write. "any" always writes. A number writes when the stored version equals it (0 means a live record at version 0). "absent" writes when no record exists at any version. On conflict, return { ok: false, conflict: { currentValue, currentVersion } }; never throw
Two concurrent creates at "absent"Exactly one wins. The loser gets the winner's record
Delta verbs patchField, incField, pushToArray, deleteField (optional)The same version check as set. Touch only state. Write the caller's updatedAt. incField treats missing or null as 0 and throws on a non-number. pushToArray treats missing as [] and throws on a non-array, null included. "absent" throws
RequestStore.setFieldsIfStatus(id, fields, allowedStatuses, updatedAt, expectedIncarnation?)Check the status (and incarnation) and write. Returns { applied, status }. An absent record gives { applied: false, status: undefined }. An empty allowedStatuses matches nothing. The incarnation is an id stamped on the request record when it is created. A request id can be used again once its record is deleted, and the new record gets a new incarnation, so a caller holding a different one is addressing an earlier record with that id: the call reports it as absent and writes nothing. fields may move status together with its result. setFieldsIfStatus is the only method that writes the abort flag
RequestStore.deleteIfStatus(id, allowedStatuses)Check the status and delete the record, items, events and runOnce results. Wait for in-flight writes to the id; do not drop them
RequestStore.delete(id)Remove items, events and runOnce results first, then the record, only after every child delete has succeeded. Drop writes queued for the id
A request set that settles itLand the items it carries in the same write as the status. A set that omits items keeps the stored ones
Resource-state set and deleteCompare the live version and write together. The first create writes 1, each commit adds 1, and a version is never reused. 0 is create-if-absent, and a tombstone satisfies it. "absent" is refused by a tombstone. Snapshot the caller's value before yielding. Index entries commit with the row or not at all
Lease acquireOne active lease per request: concurrent first acquires from different holders grant exactly one. An expired lease can be taken over. A stale holder's release does not free a newer holder's lease
Wake owe, move, clearA wake has dueAt, when the work is due, and landBy, when the run that owes the work should have finished writing. A check that finds nothing owed before landBy keeps the wake until landBy instead of clearing it. owe keeps one wake per key, with the earlier dueAt and the later landBy, and adds 1 to its version. move and clear take the version the caller read and apply only if the wake is at that version, so a wake written while the host is handling the old one survives
Resource index completeBuildAdd the entries and mark built in one commit, only if the building marker it began is there. A set leaves the key's entries as exactly the ones it lists, in the row's commit
listPendingForUserOne query joining each suspension to its request, not a read then a filter

Other obligations​

MemberObligation
RequestStore.persistItems(requestId, items)Union by item id, last write wins. Existing items keep their position and new ids append. Re-persisting an id whose content changed writes the latest content. Items are readable before the request settles
flushItems, flushEventsResolve when pending writes have landed. A failed write rejects
countItems(requestId)Count without loading payloads. 0 for an unknown request
isAbortRequested(requestId)A primary-key lookup, constant in the number of items: it runs on every heartbeat for every running request. false for an unknown request
set and the abort flagNever honours abortRequested from a full record. The stored value survives a record that omits it, and a record that carries it cannot set one
getEvents(requestId, fromSequence?)Events with sequence_number > fromSequence, sorted. No argument returns the whole log
subscribeToEvents(requestId, options)Catch-up for sequence_number > fromSequence, then live, with no duplicates across the boundary. Ends on signal.abort, on a terminal event (completed, failed, incomplete, aborted, suspended, interrupted), or after livenessTimeoutMs (default 30000) of silence with a synthetic request.interrupted. followThroughSuspend keeps going past request.suspended. More than maxPendingEvents (default 1000) pending throws StoreSubscriptionError("backpressure_overflow"). Call options.isStillAuthorized after every read that returned events and before yielding any; end without yielding when it resolves false or throws. SQLite, filesystem, and Postgres without liveTailPool poll until one of those ends it. No built-in store ends after the catch-up
getRunOnceResult, setRunOnceResult{ found, value }. set replaces any prior value for (requestId, key). Removed when the request is deleted; deleting r leaves the results of an id that merely starts with r
RequestRecord fieldsPersist finalizedAtMs (null means not finished, absent means unknown; tell them apart with === null), heartbeatsUntilFinalized, incarnation (the id described under setFieldsIfStatus in What must be atomic: stamped once at creation, carried unchanged), result (its shape is in HTTP API), spentByModel, spentThroughItemIndex, spentHarnessRuns, source (a record without one reads as "http"), attachments, historyStart
SessionRecord fieldsPersist flowId, parentSessionId, lineageId, topic, coordinate. An unset field may read back null from a store that nulls absent keys, so guard == null
FilterstenantId and orgId as present-versus-absent exact match, safe with NULL. parentage and flowId as below
ContentStoreget, set (create or overwrite, last write wins), delete, getAll, getByPrefix (an empty prefix returns all; wildcards are literal), deleteAll. Keyed (scopeType, scopeId, resourceKey)
ResourceStateStoreReads return live rows only; a tombstone reads as absent. delete keeps the version and drops the payload. deleteAll tombstones the scope. purgeTombstones is the only reclaim. A numeric expectedVersion must be a non-negative integer, or it throws TypeError, never a conflict. A row with no version reads as live at version 1. Every state crossing the boundary is a deep copy
ResourceStateStore.indexesAll four verbs (state, beginBuild, completeBuild, findKeys) or none. Without them, lookups scan
CheckpointStoreLatest only per (requestId, blockInstanceId). delete at sequencer end. deleteForRequest is idempotent
SuspensionStoreset, get, list, deleteForRequest, pruneTerminalBefore(cutoff, limit) (never touches pending; returns rows deleted), listPendingForUser
TraceStoreappendEvent, flush, getEvents(requestId, fromSequence?) (exclusive lower bound), listRequestIds (insertion order). Bounded retention is the store's job
ActiveRequestRegistryregister, heartbeat, deregister, listStale(thresholdMs), listAll, get. Declare sharedAcrossProcesses: absent means not shared
RetentionSession retention deletes whole past requests, only once finalizedAtMs is set, through deleteIfStatus. Its settings are in Flows and actions

List filters a store applies in its query​

OptionContract
SessionListOptions.parentageOmitted or "top-level": only sessions with no parent. "all": every session. { parentOf: id }: that session's children. A null parent counts as none. An absent parentage narrows, where an absent tenantId or orgId widens
SessionListOptions.stateExact match on top-level state fields with string values. The route admits only .readonly() fields of the addressed flow
SessionListOptions.orderBy"updatedAt" (default) or "createdAt", ordered (createdAt, id) so paging neither skips nor repeats a written row
RequestListOptions.sessionIdOne id (equality) or an array (set membership; empty matches nothing)
RequestListOptions.statusOne status or an array. An empty array matches nothing; it is not "no filter"
RequestListOptions.orderBy"updatedAt" (default), "startedAtMs" ((startedAtMs, id)), or "none" (unordered; with limit: 1 it stops at the first match)
RequestListOptions.withItemsDefault false: SQLite and Postgres leave items off. In-memory and filesystem keep items on the record and return them whatever the flag
limit, offsetOn every list

Each member's conformance suite is exported from @flow-state-dev/engine/testing, listed in Engine API.

Concurrency and sharing​

StoreScope-state and resource-state writesSeveral processes on one store
In-memoryAtomic in the storeEach process has its own data
FilesystemPer-record and per-key lock on the store instanceNot supported. Two instances over one directory race: both create-if-absent calls can succeed, and one record can overwrite another
SQLiteAtomic: one transaction per write, and the status-checked writes take the write lock firstOne writer at a time (a second waits up to 5000 ms, then SQLITE_BUSY). Readers run beside it. sharedAcrossProcesses is false. Does not back bus
PostgresAtomic in the store. Schema init runs under an advisory lockEvery connection to the database. sharedAcrossProcesses is true for connectionString and { pool }. Backs bus
  • Increments and appends combine; other writes replace. incField and pushToArray apply to the value the store holds when they run, so concurrent increments and appends both land on a built-in store. patchField replaces. The filesystem session, user and org stores have no deleteField, and no store has it on the request record.
  • Separate dispatch and worker processes must share one durable store, and a cancel reaches a request in another process only through a shared request store. Both are in Background work.
  • After a restart, an in-flight request on a store that persists reads interrupted once its last heartbeat is stale and a sweep has run. In memory, the registry and record die with the process, so nothing is marked. A suspended request is left alone.

Cost per request​

WhatCost
Items, SQLite and PostgresOne row per item in request_items, upserted by (request_id, item_id). Only items whose serialized content changed since the last write are written. A block's block_trace item keeps one row in request_items, rewritten when its status moves from in_progress to completed and left alone by writes that did not change it
Items, filesystem and in-memoryInline on the request record. Every item write reads, merges and writes the whole record, so the cost grows with the number of items. countItems reads the record
Settling writeLands the final items and the status together
Events, SQLite and PostgresOne row per event in request_events
Events, filesystemAppends only the new events to one NDJSON file per request
list()SQLite and Postgres read no items unless withItems: true. Filesystem and in-memory return the items on each record either way
countItemsAn indexed COUNT on request_items (SQLite, Postgres). A record read on the filesystem. Used by retention's maxItems
Abort checkOne primary-key read per heartbeat per running request. A stat of the .abort marker on the filesystem. The heartbeat interval is in Runtime configuration
CheckpointOne row per (request, sequencer instance), overwritten at each step boundary and each pause, and deleted when the sequencer ends. Constant however many steps
runOnceOne row (or file) per distinct key per request
An open session viewWith a bus that crosses processes, it reads the store after each change notice, at most once a second. Otherwise it reads once a second. A view of a quiet session costs nothing on a crossing bus. Connection behaviour is in Items and the stream; client timers are in Client configuration
Schema initSQLite: on open unless skipSchemaInit. Postgres: on every create unless skipSchemaInit. vercelPostgresStores skips it

How much history a request loads and when old requests are evicted are session settings in Flows and actions. Resource deletes and their rows are in Resources and collections.

The change bus​

A bus carries notices that something under a topic changed. It never carries rows, delivers at most once, and publishes only once the change can be read. Every request and session write that lands publishes. A write that did not land (a version conflict, a failed status check) publishes nothing, and neither does persistEvents. An open session view reads the store after a notice.

MemberMeaning
publish(notice)A failure must not fail the write
subscribe(topic, listener)A topic is { scope, id, tenantId, resource? }. A subscriber to a scope hears every notice under it. One narrowed to a resource hears only that resource's
crossesProcessestrue only while a change in any process serving the app reaches this one. While true, session views stop their timed read and clients stop their fallback polls, so a wrong true is a view that stops updating
onCrossingChange(listener)A change to false puts waiting views back on the timed read
BusBehaviour
In-memory (the default, and what a SQLite profile gets)crossesProcesses is always true, even when another process writes the same SQLite file, so views on it do no timed read. It is right for an app that runs as one process. createInMemoryBus() from @flow-state-dev/engine/host lets an adapter fan out in-process
PostgresOne LISTEN connection per process, taken from the tail pool by the first subscriber and handed back by the last. A process with no open view (a worker, fsdev run) publishes and holds none. It pings itself every 2 s and says it crosses while it hears its own ping. Unheard for 3 s, or connection lost, it says it does not, views go back to the once-a-second read, it reconnects with backoff (100 ms to 30 s), sends each subscriber one resync notice, and says it crosses again on the next ping heard. A payload of 8000 bytes or more drops its ids and task-board partition first, then its resource narrowing, and goes out as the bare scope. A transaction-mode pooler accepts LISTEN and delivers nothing; the ping is how that shows
Postgres with no tail pool{ executor } or { pool } without liveTailPool, or liveTailPool: null: it never listens and never says it crosses. Writes notify for { pool } (so vercelPostgresStores) and a connection string. { executor } with no tail pool sends no notices
Your own registryA StoreRegistry you build can set bus. The engine otherwise fills an in-memory bus

With Postgres and several servers, a view open on one server sees a change saved on another as soon as it is saved, with no configuration.

On SQLite, a write from another process reaches an open view only when a change made in the view's own process wakes a read of that session, or when the view reconnects (the server closes each session stream after 15 minutes and the client reconnects). That covers several servers on one SQLite file, and fsdev run or fsdev chat writing the SQLite file a running fsdev dev reads.

Which store each fsdev command opens, and --store, are in CLI.

Trace store​

Traces are kept in memory by default (and by the Postgres adapter). The in-memory, filesystem and SQLite factories take a traceStore option: createInMemoryStores({ traceStore: { maxRequests, maxBytesPerRequest } }), filesystemStores({ traceStore: { maxRequests } }), sqliteStores({ traceStore: { maxRequests } }). The event record, retention and what a failed write does are in Items and the stream.

Moving data between stores​

No command copies records from one adapter to another. A script reads one store through its calls and writes the other, as in Move data between stores. These are the limits of that route.

TopicBehaviour
Paused runsA run waiting at a stop for an answer is not on the new store. Answer or discard every stop before a move.
Attachment bytesHeld outside the store, in the folder the blobs slot uses (.fsdev/blobs/<profile>/ by default). A move does not carry them.
Traces, leases and dynamic schedulesNot carried. The new store starts with no leases. Recreate schedules there, as in Schedules.
The in-memory storeKeeps data for one process only, so a move script in another process cannot read it.
Records with no flowId or orgIdCarry no attribution and arrive as stored. They need the same attribution they needed on the old store.
Write modes"absent" writes only when the key is missing. resourceState.set honours it and content.set overwrites, so a rerun leaves records alone and overwrites content.
session.listReturns top-level sessions by default. parentage: "all" includes child sessions.
User recordsA user in two organizations has two records, so a user is keyed by record, not by user id.
Schema creationThe Postgres adapter creates its tables when it opens.
Tenant sessionsA tenant session record's id is <tenantId>:<sessionId>, and its requests carry the bare session id and the tenantId.

Next​