/will-wright-eng-skills:state-machine-auditfrom will-wright-eng-skills
Find the explicit and implicit state machines in a codebase, classify each as explicit or implicit with evidence, document states/invariants/transition tables, prove which invalid states are reachable (including via retries and concurrency), then fix confirmed bugs with regression tests. Use when asked to audit state handling, find state bugs, map state machines, or "find the implicit state machines in my app".
Ships in will-wright-eng-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
State machines are not the problem. The problem is the gap between the machine the code actually implements and the one its authors think it implements. This skill closes that gap by making every machine explicit on paper, then checking the code against the paper.
The deliverable is one living document (docs/state-machines.md unless the repo has a
better home) plus fixes with regression tests. The document is scaffolding; the confirmed,
evidenced bugs are the product.
states × events table. Blank cells are
findings, not omissions.Search for anything whose behavior depends on "what mode is this thing in". Starting signals:
status, state, phase, stage, mode, step fields; enums or string unions of
lifecycle words (pending, active, closed, draft, failed, retrying).isPaid, isShipped, isCancelled), nullable
timestamps that act as flags (paidAt, deletedAt), or Optional fields whose presence
implies a phase.switch/match/if chains on the same field across multiple files.onConnect, onClose, componentDidMount, beforeSave).CHECK status IN (...)).For each candidate, decide whether it is a real machine (distinct states with meaningful transitions and invariants) or just a flag. A single boolean with no ordering is usually not worth modeling; two or more correlated fields almost always are.
Give every machine exactly one verdict. Record the signals you observed.
| Verdict | Definition | Typical signals |
|---|---|---|
| Explicit | States are a closed, named set and transitions are defined in one place. | Enum/discriminated union for state; a single reducer, transition function/table, or library (XState, Stateless, Boost.SML, Spring StateMachine, Temporal/saga definitions); invalid transitions rejected centrally. |
| Partially explicit | States are named but transitions are not centralized, or vice versa. | A Status enum exists but any call site can write entity.status = X; or a transition function exists but state is still reconstructed from several fields. |
| Implicit | The machine is emergent. Neither states nor transitions are declared anywhere. | State derived from combinations of booleans/nullables/timestamps; lifecycle words compared as raw strings; transitions spread across handlers with no shared guard; the "diagram" exists only in people's heads. |
Also record where the machine lives: in-memory object, DB row, client store, message in a queue, or split across several of these (split storage is itself a common source of invalid states, because the parts can disagree).
Rough prior for effort allocation: implicit machines produce the most reachable-invalid-state bugs; partially explicit produce the most bypass bugs (someone writes the field directly); explicit ones mostly produce drift bugs (code outside the machine assumes transitions the machine no longer has, or vice versa). Check all three; weight time accordingly.
In the document, one section per machine, in this shape:
## <Machine name> (verdict: Implicit | Partially explicit | Explicit)
**Lives in:** <files / tables / stores>
**Classification evidence:** <bullet list of signals from the rubric>
**Concurrency context:** <who can transition it, from where, can two actors overlap>
### States
| State | How the code represents it | Notes |
|---|---|---|
| Pending | `paidAt == null && shippedAt == null && !cancelled` | initial |
| ...
For implicit machines, every state must be defined as a predicate over the real fields.
List the field combinations that map to *no* named state — these are candidate invalid states.
### Invariants
- I1: An order is debited at most once.
- I2: `shippedAt != null` implies `paidAt != null`.
- ...
Write invariants as checkable statements. Prefer ones that a test or assertion could verify.
### Transition table
| From \ Event | pay | ship | cancel | pay (retry/dup) | ship ∥ cancel (race) |
|---|---|---|---|---|---|
| Pending | Paid | ✗ (no handler: ___) | Cancelled | ... | ... |
| Paid | ? | Shipped | Cancelled?? | ... | ... |
| ...
Cell legend:
- `NextState` — handled, lands in a valid state
- `✗` — rejected or unreachable, note *how* (guard at file:line, DB constraint, etc.)
- `?` — no handler found; behavior unknown (crash / silent no-op / corruption) — investigate
- `!!` — reaches an invalid state; link to a finding
Always include the retry/duplicate and race columns relevant to the concurrency context from Phase 0. Common event variants worth columns:
For every ? and !! cell and every unnamed field combination, determine whether the code
can actually get there. Work from the table, not from intuition.
For each candidate:
file:line → file:line.Anything you cannot confirm goes in an Unverified list with what would be needed to confirm it. Do not pad the bug list.
Group findings into issues by root cause, not by symptom. Ten cells that are all reachable
because status is written directly from six call sites are one issue ("no central transition
guard"), not ten.
Rank by impact, roughly:
For each issue record: severity, affected machine(s), the table cells it covers, root cause, proposed fix, and whether the fix changes the machine's shape (new state, removed transition, new guard).
For each issue, in priority order:
test_order_debited_at_most_once).!!/? to its new value, add the guard citation,
bump the verdict if the machine became more explicit, and move the finding to a
Resolved section with the test name.Do not stop at the first fix. Work the list until the remaining issues are ones the user should decide on (behavior changes, product questions, large refactors), then stop and present those.
The final document should read top-down like this:
# State machines in <subsystem>
_Last verified against commit <sha> on <date>._
## Summary
| Machine | Verdict | States | Invalid states reachable | Open issues | Resolved |
|---|---|---|---|---|---|
| Order lifecycle | Implicit | 6 (+3 unnamed) | 4 confirmed | 2 | 3 |
| WebSocket conn | Explicit | 4 | 0 | 0 | 1 (drift) |
## Issues (open), by priority
### ISSUE-1 [P1] Double debit on payment webhook redelivery
- Machines: Order lifecycle
- Cells: Paid × pay(dup)
- Evidence: reproduced — `tests/orders/test_payment_idempotency.py::test_order_debited_at_most_once`
path: `webhooks/stripe.py:88 → services/orders.py:140 → billing/ledger.py:52`
- Root cause: no idempotency key; guard at orders.py:131 is read-then-write outside txn
- Proposed fix: ...
- Status: open — needs product decision on ...
## Resolved
...
## Unverified
...
## Machines
(one Phase 2 section per machine)
? is an honest cell until traced.What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
Generated from the plugin's indexed repository (will-wright-eng/skills) — no native marketplace selected
npx claudepluginhub p/will-wright-eng-will-wright-eng-skills21 skills in this plugin
/agent-specificationWrite or review the specification of an agent, or of a system of several agents, through a question/answer session. Chooses the arrangement first (one agent, pipeline, orchestrator or blackboard), then settles one SPECIFICATION.md per agent and, when there is more than one agent, a SYSTEM.md that states how they are joined. Works in a fresh repo or against one role of a system that already exists. Takes an optional path to a specification or system document to review. Use when defining, scoping or reviewing an agent or a multi-agent system, choosing between agent patterns, writing an agent's SPECIFICATION.md, or giving each role of an existing agent system a written scope./annealDecompose a god module into stable and volatile pieces whose boundaries match how the code actually changes. Locates hotspots with the hc CLI (decay-weighted churn × complexity quadrants), autopsies the chosen file along three evidence axes (symbol co-change, consumer slices, internal references), interviews through each proposed seam one at a time, and delivers a strangler-fig migration plan with a measurable hc baseline. Use when a file is a "god module" or "god file", one file soaks up every change, a module needs splitting, or the user wants to isolate hot code or reduce churn concentration./assess-test-suiteAssess a project's test suite against the verification practice in "How the Claude Code team thinks about verification" — classifies every test on two axes (scope unit/integration/E2E × oracle interaction/example/snapshot/property/differential) plus health tags (flaky, slow, cannot-fail, not agent-runnable), maps user-facing features to E2E coverage, then proposes a ranked refactor toward E2E, property and differential tests, closing with a short note on what the refactor does to CI/CD runtime. Writes the assessment only on confirmation and never edits tests. Use when the user wants to "assess the test suite", "audit our tests", know "are our tests any good" or "which tests are worth writing", plan a test strategy or test refactor, deal with too many mocks or unit tests or with flaky tests, or make a test suite a reliable feedback loop for coding agents./autoresearch-methodExplain the autoresearch methodology — a verifiable autonomous experiment loop — and evaluate whether the current repo is a good fit before running the autoresearch-verify and autoresearch-program skills. Use when a user wants to add autonomous experimentation to a project, asks about autoresearch/autoresearch, or is about to invoke the other autoresearch skills./autoresearch-programGenerate `program.md` at the repo root from the autoresearch program template, with mutable/immutable scope and verifier commands baked in via light templating. Run after autoresearch-verify produces the verifier script. The generated program.md is the operating directive for a fresh agent session running the autoresearch loop — after this skill runs, the autoresearch skills are no longer in the picture. Use when a user wants to generate the loop directive for an autoresearch run./autoresearch-verifyBuild a repo-specific verifier script for an autoresearch loop. The script has two modes — `light` (fast per-candidate metric evaluation, emits the JSON the loop consumes) and `heavy` (matrix-of-conditions integrity check). Run after autoresearch-method confirms the repo fits and before autoresearch-program. Use when a user wants to build the verifier script for an autoresearch loop.