state.do
State Machines That Never Lose Progress
Durable execution with automatic state persistence, sub-100ms state transitions, and zero data loss. Build complex workflows that survive failures, handle human approvals, and resume exactly where they stopped.
import { State, on } from 'state.do' // Durable state machine with automatic persistenceconst OrderState = State({ initial: 'pending', states: { pending: { on: { PAYMENT_RECEIVED: 'processing' } }, processing: { on: { ITEMS_SHIPPED: 'shipped', FAILED: 'error' } }, shipped: { on: { DELIVERED: 'completed' } } }}) // React to state transitions and trigger workflowson.Order.state.changed($ => $.to === 'processing' ? $.Warehouse.send.ShippingRequest({ orderId: $.data.orderId }) : $.Customer.send.Email({ template: `order-${$.to}` }))
Frequently asked questions
State.do uses declarative TypeScript to define workflows with automatic state persistence and failure recovery. No visual builders, no XML, no proprietary DSLs. Just code that reads like business logic with durable execution, automatic retries, and time-travel debugging. State transitions are atomic operations with full ACID guarantees.
Automatic retry with exponential backoff (100ms to 1hr), dead letter queues, and error recovery workflows. Define custom retry policies, fallback strategies, and compensation logic. State is persisted before each transition—never lose progress or leave workflows in inconsistent states. Failed steps can be retried manually or automatically based on error type.
Yes. Durable execution with automatic state persistence means workflows can wait for external events, human approvals, or scheduled times without consuming resources. A workflow can pause for days waiting for payment confirmation, then resume in milliseconds when the webhook arrives. No timeouts, no polling—just efficient event-driven execution.
Full local testing with Vitest or Jest. Mock external services, simulate failures, and validate state transitions deterministically. Time-travel debugging lets you inspect workflow state at any point in execution history. Step through state transitions, replay events, and verify behavior under all conditions before deploying to production.
Yes. Workflows are semantic objects that agents can read, analyze, and optimize autonomously. Agents can add error handling, insert monitoring steps, restructure state machines based on performance data, or suggest improvements to transition logic. The state machine definition is code—agents can refactor it like any other TypeScript with full type safety.