INTERLOCKSAFETYRUSTHAZARD-CLASSES

Hazard classes 0 to 4 and the Interlock state machine

Interlock sorts every action into five hazard classes and runs as one pure Rust function. What merged, how it is tested and what is still missing.

The plain version

A table saw has a guard, a key and a button. You cannot make the blade spin by asking it nicely. Interlock is that idea for an AI agent working near real power. We wrote down, as code, what each kind of action needs before the power may come on, and we tested the code in simulation.

The five hazard classes: 0 look, 1 safe, 2 armed, 3 keyed, 4 never. Reading and measuring needs no permission. Low-energy actions need a person to hold an arm switch on. Higher-energy or hard-to-undo actions need a key and a fresh button press for that one action. Class 4 has no power rail behind it at all, so the answer is always no.

What merged

Three pull requests built it in layers.

  • #150 added the interlock as a pure crate: one function, step, that takes the previous state, the inputs sampled this tick and at most one event, and returns the next state and the outputs to drive. It reads no clock, allocates nothing and is no_std, so the same code can run in a laptop test and later in firmware.
  • #192 bound leases to a port and an action, added output feedback and the firmware-update jumper.
  • #213 made faults survive restarts, restricted fault clearing to the panel and turned the heartbeat into a challenge.

The rules, in detail

Rail A and rail B. Rail A (class 2) is on only while armed: no fault, the arm switch on, and a valid arm sequence behind it. Rail B (class 3) also needs the key switch on and a live lease. A lease names one port and the digest of one action, and is granted only by a fresh panel press while a request is pending. It ends on use, on timeout, or when the key or arm switch goes off. A use that names another target is refused and ends the lease.

Off after restart, and a restart forgets nothing. Every output is off at power-on. A restart reads a fault record that the firmware keeps in non-volatile memory. A missing or unreadable record, or one saying a rail may have been on, comes up with a fault latched. Only a record of "clear" lets the interlock come up unfaulted, and then it still waits for the arm switch to be seen off, then on.

Heartbeat as a challenge. The interlock issues a fresh challenge every period and the supervisor must compute the reply once, in a window. Wrong, stale, early, repeated or missing replies are all a lost heartbeat, which turns every output off and latches a fault. Nothing arms until a correct reply has been seen. The pattern comes from the question-and-answer watchdogs used in automotive and industrial controllers.

Output feedback. Each rail's sensed state is compared with what the previous tick commanded. A rail that is live while commanded off is stuck on: everything drops and a mismatch fault latches on that tick.

Faults clear only at the panel. A clear request from the supervisor is refused in every state. A clear needs a panel token, the panel button sensed pressed, the emergency stop released, the heartbeat answered, no rail live and the arm switch off.

Firmware jumper. With the jumper fitted and nothing armed the interlock enters a firmware-update mode in which every rail is off and nothing can arm. Fitting it while armed latches a fault.

How it is tested

tests/invariants.rs checks the invariants exhaustively one step at a time over representative states, and over long random sequences against an independent model. A separate test pins the whole transition table to a rules version, which the trust root reports to the supervisor so it will not plan against rules it was not built for. Mutation testing later found tests that missed small changes; see the mutation note.

What is not built

No hardware. The pin wiring, brown-out behaviour, the relay's charge pump and the persisted fault record on real memory are all unproven. One residual gap is documented in the code: a fault that latches while nothing is armed, followed by a power loss inside the record's write time, comes back as unfaulted. Nothing was on, and the arm switch must still go off and on.

← All lab notes