Verification for AI-written code

Code generation is solved
Trust is the bottleneck

AI now writes most of the stateful code your systems depend on — workflows, control logic, anything with a "mode." That's exactly the code humans are worst at reviewing by eye: the dangerous bugs live in combinations that are hard to predict and easy to leave untested. Cognitive Fab brings deterministic, exhaustive verification to that code, so your team gates it on every change instead of trusting it on faith.

Why it matters

The bugs that cause outages hide in the states hardest to enumerate.

Review catches what a reviewer thought to imagine. It doesn't reliably catch the interleaving that's hardest to picture in advance — the DNS race condition no test enumerates and no reviewer sees, until it's already in production. That's not a hypothetical: it's the exact class of bug that pushed Amazon and Microsoft to formally verify their most critical infrastructure.

Amazon built specialist, PhD-level teams to write TLA+ models of S3 and DynamoDB to catch design defects in reachable states that testing and code review couldn't reach — the kind of defect that only shows up once you check every reachable state, not the ones a person happens to think of.

Microsoft did the same for Azure Cosmos DB. In both cases, the fix wasn't more review — it was exhaustive, deterministic checking of the state machine underneath the service.

That precedent used to require a specialist team and months of formal-methods training. It doesn't anymore — that's the point of Polygraph.

And it's not just Amazon and Microsoft. MongoDB, Elastic, Datadog, PingCAP, Yandex, and dozens of others reach for the same class of tool once review by eye stops being enough.

Ref: Newcombe et al., "How Amazon Web Services Uses Formal Methods," CACM 2015; Microsoft Azure Cosmos DB TLA+ verification; a crowdsourced list of companies using formal methods.

Jean-Jacques Dubray, Ph.D.

Author of the SAM pattern

A career spent on stateful systems you can trust: a 1987 Ph.D.; the software engineer and material scientist behind the IMSC closed-loop control project at Hughes Research Labs; chief architect of the NEC Boston Technology Center, leading the design of one of the first business-process engines; and a contributor to the B2B and web-services standards that formalized how systems coordinate — ebXML BPSS, WS-TX, and XML DSig.

What's different now: the spec is ordinary code — no specialist team required to write the math.

A harder, largely unsolved problem

Verifying a version is one problem. Evolving a live fleet of them is another.

The moment you change a state machine's definition, every instance already running it — the order half-shipped, the session half-negotiated — is still running the old one. Most verification tooling stops at "is this version correct" and has nothing to say about "is this deploy safe for the instances already in flight." That's the problem polyvers is built to close: classify the change, seed it against real in-flight state from the live fleet, and gate the deploy on the verdict — so a live system can change without breaking the instances already running in it.

Introducing Polygraph

Verify, don't review.

A verification-gated lifecycle for the code AI agents now write. Code generation is solved — trust is the bottleneck. Agents already write large amounts of stateful code, the kind hardest to get right, and no human can enumerate every reachable state by eye. The dangerous bugs hide in combinations that are hard to predict and easy to leave untested.

Review — today

  • A human reads the diff
  • Samples the cases someone imagined
  • Misses combinatorial defects

Trust blindly

Verify — Polygraph

  • A deterministic gate runs on every change
  • Explores every reachable state exhaustively
  • Every bug arrives with its reproduction

Trust by construction

Nine tools, one gate

Plugins to a coding agent. Every step the agent takes, a deterministic gate checks — no model needed at check time.

hover a mark ↗ · click to open
Polygraph · fig 1
Nine tools, one gate
Every tool is a plugin to a coding agent. The gate at the center is deterministic — no model call at check time.
hover a tool ↗
every change
every tool call
code
design-time
polygen
Authors the machine, model-checks its own output, repairs the code.
polynv
Elicits the rules every other gate is measured against.
polyvers
Evolves it safely against the instances still in flight.
author the machine · elicit the rules · evolve it safely
ci / cd
polygate
Runs the gates on every merge request — unverified changes can't merge.
keyless merge gate on every change
runtime
polyrun
Executes verified machines durably; the journal feeds the gates back.
durable, exactly-once execution
polygraph
the deterministic gate
SAM v2
the checkable specification model
exercises the whole toolset
100 production state machines
hashicorp/raft · hatchet-dev/hatchet · n8n-io/n8n …
↻ measure → tune the tools
qualifies SAM v2 across models
SysMoBench
Haiku 5 · Fable · Mistral · OpenAI …
↻ score → tune SAM v2
agents
polysec
Proves every path to the forbidden state passes a default-deny gate — or hands you the witness trace.
before it ships
polyman
Steps the proven machine in front of a live agent's tools, denying the call before it runs.
on a live agent
polyviz
Renders only what the gate already produced. Byte-identical SVG, run to run.
reporting

3 of the world's most critical cloud services — S3, DynamoDB, Azure Cosmos DB — are formally verified with TLA+, because their teams learned the hard way that review by eye doesn't catch race conditions across a system's reachable states. Polygraph brings that same rigor to the state machines AI now writes for everyone else, without the specialist team.

The system

The lifecycle, the deliverables, and who decides what

Where each tool fires across the development lifecycle, the artifact family they all speak, and — layer by layer — what is mechanically gated, what is partially measured, and what remains human judgment.

Polygraph · fig 2
Where each tool fires in the lifecycle
Six phases. Each names the tool that acts, the artifact it leaves behind, and whether a human decides.
click a phase ↗
01
Elicit
polynv
Harvest, pre-check and disposition the rules the machine must obey.
→ invariants.mjs
→ intent-ledger.json
02
Author
polygen
Draft the contract, author the SAM v2 module, self-repair against the checker.
→ contract.json
→ next.cjs · effects.cjs
03
Audit
polygraph
Generate independent specs, replay real traces, model-check exhaustively from init.
→ specs 1..N
→ findings + counterexamples
04
Gate
polygate
Block the merge unless the committed artifacts are fresh and still pass.
→ merge verdict
→ published hashes
05
Run
polyrun
Execute the verified machine durably; keep checking it in production.
→ journal
→ fleet snapshots
06
Evolve
polyvers
Classify the change, seed the live fleet, gate the deploy on the verdict.
→ compat-report
→ migrate.cjs
designer decides
human reviews contract
mechanical
mechanical · keyless
poison on impossible
mechanical · exit 0
Polygraph · fig 3
One artifact family, nine consumers
What one tool produces, the next consumes. Every artifact is inspectable and diffable.
produces
consumes
poly
nv
poly
gen
poly
graph
poly
gate
poly
run
poly
vers
poly
sec
poly
man
poly
viz
contract.json
observable keys, action alphabet, data domains, terminals
next.cjs
the machine — a SAM v2 strict-profile module
invariants.mjs
intent, as plain JS predicates over state
*.ndjson traces
ground truth: {pre, action, data, post} windows
effects.cjs + manifest
pure effect mapper over transitions
fleet snapshots
live in-flight state, exported or synthesized
migrate.cjs
the pure shape migration for a version
compat-report.json
the versioning verdict — deterministic, PR-gateable
intent-ledger.json
every rule ever considered, with attributed dispositions
the universal currency
Every consumer speaks the same window: {pre, action, data, post} — the replayer scores against it, the harness captures it, the polyrun journal is a stream of it.
Polygraph · fig 4
What is checked, and what is judged
Each layer of the stack, the argument that covers it, and the tool that makes the argument.
mechanical gate
partially measured
human judgment
Machine logic
mechanical gate
Exhaustive model check against invariants, per machine, over its declared finite action/data domains.
polygraph · polygen
Data abstraction
human judgment
Someone picks the representative values. No gate measures whether they exercise every boundary the code branches on.
Invariant-set strength
partially measured
Mutation adequacy grade — kill ratio over behaviorally distinct mutants, equivalents discarded by graph comparison. Blind spot: behaviour-removing mutants largely evade safety invariants.
polynv
Machine ∘ mapper composition
mechanical gate
Path exploration including emissions, spawns and timer validity — reproducing the kernel’s poison rules statically.
polyrun check-effects
Parent × child composition
mechanical gate
Exhaustive joint-state check against cross-machine invariants. Open: grandchildren, joint mid-flight seeding.
polyrun check-product · polyvers matrix
Version compatibility
mechanical gate
Lanes and gates over fleet snapshots — exactly as good as the stated invariants and the corpus tier, both disclosed in the report.
polyvers
Merge discipline
mechanical gate
Content-hash staleness plus keyless replay and model check on every merge request. A stale artifact cannot reach a protected branch.
polygate
Kernel, stores, workers
partially measured
Seeded deterministic simulation over the real kernel with model-in-lockstep parity, injected store faults and duplicate delivery. Sampled schedules, not exhaustive.
polyrun simulate
Agent tool mediation
mechanical gate
Fully-mediated reachability proven at design time and the same machine enforced at runtime. Your tool→effect-class labels remain a trust obligation.
polysec · polyman
Effect handlers
human judgment
Must be idempotent under the provided key — the same division of labour as Temporal activities.
yours
Contract & invariants
human judgment
The one thing no tool derives. A converged run against wrong intent proves nothing.
polynv makes it cheaper
scope disclosure
Everything above is a consistency check, not a proof. “Exhaustive” always means exhaustive over the finite (action, data) domains the contract declares — never over unbounded real data.
Work with us

Bring verification to the code your team ships with AI.

Code generation is solved. Trust is the bottleneck. Advisory and training from the author of the SAM pattern — so your team can gate AI-written code deterministically, on every change, instead of reviewing and hoping you catch every defect.

Teams shipping AI-written stateful code Coding-agent & dev-tool builders Safety-critical & regulated teams Frontier AI labs

A 30-minute conversation about where AI-written code is quietly accumulating risk in your systems — and whether verification is the answer.

Where stateful code lives

Anything that occupies a situation and moves between them on events is a state machine — whether or not anyone drew it as one. It is the hardest software to get right, and it is everywhere.

🗂️ Business workflow

orders, billing, subscriptions, approvals NServiceBus, Particular Software

☁️ Cloud infra & databases

replication, consensus, consistency Amazon S3/DynamoDB, Azure Cosmos DB, MongoDB, Datadog, PingCAP, Elastic, Yandex ClickHouse

🔬 Semiconductor & hardware

pre-silicon & chip verification Intel

⚙️ Industrial control

SCADA, PLCs, factory automation

🤖 Robotics

motion planning, task sequencing

🚗 Autonomous vehicles

perception → decision → actuation

✈️ Aerospace & flight

flight control, avionics modese.g. OpenComRTOS — formally-designed RTOS

🩺 Medical devices

a pump that free-flows, a scanner stuck between modes

💳 Payments & finance

settlement, ledgers, trade lifecycle

📡 Telecom & protocols

call state, session & consensus protocols Informal Systems — Quint/TLA+, IBC

⚡ Energy & grid

grid control, battery & plant management

🚚 Logistics & supply

fulfillment, routing, inventory

🔌 Embedded & IoT

…and everything with a “mode”

Rigor from design to operations

Most systems bury their state machine in code, where it can't be inspected, verified, or safely evolved. We make it a first-class artifact across its whole lifecycle.

Design

Model states, actions, and transitions explicitly — with contracts and invariants that capture what the system must and must never do.

Verify

Check machines against their contracts before they ship: reachable-state analysis, invariant checking, and replay of real traces against the model.

Operate

Run fleets of machines with visibility into every instance's state, safe version migrations, and compatibility gates for every change.

Evolve

Change a live system without breaking it — versioned machine definitions, validated migrations, and gates that catch incompatibilities before deployment.

Tell me about your stateful code.

A 30-minute conversation about where AI-written code is quietly accumulating risk in your systems — and whether verification is the answer.