Skip to content
Nelson D’SouzaEmail me
Writing

Done means used: wiring agent-built code end to end

How I keep an agent-built system wired end to end: done means integrated and used, a scoreboard whose bar only rises, and a review of what really runs.

By · · 11 min read

  • AI Agents
  • Verification
  • Formal Methods
  • Rust
In this note
  1. The garden
  2. Model checks that must catch broken copies
  3. A scoreboard that only moves up
  4. What the integration review checks
  5. Done means used
  6. Signals that clear themselves
  7. A gate built to fail
  8. Code is memory

On 2026-11-22 a review of Sage, my personal assistant, found three subsystems with no live caller and no installed binary, a usage ledger that had never written a row, and live binaries dated 2026-11-04 and 2026-11-19. Every static gate was green at the time. Agents had written that code, it had landed on main, and nothing on my scoreboard asked whether anything called it.

Agents write most of the code in Sage. I write the briefs, review the diffs and make the design calls. They write code faster than anyone can read it line by line, so the process around them has to catch what reading misses. Three parts of it matter here: a scoreboard that rates every feature against a baseline that only rises, an integration review that checks each subsystem against the running machine, and, since that review, a definition of done that means integrated and used. What the review found became the top rungs of a stage ladder, so the same gap now fails the gate.

The garden#

Sage is a Rust hub with a knowledge service (Alfred) and a builder (Bob the Builder) plugged into it. When agents write most of the code, the failure I design against is silent drift: a feature works on the CLI but not on the web, a lifecycle is tracked with three booleans that can contradict each other, or dead modules pile up because nobody remembers what is still wired.

I call the practice the garden. It starts with one JSON index, a product feature map, which lists every user-facing feature, its entry points across CLI, web and chat, and the source files it binds to. The agents work through the system one subsystem at a time, ordered by what a bug would cost, starting with the build runner and moving out toward lower-risk tools.

Every subsystem goes through the same eight steps:

  1. Inventory every entry point, owner, durable writer and lifecycle in the subsystem.
  2. Turn each lifecycle into an explicit typed state machine.
  3. Formally verify the lifecycles where a bug costs most.
  4. Delete dead code and split oversized files by responsibility.
  5. Bring the CLI, web and chat to parity through one shared operation.
  6. Check architectural boundaries and dependency directions.
  7. Update the feature map with what changed.
  8. Gate, land, deploy and exercise the feature once on the live box.

The state-machine rule is short on purpose. Every sequential lifecycle is an enum of states, an enum of events, and one pure next(state, event) function that returns an error for any illegal transition. Side effects happen after the transition is committed to disk, never inside it. No pair of booleans may stand in for a state. If a struct holds both is_running: bool and cancelled: bool, both can be true at once and every caller has to guess which wins. An enum cannot express that contradiction, so the compiler catches it before a test ever runs.

Model checks that must catch broken copies#

Where a bug would be expensive, such as kicking off a duplicate build or letting a stale worker overwrite a finished task, the state machine also gets a TLA+ specification checked by TLC. TLC is a model checker. Given a finite slice of the system (a few tasks, a few agents, a ticking clock), it walks every reachable interleaving of events to see whether any invariant can ever be broken.

A green model-checker run proves only that the model satisfies its invariants, not that those invariants are non-vacuous. An invariant that accidentally simplifies to true, or an action that never fires, passes every time. That is the same proxy trap I wrote about in my delivery loop: an instrument nobody has held against a known-bad input is untested.

So every check in the model sits beside a deliberately broken variant, a copy of the spec with one rule removed or weakened, and the check must catch it:

  • The build lifecycle, the first subsystem the agents worked through, has 12 broken variants, each caught by its named invariant or action property.
  • Commons, the agent board built next, has 20 for its task rules alone.

A conformance test in Rust reads the model’s edge table directly and compares it with the Rust next function in both directions. Neither the spec nor the code can drift without breaking the build.

A scoreboard that only moves up#

To track progress across dozens of features, a script (garden_scoreboard.py) scores every feature in the feature map. At first it measured four structural criteria:

  • The feature’s lifecycle is a typed state machine with a single writer.
  • Its formal model (where needed) is verified and in sync with the code.
  • Its CLI, web and chat entry points are at parity.
  • None of its non-test source files exceeds 500 lines.

The script runs inside the ship gate’s static-analysis step as a ratchet. It fails if any feature’s score drops compared with origin/main, or if a new feature arrives below the bar. A branch lands its improvement and updates the baseline file in the same commit, so the bar only moves up.

Before the stage ladder, 37 features scored 69 of 288 points (24 percent). Thirteen had a typed state machine, 11 were verified, eight met the file-length rule and one was at parity.

What the integration review checks#

A ratchet only holds the line on what it measures, so the scoreboard needs an outside check. The integration review is that check. An agent walks every layer of the design against the running machine and records only its highest proven level: designed, built, wired, or used with live data in the last 14 days.

The review of 2026-11-22 shows what it catches. The manager loop and the research loop had no dependents anywhere in the workspace, the durable core was called only by the uncalled manager loop, and none of the three had an installed binary. The usage ledger had code and tests, yet no usage.sqlite existed on disk, so the cost page showed nothing. The live binaries were weeks behind main.

It also checks whether the parts that run are doing useful work. A background model probe had been calling every configured provider, paid ones included, four times every five minutes for seven months. Two providers had failed on auth 14,574 times in a row each. The probe had written 171,402 rows (124 MB) to SQLite, its one reader read only the newest window per task class, and nothing acted on the result. The probe is now off unless configured on, and its table keeps a bounded window. The feature map needed the same correction: it marked tracing as “live” on the strength of a single reported observation.

The cause sat in both the scoreboard and the briefs. The scoreboard rewarded state machines, parity and file length, and never asked whether anything called the code. At the same time, my briefs scoped one subsystem at a time without requiring a caller or a deploy. Between the briefs and the score, landing an unwired library looked finished.

Done means used#

So I changed what “done” means. Landing on main is no longer done. It is only built. Every feature now climbs a five-rung ladder, and every rung above built requires recorded evidence in the feature map.

The stage ladderFlowchart with 5 nodes, 4 connections. Each step is listed as text below.DesignedBuilt (lands on main)Integrated (gatedboundary test)Deployed (live binarycarries commit)Used (reviewedquery over live data)weight 2weight 3
  1. Designed to Built (lands on main)
  2. Built (lands on main) to Integrated (gated boundary test): “weight 2”
  3. Integrated (gated boundary test) to Deployed (live binary carries commit)
  4. Deployed (live binary carries commit) to Used (reviewed query over live data): “weight 3”
Fig. 1 The stage ladder Landing on main only reaches built. Each higher rung requires recorded evidence in the feature map (with used recorded as a reviewed declaration in git rather than queried live by the gate), and the scoreboard weights integrated and used so real use outscores structure.

Each rung has a concrete definition:

  • Integrated. A non-ignored test that the gate runs drives the feature through its real entry point (CLI, web, chat, HTTP or MCP) across at least two components, with no mocks of our own code.
  • Deployed. Recorded in a follow-up attestation commit after deploy: the feature map names the commit the live binary carries and the command that proved it (built and integrated land on main first, because a pre-merge branch cannot prove it is deployed).
  • Used. Also recorded post-deploy: the map names the query run over live data, its result, the time window it covered, and a tracked file holding the raw evidence.

A declared stage above its evidence fails the gate. So does a declared stage below it, so a branch that adds real evidence also advances the stage. And the scoreboard weights integrated at 2 and used at 3, against 1 for each structural criterion. A feature that is integrated and used now outscores a textbook state machine that nobody calls, and a feature only counts as at-bar once it is used.

Scoreboard versionCriteria and weightsScore across 37 featuresFeatures at bar
Before (structure only)machine (1), verified (1), parity (1), loc (1)69 / 288 (24%)—
After (done means used)four structure (1 each), e2e (2), used (3)139 / 630 (22%)0 of 37

The score dropped on the day this landed, from 24 percent to 22 percent, with zero of 37 features at the bar. That day-one score is a baseline hypothesis on a single-developer local box—not a multi-stage enterprise release train—and whether it raises live wiring over time awaits longitudinal proof. Every branch now has to beat it.

The design has known limits. The ship gate never queries a live service, because a gate must be reproducible from the git tree alone. That means a used record is a dated declaration checked by human code review rather than a live probe—a real circularity when agents generate code faster than anyone reads it line by line. And until the live binaries embed a commit hash, deployed is inferred from install logs and marker strings extracted from the binary.

The ladder also makes progress harder to show. A branch can no longer move a feature to integrated with a refactor, and moving all the way to at-bar requires a post-deploy commit carrying a live-data query; on the day the ladder landed no feature was at the bar. The file-length criterion has a weaker spot. A cap on lines scores a module cut into two arbitrary halves the same as one split along a real seam. The code standard says a module over 500 lines is split by responsibility, and only review can tell which kind of split happened.

Signals that clear themselves#

The review also reads the monitoring signals, and asks whether each one can still tell a fault from a healthy service.

The Telegram connector reported degraded in all 8,573 status samples collected since 2026-11-20. Over 38 hours it had seen 45 errors, roughly one transient network hiccup an hour, and its last_error field never cleared. Once one error happened, the connector stayed degraded forever, so the flag could no longer distinguish a live outage from a blip yesterday. It is now a small health state machine where a clean poll clears the fault.

One case is still open. After the next deploy, /health reported degraded for hours, and the only reason was connector_inbound_stale: no Telegram message had arrived since startup. A quiet inbox is not a fault while polling succeeds, so this is the same flag problem in a new place.

Tracing gets the same question one layer down. Over seven days the gateway exported 48,036 spans. Of the 7,115 model-call spans, 7,000 carried no model attribute at all and the remaining 115 came from a test fixture (router-e2e-test). Not one was a live model call.

A gate built to fail#

Nothing reaches main without passing the ship gate. Given a diff against origin/main, the gate picks the verification categories the change triggers (build, lint, unit, regression, mutation, diff coverage, threat modelling, formal verification), runs each check through a wrapper that logs the exit code, output and SHA-256 digest, and writes an attestation keyed to the exact git tree hash. A pre-push hook refuses any tree without a valid attestation.

The rule that matters most is that failed evidence can never be edited or deleted. An agent cannot quietly erase a red check and re-run until it gets lucky.

That immutability is deliberate, and it has a cost. On 2026-11-22 four git trees took permanent failing evidence in one day from bad commands, not bad code: a bare tlc call with missing arguments, an auto-detected default test command that did not fit the repo, a test that flaked under load, and a hand-typed commit SHA. Each one forced a fresh tree and a full re-run.

So the gate has a separate try subcommand. try executes a check in the exact environment run uses and prints what it would record, while recording nothing. Once try exits 0, run executes the command for the record.

Try, then run, then attestFlowchart with 7 nodes, 7 connections. Each step is listed as text below.Plan categories fromdiffTry the commandExit 0?Fix command orcodeRun (immutableevidence)Attest exact git treePre-push hookverifies treenoretry commandyes
  1. Plan categories from diff to Try the command
  2. Try the command to Exit 0?
  3. Exit 0? to Fix command or code: “no”
  4. Fix command or code to Try the command: “retry command”
  5. Exit 0? to Run (immutable evidence): “yes”
  6. Run (immutable evidence) to Attest exact git tree
  7. Attest exact git tree to Pre-push hook verifies tree
Fig. 2 Try, then run, then attest Try is the only step that can fail for free. Because recorded evidence is immutable, a mistyped command is caught before it marks the tree.

The load flake got a fix in the test kit. A test that wrote a helper script and immediately executed it failed on Linux with ETXTBSY (“text file busy”) in 276 of 2,000 runs at eight forking threads. The mechanism is a classic Unix trap. Thread A opens a file for writing. Thread B concurrently calls fork() to launch an unrelated subprocess, and that child inherits a duplicate of thread A’s still-open write descriptor. Even after thread A closes its own descriptor and calls exec(), the kernel sees the child still holding a writable handle to that file and refuses to execute it.

Now one shared helper in sage-testkit writes every executable test script through a separate sh process that has already exited before the test calls exec, and a static check flags any test that sets 0o755 permissions on a file in place.

Process tests had a sibling race. They bound an ephemeral port, closed the socket, and started a real gateway hoping the port would stay free. Four parallel copies collided every time (0 of 24 passed under load). The gateway now accepts port 0 and logs the port the kernel assigned, so tests never pick a port before the gateway owns it.

The gate has no retries. A retry would hide which run failed and why.

The gate’s own helper scripts get the same scrutiny. A Python helper that tells the gate whether a diff is test-only accepted --base=--output=FILE, passed it straight to git diff, wrote the file and exited 0 with empty output. That would have led the gate to mark every behavioural verification category not applicable. Every git call in the helpers now validates revision arguments at the boundary (refusing a leading -) and puts --end-of-options before them, enforced by a static check on every diff.

Code is memory#

I learned this framing from Lauren Tan, who calls it “code is memory”. In her talk All Code Is Slop (Except Mine) she puts it plainly: “The codebase is also one of the agent’s largest inputs.”

Coding agents do not remember last week’s post-mortem. The codebase does. Whatever lands on main becomes the example the next agent imitates, so every shortcut that slips through review quietly becomes the new house style.

That is why each finding in this post ends as a written rule in the code standard, dated with the finding that caused it, and wherever a script can enforce it, as a check that fails the build: the probe nobody acted on, the permanent degraded flag, the ETXTBSY race, the argument injection.


While the scoreboard rewarded structure, the agents built clean, well-typed libraries, some of which nothing called. Now the baseline bar rewards integration and live use—designed to be tested over the merges ahead—and every report has to show who calls the code.

Built in: Alfred, Sage

All writing