Every Layer Removes a Reading
Since January 2026 I have added formal layers one at a time to how I run a company and my own records, each where one sentence was turning into two meanings. Here is the order, the date each layer entered the repository, and the one I have not built: checking the specification against what the system actually did.
On 05/11/2026 Datadog's engineering blog published How we continuously validate formal specifications in production. They wrote TLA+ specifications for parts of their event database, then built a tool, FETCh, that turns each specification into a runtime monitor: every action in the specification becomes a function, every production event is matched to an action, and a failed precondition means the system did something the specification forbids. The sentence that matters is this one: "Reviews provide a point-in-time evaluation, while production systems continue to evolve." And the consequence: "Because the specification itself still appears correct, that drift can create a false sense of confidence."
That post is the prompt for this one. A formal specification is a claim about a system. Checking the specification proves something about the specification. Nothing in that loop looks at the system. The Datadog team closed the loop by reading what production actually did. I have spent this year closing smaller loops of the same shape, one at a time, and I think the order in which I closed them is more useful to anyone starting out than any single layer.
None of this is new in kind. Amazon described using TLA+ on production designs in Communications of the ACM in 2015. The seL4 proof (Klein and colleagues, 2009) is the canonical demonstration that a proof is about a model, and that connecting the model to the code is much of the work. Design by contract put checkable preconditions into ordinary programs decades ago, Daniel Jackson's lightweight formal methods argued for partial specifications checked cheaply, and runtime verification has been a field in its own right for over twenty years (Leucker and Schallhart's 2009 survey is a good entry point). The Datadog post itself points to PObserve, which checks P specifications against real traces. What I add is not a technique. It is an order, and a rule for when the next layer is due.
The thesis is simple. Natural language admits several readings. Readings diverge as they pass between people, agents and months, and the cost of the divergence compounds at every reading, while the cost of removing it is paid once. I claim the direction, not a multiplier: I have no measured rate. So a formal layer earns its place only where it removes a class of ambiguity at the point where that ambiguity would otherwise compound, and only if a machine checks it on every change. Everything below is an application of that rule. If it is wrong, the evidence would be a layer I added that removed no ambiguity anyone was paying for, or an ambiguity that kept compounding with every layer in place. I name the open one at the end.
The rule for adding a layer
Three tests decide whether a layer goes in.
First, it must remove a specific reading, not "improve quality". If I cannot say which sentence used to mean two things and now means one, the layer is decoration.
Second, a machine must check it on every change. A rule that lives only in a document is a sentence, and sentences are what the layers exist to replace.
Third, the layer must not be able to pass while checking nothing. A formal layer that can be vacuous is worse than no layer, because it manufactures confidence. This third test arrived late, and much of the work since June has been going back to apply it to layers that already existed.
The sequence
Every date below is the first appearance of the layer in the git history of my working repository. Where a layer existed in a weaker form before it became binding, both dates are given.
| First in git | Layer | The reading it removes | What checks it |
|---|---|---|---|
| 22/01/2026 | Requirements as prd.json records; schema from 23/01/2026 |
"The system should do X and Y": one sentence, several requirements, no owner | Schema validation |
| 01/02/2026 | Machine-generated Lean 4 proofs of capability bounds | "The agent cannot do Z", asserted rather than shown | The Lean kernel |
| 13/02/2026 | First Lean 4 projects in the repository | Arithmetic and decision rules held in prose | lake build |
| 16/05/2026 | modlean: a compositional model with decidable invariants and provenance constructors | Facts with no source; status that is an opinion | The type checker and decide |
| 19/05/2026 | lean-prd: a prd.json restated as a Lean specification |
Acceptance criteria that read as met because nobody can say what "met" means | The kernel, per requirement |
| 25/05/2026 | Requirement-id parity between prd.json and its Lean spec, in the validator hook |
Two files that both claim to be the requirement set | Validator on every write |
| 31/05/2026 | The four-layer discipline as the house standard | Derived state written by hand | Judgement, later partly gated |
| 05/06/2026 | The lifetime-value discipline as a test on assets | "This is helpful right now" | A pricing judgement before commit, not machine-checked |
| 10/06/2026 | Enforcement gates, starting with deployed reality and anti-theatre | "It is live", "it is verified" | Hooks, git hooks and nightly reconciliation |
| 23/06/2026 | Proof-claim mapping | A prose claim that a theorem exists | Gate: a claim marked as proved in a proposal names a sorry-free theorem |
| 24/06/2026 | Derived-artefact drift | A generated file edited by hand, or not regenerated | Gate: regenerate and compare |
| 21/07/2026 | PRD-to-Lean coherence as a blocking gate | A proof about a copy of the requirements | Gate: re-derive the id set from the JSON |
| 18/10/2026 | Axiom audit from the kernel's own report | "Proved", where the proof rests on an unstated assumption | #print axioms, weekly, report-only |
| Not built | Runtime monitors compiled from Lean specifications | "The system does what the spec says" | What ran |
Two rows fail my own second test. The four-layer rule and the pricing test are judged, not checked, which makes them the layers I trust least, and the gates that followed are partly an attempt to mechanise them.
As of today the gates directory holds 162 Python files, a few of them shared helpers rather than gates. The count is not the point. The point is that each was added for a class of mistake, and the table above is the spine they hang from.
Requirements as records (January)
The first layer needs no Lean. A requirement written in prose fails slowly: the sentence that is three requirements joined by "and", the dependency on something already cut, the owner who disappears. Writing each requirement as a record against a schema, with an id, an owner, acceptance criteria and dependencies, removes those readings at the door. A malformed record is rejected when it is written, not discovered when it is built. I have argued this at length before. In this sequence it matters because it gives every later layer something with identity to point at. You cannot check a proof against "the requirements" unless the requirements have ids.
Proofs, then a toolchain (February)
On 01/02/2026 I published machine-generated Lean 4 proofs of small capability bounds, produced by a proof-generating model and checked by Lean's kernel. The reading this removes is the one every AI safety argument trades on: "the agent cannot do Z". Asserted, it is a promise. Proved, it is a statement about a model of the agent, which is narrower and true.
Twelve days later the first Lean projects entered the repository as working tools, not essays. The reading removed there is more mundane: arithmetic and decision rules that lived in paragraphs, where every reader recomputes them slightly differently. A Lean function has one answer per input, and the type checker confirms it is the function I wrote rather than the one each reader reconstructs.
This is where the cost becomes visible. Lean is slow to write and unfamiliar to read. It was worth it here because the rules were the kind I would otherwise re-derive every few weeks, and re-derivation is exactly where readings multiply.
The PRD as a specification (May)
lean-prd restates a prd.json as a Lean file: requirements become propositions, acceptance criteria become proof obligations, the dependency graph becomes a structure the kernel can check for cycles. Its content first appears in git on 19/05/2026. The reading it removes is "this requirement is done". In prose, done is whatever the person reporting it means. As a proof obligation, done is a term the kernel accepts.
This layer also produced the first lesson about vacuity. A proposition can be defined as True, and then every obligation is discharged by construction. The build is green and nothing has been checked. That is the strongest argument I know against treating "it compiles" as evidence, and it is the reason the anti-theatre gate exists.
A model with provenance (May)
modlean, from 16/05/2026, is a compositional Lean model of the domains I keep records about. Modules for each domain sit next to the documents they describe. Two design choices carry the weight.
Invariants are decidable. "This application is ready to submit" is a Bool-valued predicate you evaluate, not a status someone typed. Status stops being an opinion.
Every fact carries a Source constructor: a file in the repository, a document, a CRM record, a self-report, an inference, or an explicit placeholder. The type system refuses a fact without one. The reading removed is the most expensive in any record-keeping system: "we know this", where nobody can say how. An inference is still allowed. It is simply labelled as an inference, forever, by the type.
Four layers as the standard (end of May)
By 31/05/2026 the pattern was clear enough to state as a rule for every derived fact:
| Layer | Format | Where drift is caught |
|---|---|---|
| Model | .lean, kernel-checked |
At build |
| Values | .json, schema-validated |
At validation |
| State | Lean evaluation (rfl, decide) |
Nowhere: it is derived |
| View | Generated reports | Nowhere, if the generator is correct |
The rule that follows is blunt: if a file belongs to none of the four layers, it should not exist. A markdown summary of derived state is the canonical example. It is correct for exactly as long as nothing underneath it changes, and nothing tells you when that stops. Narrative prose remains the right medium for why. It is the wrong medium for what.
The interesting row is the third. State is not stored. It is computed from model and values on demand, so there is no copy to go stale. A stored result is a copy, and a copy can go stale. A computed one cannot.
Pricing the asset (June)
On 05/06/2026 the lifetime-value discipline became a test applied to new assets. Every script, document or service is judged by an integral over its lifetime: the utility it provides, minus the upkeep it imposes, with upkeep priced by a shadow price derived from a hard cap on how much of my time maintenance may take. The calibration file, from 08/06/2026, sets that cap at 0.4 per cent, which prices each unit of upkeep at 250 units of utility. The operational form is a walk-away test: if I left this alone for two months, would it still work with nobody touching it?
This looks like economics, not formal methods, but it removes a reading too. "This is helpful" has two meanings: helpful today, and worth having for its whole life. The first is what a capable agent optimises when nothing stops it. The gate forces the second, and it is the reason most of the layers above came with automation attached rather than as instructions.
Gates (June onwards)
The enforcement gates started on 10/06/2026. The first was deployed reality: a schema-validated manifest of what is supposed to be live, a check that refuses a deploy that does not pin its branch, and a nightly reconciliation of what is actually serving against the manifest. The reading removed is "it is live", which an agent will say on the evidence of a successful command.
The anti-theatre gate landed the same day. It lints Lean files for sorry, for propositions defined as True, and for imports nothing can resolve, and it ratchets the counts so they may fall and never rise. This is the third test from the start of this essay turned into a check: it verifies the verifiers.
Gates are tiered. A decidable predicate with near-zero false positives blocks. A heuristic warns and writes a ledger entry, and graduates to blocking only when its precision is shown. Every firing says what fired, why the check exists, what it saw, what to do instead, and how to override, and the override is itself logged. A gate that blocks without explaining itself teaches nothing, and a gate that cannot be overridden will be routed around. Demotion is as explicit as promotion: a noisy blocking gate drops back to warning, by a commit, never silently. And the test that admits a layer is the one that removes it: when I can no longer name the reading it removes, it goes. That rule, too, is judged, not checked.
Two later gates matter for the argument. From 23/06/2026, a claim in a proposal marked as proved must name a declared theorem in a specification with no sorry, no axiom and no True stubs, and in continuous integration that specification must build. From 24/06/2026, a generated file is checked by regenerating it from its source and comparing, on the principle that a derived file's generator is its specification.
The proof is about the copy (July)
The PRD-to-Lean link had been checked since 25/05/2026 at the level of requirement ids, inside the validator, for specifications but by design not for the model files that asserted counts about a PRD. On 21/07/2026 it became a blocking gate, because of a mechanism that is easy to miss and that carries the rest of this essay.
When a Lean file asserts something about a prd.json, such as how many requirements are in scope, the kernel proves it about the literal written into the Lean file. It knows nothing about the JSON. If the JSON gains a requirement, the proof stays green and the claim becomes false. The verified artefact keeps describing a world that no longer exists, with full formal confidence.
That is Datadog's drift exactly, one level up. Their specification drifted from the running system. Mine could drift from the requirements it claimed to formalise. The gate re-derives the id set from the JSON and compares it to the literal. It is not clever. It is a set comparison. It is also the difference between a proof and a proof about a copy.
The axiom audit, from 18/10/2026, reads Lean's own #print axioms report for each theorem rather than searching the source text, because the report lists what a proof actually depends on and a text search only sees what was typed. It runs weekly and reports rather than blocks. It also shows the gap I have not closed. A proof by native_decide trusts the compiled evaluator, not just the kernel, so the trusted base of those proofs is the kernel plus the compiler. Add the scripts that extract requirement ids from JSON, and the honest statement of what my proofs rest on is longer than "the kernel".
What the layers do not do
Every layer above checks a relationship between two artefacts I wrote. None checks the world.
A wrong model passes. If I formalise the wrong rule, the kernel confirms the wrong rule. A wrong requirement passes: the schema checks shape, not wisdom. An unmodelled environment passes: the proof covers what the model includes and nothing it leaves out. These are not defects in the tools. They are what verification means: it shows that one artefact agrees with another.
The layers also cost. Specifications have to be maintained when requirements change, and an unmaintained proof is a false statement with a certificate. Gates produce false positives, and an override count cannot see a check that was bypassed rather than overridden, so precision is always partly estimated. I can count what the gates blocked. I cannot count what they prevented, and I make no claim about that. I accept those costs because the alternative is paying the divergence cost at every reading, indefinitely. But they are real, and an essay that hid them would be an advertisement.
The objections
This is ceremony. The strongest form: every layer is friction between intent and effect, and a small team should just build. My answer is that almost none of these layers asks a person to do anything. The schema, the build, the gates and the reconciliation run without me. The ceremony critique is right about checklists that humans must remember. It is wrong about checks a machine runs on every change, which remove ceremony by making the meeting where people reconcile documents unnecessary.
Lightweight methods give most of the value. I agree, and the sequence shows it. The first layer is a JSON schema. The cheapest layers came first and paid first. Full proof appears only where a rule would otherwise be re-derived by hand, and it sits on a spectrum with schemas, types and property tests rather than above them. Where I disagree is the implied conclusion that proof is never worth it. The coherence gate exists because proofs were worth enough to be worth keeping true.
You will optimise for green gates instead of correct systems. Yes, that is the risk with any measurable target, and a capable agent finds it fastest. The anti-theatre gate, the proof-claim map and the axiom audit exist precisely because a green build is the easiest thing to fake by accident. The residual risk is the one in the previous section: every layer checks artefacts against artefacts. Which is why the next layer is not another check of the same kind.
Why Lean rather than TLA+? Datadog chose TLA+ because it fits distributed protocols and model checking. I chose Lean because my specifications are mostly rules and requirements, and because a decidable proposition in Lean is already an executable check. Different tools for different shapes of specification. The point of their post does not depend on the tool.
Built, and not built
Built and running: requirement records with a schema; Lean specifications of PRDs; a compositional model with decidable invariants and provenance constructors; the four-layer rule and the lifetime-value test, both judged rather than checked; the enforcement gates, including deployed reality, anti-theatre, proof-claim mapping, derived-artefact drift and PRD-to-Lean coherence; and the axiom audit, which reports and does not yet block.
Not built: anything that checks a Lean specification against what a system actually did.
The next layer: checking what ran
This is the layer the Datadog post describes, and it is the one I am building next. It is a plan, not a result.
The deployed-reality gate already compares what is serving against what a manifest says should be serving. That checks configuration. It does not check behaviour. The step that remains is to take the transition rules a Lean specification already states, compile them to a monitor, and run that monitor over the event logs of the systems they describe. If the logs show a transition the specification forbids, the specification and the system have diverged, and one of them is wrong. Control engineers will recognise this as fault detection by residuals: compare what the plant did with what the model allows, and alarm on the difference.
Lean gives a head start that TLA+ does not, because the invariants are already decidable: a Decidable proposition has an executable decision procedure, so the checker exists the moment the specification compiles. What it does not give is the hard part Datadog names honestly: instrumenting systems so that their events map onto specification actions, and keeping that mapping true. That mapping is itself a link between two artefacts, and it will need its own coherence check, or the monitor will be checking a copy of the system the way the proof once checked a copy of the requirements.
I will count this layer done when three things hold: at least one Lean specification is compiled into a monitor rather than hand-translated; the monitor runs on real events without anyone starting it; and a deliberately injected violation is caught, so the monitor is shown to be able to fail. Until then, everything in the table above proves that my artefacts agree with each other. That is a great deal. It is not the same as proving they agree with the world.
Each layer in this essay removed a reading. The last reading left is "the system does what the specification says". It is the only one that has to be checked against something I did not write.
About the author: Eduardo Aguilar Pelaez is CTO and co-founder at Legal Engine Ltd. He writes on formal methods, AI agents, and the discipline of building systems that survive being walked away from.