Generated State Machines Turn Agent Plans Into Runtime Contracts
project-specific XState 5 plans map directly to joelclaw agent loops and workflow-rig handoffs
The source page is gone, which is annoying but clarifying: the durable bit is Joel’s Slack backfill. The idea was pi-cloud-workflows taking inspiration from Claude Code-style “ultracode” workflows and spinning them up as effectively open-ended Cloudflare Workers.
The clever part is the post-planning step. Instead of letting an agent wander through a checklist, the system dynamically generates a project-specific XState 5 machine. That turns the plan into a runtime contract: named states, transitions, retries, cancellation paths, and handoffs. Less vibes, more executable shape.
For joelclaw, the useful pattern isn’t “run agents in the cloud.” It’s compile the plan into a machine before execution. Planning produces intent, the generated state machine makes the lifecycle explicit, and the runner can execute that shape across Cloudflare Workers, Cloudflare Workflows, or whatever runtime is least fucky for the job.
This is a good fit for agent loops because it gives reviewers, operators, and future agents a concrete artifact to inspect. If the run stalls, you don’t ask “what was the agent trying to do?” You ask “what state is the machine in, what transition failed, and what event gets it moving again?”
Key Ideas
- A post-planning phase can compile an agent’s plan into an executable XState 5 machine instead of leaving it as prose.
- Project-specific state machines make agent lifecycle states, retries, cancellation, and handoffs visible instead of hiding them in prompt soup.
- Cloudflare Workers make the “spin up many tiny executors” idea cheap enough to explore, but the durable artifact is the machine, not the worker.
- Cloudflare Workflows and Durable Objects are adjacent runtime pieces for long-running coordination, state, and recovery.
- The pattern maps cleanly to joelclaw agent loops: planner emits intent, machine generator emits control flow, runner executes, reviewer inspects the machine state.