State Machine

A mechanism that strictly defines all valid states and permitted transitions for a system, preventing operations from executing out of sequence or entering invalid states.

General Meaning

A finite state machine (FSM) is a computational model where an entity resides in exactly one state out of a predetermined finite set of states at any given moment, transitioning between them only in response to explicit events according to defined transition rules.

Rather than relying on arbitrary boolean flags or mutable variables scattered throughout an application, an explicit state machine codifies an allowlist of valid transitions. This structural constraint eliminates illegal state skips, unexpected concurrent overrides, and deadlocks across complex asynchronous workflows.

Why It Matters

  • Blocking invalid operational sequences: Prevents prohibited transitions, such as completing an unstarted task or resuming an abandoned job without proper review.
  • Eliminating ambiguity around completion: Distinguishes actively working, PR review, deployment waiting, and dependency blocked states instead of lumping them into a simplistic binary status.
  • Enabling exhaustive verification and automated testing: Finite states and explicit transitions allow comprehensive unit testing across boundary conditions and edge cases.

How the Site Factory Uses It

The Site Factory applies explicit state machines across task lifecycles, agent-to-agent (A2A) stages, and job dispatching. In honbu/work.py, tasks progress through ready, running, blocked, scheduled, pr, deploy, done, cancelled, and hold, where done and cancelled serve as terminal states governed by an immutable TRANSITIONS map.

Similarly, honbu/a2a_contract.py enforces step-by-step progress (ready to leased, reported, and verified), while dispatch/src/authority.js tracks job leases. Following docs/architecture.md, tasks waiting on conditions remain in scheduled and cannot transition to ready without verified observations, while reviving a cancelled task requires the dedicated reopen-cancelled command to enter blocked.

Caveats & Operational Rules

  • Do not oversimplify state granularity: Reducing workflows to binary incomplete and complete flags conceals whether work is waiting for code review or awaiting live deployment.
  • Require objective evidence for transitions: State changes should demand verifiable artifacts such as PR URLs, content hashes, or test logs rather than bare boolean updates.
  • Guard terminal state re-entry: Once a task enters done, it cannot be reopened, and recovering a cancelled task must follow audited procedures via reopen-cancelled.

Related Terms

References

  • Book: Mark Richards & Neal Ford, *Fundamentals of Software Architecture*, Chapter 12 (Workflow Architecture)

Verified: 2026-11-08