---
title: Verifying Urithiru
url: https://mcwelling.dev/urithiru.html
author: McWelling Todman
date: 2026-12-05
repo: https://github.com/mcwelling/urithiru
---

# Verifying Urithiru

[Urithiru](https://github.com/mcwelling/urithiru) gives coding agents one container per project. It began as the container layer of [Syl](https://github.com/mcwelling/Sylphrena), my agent harness. I pulled it out so other harnesses could share it.

Sharing is the hard part. Several agents can use one container. If one of them decides wrong, it deletes another's work. So I held it to a formal bar. Here is how that went.

## What it does

Urithiru starts, resumes and removes a Podman or Docker container for each project. It runs commands in it with timeouts, memory and CPU limits, and out-of-memory detection. Cancelling a command stops everything the command started.

It knows nothing about agents, models or terminals, so any harness can use it. Syl uses it in production. It also has a command line and an MCP server. An agent that finds a tool missing can install it mid-session and get back a diff to the project's config for its user to review.

The name comes from Sanderson's *Stormlight Archive*: a tower that houses every order of Radiants.

## The method

I followed Marc Brooker's [correctness approach for modern systems software](https://brooker.co.za/blog/2026/11/30/correctness.html). The person owns what must be true: the properties, and the assumptions each one needs. Agents write the code and a stack of checks against that spec. Then each check is broken on purpose, to show it can fail.

I owned the spec. I signed off on every revision, chose to model the fix before writing it, decided what came next and approved every merge. Claude Code agents wrote the drafts, code, models, proofs, simulations and docs.

## Formal verification, briefly

Tests check the cases you think of. Formal verification checks a claim against every case, or proves no case can break it. It needs a precise statement of what must be true and a tool that checks the reasoning mechanically.

The tools here:

- **[Lean](https://lean-lang.org/)** is a programming language and proof assistant. You state a theorem and give a proof. Lean's small kernel checks every step. If the kernel accepts it, the proof is right, whoever wrote it. That is what makes agent-written proofs worth trusting.
- **Veil** models protocols in Lean. The model describes the system as states and the steps clients can take. Veil walks every reachable state up to a set size, which is model checking. It also proves invariants that hold at any size.
- **cvc5** is an SMT solver. It does the heavy search behind those any-size proofs. Solvers have bugs, so its proofs are rebuilt in Lean and checked by the kernel.
- **Charon and Aeneas** turn Rust into Lean. Charon reads what the Rust compiler produces. Aeneas rewrites it as Lean functions that mean the same thing. The proofs are about the real code, not a sketch of it.
- **A refinement proof** links the code to the model: every decision the code makes is a step the model allows. What holds for the model holds for those decisions.
- **Simulation** covers what proofs can't reach. The code that talks to Podman and the operating system isn't pure, so it can't be extracted. A seeded simulation runs many clients against a fake engine that fails and crashes on purpose. The same seed gives the same run, so any failure replays.
- **Mutants** test the tests. Plant a bug and the check must fail. A check that passes anyway was checking nothing.

Each layer covers a gap in the one before. The spec says what must be true. The model shows the design keeps it, in every state and at any size. The refinement and the code proofs tie the design to the Rust. The simulation covers the I/O. The mutants show every layer can fail.

No layer is enough alone. Together they shrink what you have to trust to a short list: the spec and its assumptions, Lean's kernel, the Rust-to-Lean translation, and the I/O that is only simulated. The repo's ledger names every item.

## The spec

The spec has 13 properties and 17 assumptions. It took six revisions. One property: no session loses its container to another client.

## Model the old code first

Before fixing anything, we modelled the code as it was. Each suspected cause got its own model, and each model produced a trace showing the failure.

Then we modelled the fix before writing it. The model changed the design. The essential fix was a session guard. Two fixes I had planned turned out not to matter to any property, so we didn't build them.

## The checks

- **Model checking.** The fixed design ran through 4.36 million states with no violation. A two-client variant ran through 77 million.
- **Proofs for any size.** The design's invariants hold for any number of clients and containers. That is 1,201 proof goals. Lean's kernel checks each one, so the SMT solver that found them isn't trusted.
- **Proofs about the code.** The Rust decision core is pure. Aeneas extracts it to Lean, where it is proved. A refinement proof shows its decisions are exactly the model's steps.
- **Simulation.** 10,000 seeded runs, with engine faults and about 15,000 clients crashing mid-operation. No violation.
- **Mutants.** Remove any fix from the model and its property breaks. Eight broken drivers each fail the simulation. Broken code fails a proof.
- **CI.** Tests, simulations and real Podman and Docker runs on every pull request. Proofs weekly.

## What it found

Eight bugs, all fixed:

1. Another client could remove a container mid-session, four different ways.
2. A fresh start on Podman also removed other projects' containers.
3. Clients with different settings took turns recreating each other's container.
4. Two non-UTF-8 paths could get the same container name. A proof found it.
5. Trimming whitespace could remove a different project's old container. A proof found it.
6. A failed `podman start` was ignored, so start "succeeded" with the container stopped.
7. A fork bomb beat the cleanup. Simulation found it. The fix stops the container first, then kills.
8. On macOS, inherited pipes hung reads past any timeout.

## Check the checkers

The checks had holes too. The proof gate passed a goal the solver had crashed on. It missed failed goals under one locale, which hid a missing clause in an invariant. And it stopped catching unfinished proofs after Lean changed the quotes in a warning.

Now each gate has its own mutant, a planted failure it must catch.

## What's still open

- The driver's I/O sequence is simulated, not proved.
- One witness still trusts the SMT solver.
- The two-client check isn't in CI yet.
- Without a process limit, a fork bomb is unbounded.

The repo's [ledger](https://github.com/mcwelling/urithiru/blob/main/docs/ledger.md) lists what is proved, what is only tested and what is assumed.

## Lessons

- Model before you fix. The model told us which fixes mattered.
- Check the checkers. A gate that can't fail proves nothing.
- Crash injection found only bugs in the test harness.
- It took about a week by commit dates: 28 merged pull requests. Syl picked up each library change.
