Le secrétaire de Fernand

Step 11: A state machine whose every case is decided before it compiles

Step 11: A state machine whose every case is decided before it compiles

The eleventh step of the harness I put around my coding agents: every rule of a long job in one state machine, with a table of every case the type checker holds.

2 min read

My tool runs long jobs that pause, resume, fail and wait for review. The rules for each were spread across the code, one if at a time. No one could see them all, and a new case could slip between two. So I put every rule in one state machine.

Böckeler's grid

Two dimensions. A guide acts before the agent, a sensor after. Each is inferential, judged by a model, or computational, decided by a program. Inferential guides are what the agent reads, AGENTS.md, a skill, a plan, sharper written in the literature's words; computational guides are deterministic tools, a codemod, a generator, a command that acts in the agent's place, code mode, where the agent writes a program instead of a string of actions, a language server. Inferential sensors are a review by a model or a person; computational sensors are the type checker, the linter, tests and fitness functions. Each practice moves a judgement toward computation, and the computational sensor is the optimum.

Inferentiala model judges, your attention follows
Computationala program decides, without your attention
Guidesbefore the agent acts
  1. 4 · literature in skills
  2. 5 · skills
toward computation
a codemod · a generator · a command (CLI) · code mode · a language server
Sensorsafter the agent acts
a review by a model or a person
toward computation
the optimum
  1. 1 · type checker
  2. 2 · linter
  3. 3 · dead code
  4. 6 · fitness functions
  5. 7 · plan in phases
  6. 8 · files per phase
  7. 9 · model per phase
  8. 10 · snapshot
  9. 11 · state machinetoday

In Birgitta Böckeler's grid of guides and sensors, the table of every case is a computational sensor. The code does not compile until each case is decided. The rule the agent reads is an inferential guide. The series' map: Guides and Sensors: Mapping Your Attention to Free It

How it works

Every signal became an event: a gate result, a rate limit, the agent's answer, a resume. One pure function takes the state and the event and returns what happens: handled, ignored, stale, rejected or unexpected.

Then a table: for each run state and each event, the expected answer. The type checker refuses the table if one cell is missing. A new event or a new state compiles only once someone has decided what happens in every case.

A whole class of errors can no longer happen: the forgotten case, the pause that lands during a resume, the archive of a run still running. The agent can't skip a cell, because the build fails first.

The idea is old: David Harel's statecharts, 1987: Statecharts: A Visual Formalism for Complex Systems And Yaron Minsky's "make illegal states unrepresentable": Effective ML Revisited

If you want an example, here is my table: lbdremy/phax/src/domain/matrix.ts

Next in this series: Step 12: Gaming the gate

A thought after reading?

If you would like to discuss about this article, you can write to me here. I share because I care and I want to learn. Please teach me with care.

Send me an emailremy@lesecretairedefernand.co