Lifecycles are machines

Use an XState machine for the application’s named states, retries, cancellation, or a lifecycle you need to resume or inspect. Model the states and the events that move between them instead of accumulating booleans whose combinations have no meaning.

An actor is a running unit that performs declared work. A side effect is work outside the state description, such as reading a file. A scope20 owns cleanup when that work ends.

setupEffect declares actors. fromEffect defines an Effect-backed side effect with an input schema. createEffectActor starts the machine inside Effect’s scope.

The machine chooses transitions and records its outcome. The invoked actor performs the file read.

join waits for the final outcome. Effect.orDie treats a machine-level failure as a programming error. The domain read failure remains an explicit machine state.

packages/core/src/inspect-machine.ts is the working example. watchActor makes the run visible to devtools. The rule in scripts/oxlint-plugin-xstate-effect.ts enforces declared actors by catching inline Effects in machine actions and actors.

See one capability, every surface18 for how a capability can own a machine and the fence39 for the rule that protects it.

Sources

  1. rat-stack/AGENTS.md at main · joelhooks/rat-stack · GitHub. GitHub joelhooks/rat-stack. Lifecycle rule; used for declared Effect actors and explicit states. Accessed 2026-10-01.
  2. rat-stack/packages/core/src/inspect-machine.ts at main · joelhooks/rat-stack · GitHub. GitHub joelhooks/rat-stack. Inspection machine; used as the working actor and scope example. Accessed 2026-10-01.
  3. rat-stack/packages/core/test/inspect-machine.test.ts at main · joelhooks/rat-stack · GitHub. GitHub joelhooks/rat-stack. Machine tests; used for the inspection lifecycle's behavior. Accessed 2026-10-01.

Last changed 2026-10-07 in f1a00f2. Source on GitHub. Change log.

Linked from

  1. add-a-capability. Learn how one contract and its handler become a command, HTTP route, MCP tool, browser RPC, and sandbox call.

    Keep it small; put real work in a service or lifecycle machine.¶

  2. add-a-lifecycle-machine. Learn how XState owns a lifecycle while Effect owns its work, errors, and services.

    A lifecycle machine defines named states and the events that permit movement between them.

  3. Agent guide. An Effect stack so pure (aspirational) Kit Langton will blush.

    Lifecycles are machines — XState owns finite lifecycle states while declared Effect actors own side effects.

  4. Agent rules for rat-stack (AGENTS.md). What you may change, which commands to run, and which changes need approval.
  5. Build and run rat-stack (README.md). What is in the repo, how the example works, and how to run it.
  6. Change log. What changed in the files served here, newest first.

    Lifecycles are machines — edited: feat(learn): teach cards 43 to 62 with plain lines, diagrams and snippets

  7. Code snippets quote a pinned source. Shipped design brief: pinned Git objects, typed diagnostics, and one build-only snippet model for both views.

    Lifecycles are machines applies when remote acquisition adds retries, cancellation, or resumability.

  8. Concurrent work needs an owner and a bound. Limit active work, retain result order, and stop child work when its owning lifetime ends.

    In rat-stack, machines own finite domain retries and cancellation.

  9. Effect 4 study: September 2026. Dated Effect 4 source studies from September 2026; current versions live in pins.md.

    ts, and lifecycles are machines.

  10. Full agent guide. An Effect stack so pure (aspirational) Kit Langton will blush.
  11. Handle expected failures without hiding defects. Declare expected failures, preserve their context, and recover by tag without turning crashes into successful outcomes.
    Link context

    The inspection machine uses it where the machine’s result is handed back to Effect because its expected file failure already travels through the Unreadable outcome.

  12. HTTP success needs a status check and a decoder. Supply the client, check the response status, decode accepted data, and name failures at the adapter boundary.

    In rat-stack, machines own finite retry lifecycles.

  13. Infrastructure as effects. Sam Goodwin relates application operations to infrastructure requirements in one typed program.

    Use an XState machine for named states, retries, cancellation, or a lifecycle to resume or inspect.

  14. Model-based testing. Describe what a system should do as a small model, generate action sequences, and check the real system against the model.

    Machines in this repo are lifecycles, so each one is a ready-made test model.

  15. One capability, every surface. A schema-typed contract and one handler feed every interface rat-stack keeps.

    See lifecycles are machines for stateful handlers and cartridges for the infrastructure boundary.

  16. Rat Stack lore | rat-stack. Short, source-grounded notes on the ideas and decisions behind rat-stack.

    Lifecycles are machines — XState owns finite lifecycle states while declared Effect actors own side effects.

  17. Schema projections: 2026-09-18 history. Historical Effect rc.115 proposal and implementation receipts from 2026-09-18; use the one-capability-every-surface lore page for the current pattern.

    packages/core: FileStats became a Schema; inspectFile is the first capability; the lifecycle machine moved here from the CLI so every surface runs it.

  18. Scopes release resources when work ends. Acquire resources lazily, keep their use inside the owner, and release them after success, failure, or interruption.

    In rat-stack, machines own finite business lifecycles.

  19. Source change history (log.md). The generated change log as Markdown.

    Lifecycles are machines — edited: feat(learn): teach cards 43 to 62 with plain lines, diagrams and snippets

  20. Structure an Effect codebase by domain. Start with folders for application work, services and Layers in the same file, and startup code that supplies implementations.

    In rat-stack, a machine owns finite modes, cancellation, or legal event sequences.

Unlinked mentions (21)