← Reference builds

Rebuilding the development loop around agents

Spec-to-PR drafting, a review agent trained on the team's own escaped defects, characterisation tests on a decade-old billing module, and a written policy that let the CTO answer the security questionnaire honestly.

B2B healthtech · ~60 engineers · Rails + React monolith/12 weeks/Levelbrook reference build

About these write-ups. These are Levelbrook reference builds — the architecture, guardrails, failure modes and economics of the systems we build, documented as complete engagements. Client names are withheld and the figures are modelled from the operating assumptions stated in each build, not lifted from a named customer’s books. The two live demos are real and run in your browser: the approval queue and the call agent.

The situation

A B2B healthtech company: 60 engineers, an eleven-year-old Rails and React monolith, ~1.4M lines, and a board that had asked what the company's AI strategy was. The existing answer was 60 code-completion licences and no measurement of any kind.

The actual engineering problems, which is where we started instead:

  • Median PR cycle time was 4.1 days, and review latency — PR opened to first substantive comment — was 19 hours. Nothing was slow because engineers typed slowly.
  • Escaped defects clustered brutally: 61% of production incidents over two years originated in four modules, all with test coverage under 20%, all authored by people who had left.
  • The billing module was the biggest of these. Nobody would change it. Work routed around it, which is how you end up with three places that calculate a proration.
  • Onboarding to first meaningful PR averaged 5.5 weeks.
The finding we lead with in every engineering engagement Code generation is the cheapest part of software and almost never the constraint. The constraints are review, comprehension, and fear of the code you already have. Point the agents there.

What got built

1. A review agent trained on their own incidents

Generic AI review comments on style and get muted within a fortnight. We mined two years of incident reports, postmortems and revert commits, and derived twenty-three concrete failure patterns this team specifically ships — N+1s introduced in serializers, missing tenant scoping on new queries (the one that matters most in multi-tenant healthcare), background jobs without idempotency keys, migrations that lock a large table, PHI reaching a log line.

The reviewer checks for those and stays silent otherwise. It posts at most three comments per PR, each one citing the specific past incident the pattern caused. Engineers argued with the design in week one and were converted by the citations: it is very hard to dismiss a comment that says "this is the pattern that caused INC-2024-11."

It has no merge rights and never will. It is a reviewer, not an approver.

2. Characterisation tests before touching the scary module

The billing module could not be safely refactored because nobody knew what it did. So the first agent work was not refactoring — it was writing characterisation tests: tests that assert current behaviour, correct or not, to create a safety net.

Method: instrument production for two weeks to capture real input/output pairs for the module's public surface (scrubbed of PHI at the boundary), generate tests from those pairs, and have an engineer review each generated test for whether the captured behaviour was actually intended. That review was the valuable part. It surfaced four long-standing bugs, one of which had been silently under-billing a class of customers for three years.

Coverage on the module went from 17% to 74% in five weeks. The team then did the refactor themselves, which was always the point.

3. Spec-to-PR, deliberately narrow

An agent that takes a well-formed ticket and produces a draft PR with tests, running in CI. We scoped it hard: it only runs on tickets tagged as belonging to a pattern that already exists in the codebase — a new endpoint on an existing resource shape, a new report on the existing reporting framework, a field addition through the standard stack. It does not do novel design and it does not touch the four high-incident modules at all.

Roughly 30% of the backlog qualified. Of the drafts it produced, 46% were merged after human review and edit; the rest were closed or rewritten, and closure reasons are captured to improve the templates. We report the 46% rather than the 30% because the honest number is the one that survives review.

4. Comprehension for humans

Grounded question-answering over the repo, the ADRs, the wiki and the full git history — the history being the part everyone forgets and the part that answers "why". "Why does this module do its own retry instead of using the shared client?" is answered by a 2019 commit message and a linked incident, not by a paraphrase of the code. This was the single most used tool of the four, by a wide margin, and it moved onboarding-to-first-PR from 5.5 weeks to 2.5.

5. The policy document

Their enterprise customers' security questionnaires had started asking about AI in the SDLC, and the company had no honest answer. We wrote one: which agents exist, what identity each runs as, what credentials each holds (all short-lived, all scoped, none with production data access), that generated code is marked in commit trailers, that no agent can approve or merge, what is logged, and how it is audited quarterly. Two of their customers asked for it verbatim.

What broke

Failure 1 — the reviewer that was technically right Early on the agent flagged genuine but trivial issues at a rate of nine comments per PR. Engineers muted it inside a week. Capping at three comments, ranked by the historical severity of the pattern, was worth more than any accuracy improvement. Attention is the scarce resource in review, not correctness.
Failure 2 — generated tests that asserted the bug Characterisation tests faithfully encoded the under-billing bug as expected behaviour. That is exactly what characterisation tests are supposed to do, and it is dangerous if anyone forgets. The mandatory human review of each generated test is not a formality; it is the entire control. We now label these tests distinctly in the suite so nobody later reads them as specifications.
Failure 3 — we measured the wrong thing for three weeks We started reporting PRs-opened-per-engineer, which went up while nothing improved. It is a metric that rewards splitting work. We switched to cycle time, review latency, escaped defect rate and change failure rate. If an AI programme cannot move those four, it has not moved anything.

Where it landed

MeasureBaselineWeek 12
Median PR cycle time4.1 days2.3 days
Median review latency (open → first comment)19h2h 40m
Test coverage, billing module17%74%
Onboarding to first meaningful PR5.5 weeks2.5 weeks
Backlog eligible for spec-to-PR30%
Agent drafts merged after human review46%
Change failure rate14%9%

Escaped defect rate is the number we care most about and it is also the one that needs longer than twelve weeks to claim honestly — the trend was down, the sample was not yet large enough to state as a result, and we said so in the final report rather than putting a number on a chart. That is the standard we hold ourselves to on every engagement, and it is why the tables on this page are shorter than a vendor's would be.

Your engineers do not type slowly.

The constraint is review, comprehension and fear of the legacy. That is where the agents belong.