Back to articles

Case Study

Agent design: lessons from an eight-day failure

We switched off an AI page-generation pipeline built over eight days and 145 commits, and replaced it with a tool built in a single day. The finer we sliced the steps and the harder we tuned the prompts, the wider the spread of results became. Quality rose only when we cut the steps an LLM judges and made the remaining ones scorable by code.

A one-day tool beat a pipeline that took eight

Reopt's Brandfront is a page builder for brand websites. Users talk to it in chat: "make the hero look like this image." The AI then reads the reference image and edits the page structure directly. This article is about the tools that carry out those edits.

Between 6 and 13 August 2026, 145 commits went into this path alone. The result was a pipeline that structures a concept from a reference image, compiles a page design plan, renders it in a real browser to inspect quality, and corrects the page from the visual verdict. A single generation request had the model make six judgments. Three routing profiles, a failover chain, a repair pass for schema rejections, a Redis cache, and a prompt byte budget hung off it. The core code alone came to 8,628 lines.

On 13 August we switched it off. A tool built in a single day that same week was producing better results. It runs on 1,601 lines with only two model steps, and it has no dedicated routing, no failover, and no repair pass.

Those eight days were not cheap either. The work over that window consumed 17.1 billion tokens — 9.7 billion through Claude and 7.4 billion through Codex, averaging 2.1 billion a day. Day-by-day usage is published at hansh.kr/works.

So what made the difference? Not the total effort. It was how many steps we stacked that an LLM has to judge. Slice the steps finer and tune the prompts harder and the average may creep up, but the spread widens with it. If three runs in ten land badly wrong, the feature is one users cannot trust.

First diagnosis — the model could read it perfectly and still not build it

The pipeline was shaped like this. A user supplies a reference image; the model translates it into an intermediate representation we defined; that representation is compiled into a page spec; the result is rendered in a browser and inspected; and whatever diverged goes back to the model for correction.

Loading diagram…
Three model judgments per build, looping back to the design plan when it diverges

Every arrow is a translation. At each one, information the next vocabulary cannot express is dropped, and that vocabulary's defaults insert things the source never had. Repeat four times and the image you first saw and the artifact you finally store are meaningfully different objects.

The first problem this creates is commonly misread. It was not that the model reads images poorly. The problem was the vocabulary we handed it.

const stylePropInputSchema = z
  .object({
    compositionId: z.string(),  // which block
    role: z.string(),           // which role inside it
    prop: z.string(),           // which property
    value: z.string(),          // one new value
  })
  .strict();

One call sets one value on one prop

This vocabulary cannot produce overlap. It has no way to express absolute coordinates or precise typography layered over a background. So when the reference was a poster-style composition — copy and a button over a background photo — the model could read that composition perfectly and still have no way to build it.

And this ceiling never shows up as "failure" in the logs. The model faithfully produces the closest thing it can express, which surfaces as a result that worked but does not resemble the request. One of reopt architecture's Module Contract judgment questions lands exactly here: what requests cannot be expressed through this contract? We had effectively answered "none". The real answer was "the kind of reference image users bring most often".

Second diagnosis — every check we added made results wobble more

We did not trust the output, so we added a check: render the page in a browser, capture it, ask a vision model how it looks, and run a correction turn if it diverged.

That check cost 40–60 seconds per page, and the cost was identical whether the result was good or bad. The correction loop was worse. Correction runs against a budget of turns and tokens, and when it fails to converge, what remains is the page as it stood when the budget ran out. The result reaching the user depends on when the budget expired.

The attached infrastructure was not small either: a serverless Chromium worker, a quality session store, per-stage timeouts, a bypass so a failed check would not discard the page. All of it was necessary, and none of it produces quality. It delays loss and softens incidents.

The deeper problem was the nature of the check. It is an LLM looking at a screen, which makes it probabilistic in its own right. A check we added because we did not trust the output lands as one more step we cannot trust. Build the same page twice and the verdicts diverge, so the corrections diverge too. Adding steps that an LLM evaluates does not raise the floor on quality. It is one more wobbly ruler.

Third diagnosis — one bad field threw the whole page away

Four panels: a page is built as one whole, one block goes wrong, the entire page is discarded, yet every other block was fine

Built as one whole → one part breaks the rules → the whole page is discarded → everything else was valid

Full generation builds a page all at once, by definition. So if one section's copy drifts or one image is missing, the whole artifact becomes questionable. Commit titles from that period name the symptom: "a failed generation must not delete the sections it finished", "stop discarding pages the check could not see". When the unit of work is large there is no way to express partial success, so you oscillate between "save everything" and "discard everything".

Two days after writing this, we pulled the same pipeline's failures together over a window and the numbers said it plainly. Of 108 tool calls, 14 failed; 11 of those were structure generation, rejected over enum violations on fields like visualSize and shape.radius. One line in the baseline document summarises this section:

Every other node was valid.

One field in one section stepped outside the rules and the whole page went in the bin. Those eleven attempts consumed 1,042 seconds, and two of them stopped at exactly 128 — a duration set by a timeout, not by the work.

What we built in a day

The new tool changed exactly one thing: what the model writes is what gets stored. No intermediate representation, no compiler, no design plan. What the model produces is the component tree that will be saved.

Loading diagram…
Built once with nothing in between, measured by code before it is stored

We also opened a new coordinate space to this tool alone: an isolated canvas with a fixed 390 design-unit width, where children use absolute coordinates and the composition holds whether the viewport is 320 or 440. The overlap and precise typography that were inexpressible in the first diagnosis are expressible here. This did not make the model smarter — same model, same image. What changed is the shape of the paper it writes on.

Removing the translations did not mean removing verification. It moved verification from after-the-fact correction to an acceptance gate before storage. The candidate block is rendered for real at 320, 390 and 440px, compared against the reference, and stored only if the improvement is confirmed. If it is not, nothing is written and the existing page stands; the failure receipt records that "the entire current page as it stood before verification" was preserved. There is no path by which a bad result reaches the user, and because the subject is a single block, verification is cheap.

Humans enter twice, too. When a target is found the tool does not edit immediately — it ends the turn on a "is this the right target?" card. And when candidate presets score close together, the user picks. The second one is implemented by leaving the tool's execute function empty: a tool with no execution function halts the agent loop where it stands, and the user's click is the resume signal. No approval state machine, no waiting queue.

Why does this matter for quality? The old pipeline carried a misjudged target all the way to the end. Running a 40-second check to completion against the wrong target hands the user a precisely wrong result. One cheap confirmation beats one expensive completion.

The four days after — the same diagnosis spread across the pipeline

That is where 13 August ends. It could have stayed a record of switching one tool off and another on, except that over the next four days the same prescription was applied to the whole concept pipeline.

We measured the contracts first. Each step was shipping a full schema to the model, and the weights looked like this.

style step     236KB   cache hit 17%
detail step    204KB   cache hit  0%
structure step  41KB   cache hit 44%

Static contract shipped on a single call

We were sending a 200KB contract afresh every time and never landing a cache hit. The schema was large, so the model struggled to satisfy it; struggling, it stepped outside the enums; and stepping outside meant total rejection. All three diagnoses meet in one place.

So we changed the shape of the contract. Instead of passing schemas as data, the steps exchange patches. The model no longer redraws the whole document — it writes only the lines it wants to change.

{"op":"add","path":"/spec/elements/hero",
 "value":{"$recipe":"side-media-hero","roles":{"headline":"…"}}}

Calling a vetted layout in a single line

Two things live in that line. One is partial acceptance: three rejected lines out of twenty still leave seventeen. The other matters more — $recipe means the model no longer invents a tree, it assembles from layouts that have already been verified. Until then, concept implementation rebuilt the hero from scratch every time, which is how text ended up laid over a photo, hiding the very thing it was meant to show. Forty-six vetted layouts already existed, including the two-column one; the concept path simply could not call them.

The static contract came down to 27KB, 12.8% of the baseline. The intermediate representation went with it — ConceptStructure v1 and v2 included, 7,416 lines of retired code.

The migration did confirm the earlier lesson once more, though. The new prompt taught a path the applier does not accept; the model wrote 48 well-formed lines exactly as taught, and every one was rejected. 26.8 seconds and 73 credits went straight into the bin. The tests were green — the fixtures spelled the correct path in by hand, so nobody ever asked what the prompt was teaching. Production logs caught it.

What we learned — exact answers and abstract ones

The diagnostic question this leaves is one line. How many steps that an LLM has to judge does the result pass through?

Each step is one more judgment the model makes alone. If p is the chance a given step clears the bar, the chance they all clear it is simply the product.

n=5, p=0.90  →  0.59
n=5, p=0.95  →  0.77   # prompts tuned to lift every step by 5 points
n=2, p=0.90  →  0.81   # prompts untouched, steps cut instead

The same effort spent on prompts versus spent on step count

Cutting five steps to two beats lifting each step by five points. The left column is exactly what we did for eight days: swap models, add failover, bolt on a repair pass, put a budget on the prompt. p crept up; n never moved. And users never experience an average. They get one good run and one badly wrong run, and they decide whether to trust the feature based on the wrong one.

The common wrong remedy is to bolt on a checking step. If the checker is an LLM, that step also has p < 1, so n simply grows by one. If the checker is code, it is a different animal: overflow pixels, clipped text counts, accessibility violations return the same answer for the same input every time. They cull bad candidates without entering the product at all.

Sometimes the steps cannot be cut. Framing a concept, laying out structure, choosing colour and type, generating images, refining details — these differ enough in kind that one call cannot do them all. What remains then is to keep any single term from going to zero. A contract where everything must be right or nothing counts, and one where the lines that landed survive, produce very different outcomes from the same step. If you cannot reduce n, making each step capable of partial success is the next largest lever.

This debt is caught by review habits more than by instrumentation. Colour the boxes an LLM judges differently from the boxes code decides, and the count of the former is the size of your spread. Before adding a check, ask whether it can be written as code. When tool failure rates are low but satisfaction is low, suspect the shape of the successes. Run the same input two or three times; if the results diverge, the fix is not a higher average but finding the step that makes them diverge.

In the end there are two kinds of answers to deal with: exact ones and abstract ones. Whether text is clipped at 320px, whether adjacent sections held — those are exact, and only code returns the same answer every time. What composition this reference image has, where this piece of copy belongs — those are abstract, and only an LLM can produce them. Assign either kind to the wrong party and it goes wrong. Over eight days we made that mistake in both directions: we tried to squeeze abstract answers into a code vocabulary, and handed scoring, which had to be exact, to an LLM.

The best results come not from picking one side but from putting both in their place and letting them mesh. Let the model interpret, take its output in a directly storable form, let code do the scoring, and ask the model back only for the last layer code cannot measure. The new tool did better in a day because it kept that arrangement, not because it used less of anything.

That does not make the eight days waste. Without them we would not have known precisely what the problem was. The quality runner taught us that defects exist which are only visible in a real render, and that became the new path's acceptance gate.

The unfinished work deserves stating plainly. The 236KB and the cache-hit figures above are all pre-migration numbers. With the contract down to 27KB, what actually changed can only be said by measuring again on the same axis — and we have not measured. That is why this article does not claim things got better. The new acceptance gate also still leans on a vision model for its last layer, and how much of that verdict can be moved into code is the next question.

Tags

reoptbrandfronttool-designguardrailsagentic-debt

Related patterns

  • Module ContractDeclare the conditions, authority, and failure paths of every execution unit.
  • Evaluation and GuardrailsDistinguish acceptable judgment from dangerous judgment via evaluation criteria and safety rules.
  • Human ApprovalKeep high-cost, high-risk, high-impact decisions inside a human-approval flow.
  • Cost ControlManage token budget, model selection, and call frequency structurally to control the cost curve.
  • Decision TraceabilityRecord judgment rationale, choices, and collaboration paths as structured logs.
  • Responsibility PartitioningName the owner of each outcome and draw the boundary around it.