2026-11-26 15:37 UTC

Formal verification can check agent-written code—but only against the properties people specify

state: seedheat: mediumuncertainty: mediumrelevance: highcoding-agent-verification formal-verification intent-alignmentLeangineering authorMicrosoft ResearchShuvendu Lahiri

What is this?

A Leangineering practitioner’s article, “Checking agent code against your intent,” explains workflows that formalize a software change’s intent as properties, then have an AI agent prove those properties with a proof assistant such as Lean or Dafny. A small trusted checker validates the proof, and a failed property can send a counterexample back to the coding agent for revision. The author draws on Microsoft Research’s neuro-formal verification (NFV), described in a November 18 post, and discusses related tools including Microsoft’s open-source NFV prototype, Midspiral’s LemmaScript, Harmonic’s Aristotle and GitHub’s Lean Squad. The article is practitioner analysis, not a new tool launch or independent evaluation. It emphasizes a key limitation: a valid proof only establishes the stated property under its assumptions; an incomplete or mistaken property, or an inaccurate model of the code, can leave important behavior unchecked. The supplied search result also points to a Microsoft Research PDD Kit post dated November 5, but provides only a snippet, so its details cannot be independently assessed here.

Why it matters

Formal checks could let coding agents catch some defects and iterate before a human reviews a change, making reliable agent-written software more practical—especially for consequential logic such as money, permissions, and state changes. But the proof checker cannot tell whether the property captures the developer’s real intent. The article’s central contribution is a useful account of both the promise and this specification bottleneck, not evidence that these workflows are already broadly adopted or reliably improve software outcomes at scale.

Current assessment

The article describes an emerging pattern: turn a change’s intent into explicit formal properties, freeze those properties before proof search, let an agent attempt a proof, and have a trusted checker validate it. A verdict may be proved, refuted with a counterexample, or unresolved. In the cited Microsoft Research NFV work, properties are derived from pull-request context; the author reports that NFV checked 217 properties across 38 recent pull requests. The article also cites an NFV benchmark in which 92% of verdicts were correct, compared with 72% for direct model answers, while cautioning that an agent allowed to translate and prove in one go produced wrong verdicts on half of buggy and correct programs. These figures are reported in the practitioner article and are not independently verified by the supplied sources. The practical promise is an automated feedback loop: in a Midspiral bill-splitting example, a failed conservation property exposed a rounding bug and the agent corrected it before human review. That example illustrates a capability, not a general success rate. Safeguards discussed include freezing the goal, checking a plain-language restatement of the property against the stated intent, listing assumptions, limiting proof attempts, and comparing a model with the running implementation. None removes the need for human judgment about whether the property is complete and meaningful. Translation or compiler models can differ from runtime behavior; the article notes, for example, that LemmaScript models TypeScript numbers as exact integers, not floating point. What is new in this evidence is a practitioner synthesis of NFV and adjacent tools, including where proofs can mislead and how they might fit into code review. It does not establish broad adoption, production impact, or comparative performance across tools. Web search surfaced a Microsoft Research result titled “Formally verifying agent-written full-stack web apps with PDD Kit,” dated November 5, 2026, with a snippet saying it turns intent into a formal spec and uses tests where proof cannot reach. Because only the search snippet is supplied, treat that as a lead for follow-up, not confirmed detail. The article’s dated reference to Microsoft Research’s November 18 NFV post and the search result’s November 5 PDD Kit date are separate chronology points; their relationship is not established here. Overall, the approach could shift some review effort from reading every line toward scrutinizing specifications, assumptions, and unresolved cases, but intent formalization remains the main human and technical bottleneck.

Measured heat

now 0 pts/hpeak 4 pts/hcomments 0/hpeers p10momentum: steady2 platformsage 122h
points/hour across evidence · reading as of 2026-11-27 02:23:58.509736+11:00 · deterministic, not a model opinion

How the heat travelled

11-21 13:00⭐ origin echo-reconstructedThe post’s cited primary upstream source for the central NFV code-review method is Shuvendu K. Lahiri’s RiSE MSR article, which says the pro
Paul Butcher on blog (echo) · attributed from hn.story.50600875
—
11-22 16:04first on hacker news · published · +27.1hChecking agent code against your intent
saviorand
—
11-22 16:04amplified on hacker news 👑hn.story.50600875
saviorand
peak 2 · 1 comments · 98% of case engagement
11-22 16:21our radar first saw it · +27.4hdiscovery anchor: hn.story.50600875—
pace: p41 vs 2105 stories at the 96h mark (now 122h old) — ahead of adobe-max-ai-agents-creative-tools-mcp (1.5x), behind 42loop-agent-operated-product-experiment (0.8x)

Evidence (2) — ⭐ canonical anchor

sourceobjectauthorscorecomments
🟧 hnChecking agent code against your intent
Retrieved article excerpt

Open article · Retrieved 2026-11-22T16:22:13.831306+00:00

The loop this post describes. The properties are frozen before the agent starts, and the checker sends refuted code back to the agent before you read anything. The dashed lines mark where a proved property can still miss.

Figure 1. The loop this post describes. The properties are frozen before the agent starts, and the checker sends refuted code back to the agent before you read anything. The dashed lines mark where a proved property can still miss.

## 1Introduction

Coding agents now write more code than I can read. One answer is to stop reading. Robert C. Martin, better known as Uncle Bob, says his current strategy “is to not read any of the code written by my agents”. Instead the code has to “run the gauntlet” of his tests, quality metrics and mutation testing[1](https://leangineer.com/blog/checking-agent-code/blog/checking-agent-code#fn-bob). I disagree. I think you should read all of it. The way to keep that possible is to get agents to write less code, and better code, before it reaches you.

More tests don’t get you there. In Dan Luu’s August runs, asking agents to use Rust’s built-in test framework roughly doubled the number of tests they wrote, “but this didn’t result in better correctness”[2](https://leangineer.com/blog/checking-agent-code/blog/checking-agent-code#fn-luu). A newer model tested better a month later[3](https://leangineer.com/blog/checking-agent-code/blog/checking-agent-code#fn-astra). Still, a test an agent writes encodes the agent’s own idea of what the code should do.

On 18 November Microsoft Research described a code reviewer that works on the “better” part[4](https://leangineer.com/blog/checking-agent-code/blog/checking-agent-code#fn-nfvpost). It starts from the intent of a change, meaning what the change is supposed to do, and writes that intent down as precise properties. An agent tries to prove that the code has each property, and a small, trusted program checks the proof. The researchers call this neuro-formal verification (NFV), and on 38 recent pull requests it checked 217 properties[5](https://leangineer.com/blog/checking-agent-code/blog/checking-agent-code#fn-prs). Harmonic’s Aristotle, Midspiral’s LemmaScript and Don Syme’s Lean Squad work in a similar way.

This post asks three questions about tools like these. What does such a proof tell you? That the code has a property you wrote down, under the assumptions it lists. What can’t it tell you? Whether the property was the right one, whether it was proved about the code that runs, and whether it says what you meant. Can you stop reading the code? No, but less of it reaches you, and what does has already been checked against the intent. Figure 1 shows the loop. Like my [last post](https://leangineer.com/blog/realworld-in-lean/), this one borrows the layout of a math paper.

## 2Verdicts

In 2014 a bug in OpenSSL, later named Heartbleed, let anyone on the internet read a server’s memory, including passwords and secret keys[6](https://leangineer.com/blog/checking-agent-code/blog/checking-agent-code#fn-heartbleed). The intent behind the fix fits in one sentence, which Aristotle uses as its example: “The response is never longer than the request.” Three steps turn a sentence like that into a checked verdict.

Construction 1 (The model). The code is translated into Lean or Dafny, two languages built for writing proofs about programs. Aristotle compiles C, Rust and Verilog into Lean, and LemmaScript compiles TypeScript into Dafny or Lean, both with an ordinary compiler. NFV has an agent do the translation instead. That works for almost any language but adds a step you have to trust.

Construction 2 (The property). The intent is written down as a formal property. Shuvendu Lahiri, who wrote the NFV paper, calls this intent formalization[7](https://leangineer.com/blog/checking-agent-code/blog/checking-agent-code#fn-lahiri). NFV derives properties from a pull request’s description, issues and discussions. In LemmaScript the intent and the property sit in comments above an ordinary TypeScript function, as in this example from its [demo](https://github.com/midspiral/lemmascript-claimcheck/blob/main/examples/demo.ts):

```
//@ contract Clamps x into the inclusive range [lo, hi]; the result never falls outside it.
//@ requires lo <= hi
//@ ensures \result >= lo && \result <= hi
export function clamp(x: number, lo: number, hi: number): number {
  if (x < lo) return lo;
  if (x > hi) return hi;
  return x;
}
```

The `contract` line is the intent in English. The `requires` and `ensures` lines are the property. They say that if `lo <= hi` when the function is called, the return value (`\result`) lies between `lo` and `hi`. TypeScript ignores all three lines, so the code that runs doesn’t change.

Construction 3 (The proof). An agent searches for a proof and a checker decides whether it holds. In Harmonic’s words, “AI writes the proofs and Lean checks every step of them, so a result never rests on the AI being right.” The checker is a small program at the core of Lean or Dafny, and it accepts a step only if the step follows from the ones before it.

Definition 1. *A *proof-backed verdict* on a property is one of three things.*

- *Proved*, with the list of assumptions the proof rests on.
- *Refuted*, with an input on which the property fails.
- *Unresolved*, if neither a proof nor a counterexample was found in time.

Remark 1 (Saying "unresolved"). A checker that can say “unresolved” is right more often when it does answer. On NFV’s benchmark of small Python programs, 92% of its verdicts were right. A model asked directly answered every program, but only 72% of its answers were right, and none came with anything that could be checked[8](https://leangineer.com/blog/checking-agent-code/blog/checking-agent-code#fn-nfv).

## 3Limits

A proof covers what its property says and nothing else. Harmonic’s [documentation](https://aristotle.harmonic.fun/docs/overview) puts it plainly, warning that “a behavior that isn’t listed as a property hasn’t been verified.” So a proof is only worth as much as its property.

Definition 2. *A proved property *matches your intent* if it is a property that matters, it was proved about the code that runs, and it says what you meant.*

The checker covers none of these three parts, and each of them fails in practice.

*A property that matters.* In Luu’s August runs, agents implementing the Zstd compression format in Rust were told to use Lean or another proof tool. They “mostly did arithmetic proofs that didn’t hit the bug-prone or risk surface areas”[2](https://leangineer.com/blog/checking-agent-code/blog/checking-agent-code#fn-luu). Don Syme says much the same of Lean Squad, which proved more than 1,200 theorems about three open-source codebases: “Most theorems are glorified testing”[9](https://leangineer.com/blog/checking-agent-code/blog/checking-agent-code#fn-squad).

*The code that runs.* An agent translating a program can model a slightly different program. The NFV blog post admits that “the proof alone cannot establish that the formalization faithfully captures the source program and supplied property.” A compiler is more predictable, but it still simplifies. LemmaScript treats TypeScript numbers as exact integers, so its proofs say nothing about floating-point rounding. Midspiral’s crosscheck looks for gaps like that. It runs the proved model and the real JavaScript on the same inputs and compares the results, which is called differential testing[10](https://leangineer.com/blog/checking-agent-code/blog/checking-agent-code#fn-ls).

*What you meant.* Midspiral’s claimcheck caught this in an election tally that an agent had built and proved. The intent was that the order of the ballots doesn’t affect the tally. The proved property only showed that adding a ballot at the front of the list gives the same count as adding it at the end. Dafny accepted it, and it looks right at a glance. But it covers only one way of reordering the ballots[11](https://leangineer.com/blog/checking-agent-code/blog/checking-agent-code#fn-claimcheck).

Remark 2 (Agents move the goal). An agent rewarded for finding a proof can also make the problem easier. The NFV blog post lists the ways: “by overconstraining the environment, simplifying the code, or weakening the property”. The authors also let a single agent translate and prove in one go. It proved the property for 98% of the buggy programs as well as 98% of the correct ones, so half of its verdicts were wrong.

## 4Safeguards

The tools guard against these failures with checks that don’t depend on the agent following instructions. That matters, because instructions turn out to be fragile. Luu’s own testing skill, a file of instructions an agent loads for a task, helped GPT-5.6 Sol and hurt the newer GPT-6 Astra[3](https://leangineer.com/blog/checking-agent-code/blog/checking-agent-code#fn-astra). There are four safeguards.

*Freeze the goal.* NFV locks the translated program and the property before the proof search starts, so the agent can add proof steps but can’t change what is being proved. LemmaScript’s seal does the same across commits. Its check fails if a proved property is changed or removed, or in its README’s words, “The prover proves the present; the seal protects the past.”

*Read the property back.* Midspiral’s claimcheck has one model restate the formal property in plain English without seeing the intent, and a second model compare the two. LemmaScript runs it on every `contract` line. The demo file from earlier has a function whose contract claims more than its property:

```
//@ contract Returns the larger of a and b.
//@ ensures \result >= a
export function largest(a: number, b: number): number {
  return a >= b ? a : b;
}
```

The code is correct and the property is proved, but the property never mentions `b`. Its restatement, “returns a number that is greater than or equal to a”, isn’t “the larger of a and b”, so the [report](https://github.com/midspiral/lemmascript-claimcheck/blob/main/examples/demo.guarantees.md) marks the function as disputed[11](https://leangineer.com/blog/checking-agent-code/blog/checking-agent-code#fn-claimcheck).

*List the assumptions.* Aristotle and NFV list the assumptions behind every verdict. Harmonic’s write-up on the LibTomMath library, where Aristotle fixed three bugs and proved the repaired code, has a section called “Outside the proof” for what wasn’t covered[12](https://leangineer.com/blog/checking-agent-code/blog/checking-agent-code#fn-tom).

*Stop early.* In NFV’s experiments, proofs that took many attempts were more likely to be wrong. The authors put that down to each attempt being another chance to weaken the goal. So NFV caps the search at five rounds and reports anything still open as unresolved[13](https://leangineer.com/blog/checking-agent-code/blog/checking-agent-code#fn-rounds).

## 5Review

All of this changes what reaches you, and how you read it.

*Feedback from the checker.* The checker sends wrong code back to the agent before it reaches you. Midspiral shows this with a bill-splitting app. Here is its `allocate` function after the agent’s fix, with most of the `requires` lines left out:

```
//@ contract Splits total across weights so every unit is accounted for.
//@ requires total >= 0
// ...
//@ ensures sum(\result) === total
function allocate(total: number, weights: number[]): number[] {
  const W = sum(weights);
  const result = weights.map(w => Math.floor(total * w / W));
  const left = total - sum(result);  // the leftover, lost to flooring
  for (let k = 0; k < left; k++)
    result[k] = result[k] + 1;  // hand them back out
  return result;
}
```

The agent’s first version ended at the `Math.floor` line, which rounds each share down, so 100 cents split three ways came to 99. The `ensures` line failed. The agent read the error and added the loop that hands out the leftover, and the property stayed as it was. Midspiral notes that “this correction happened without a human 
saviorand21
🟧 echo.blog ⭐The post’s cited primary upstream source for the central NFV code-review method is Shuvendu K. Lahiri’s RiSE MSR article, which says the proPaul Butcher——

Interpretation history

Decision trace