Chaos Begets Chaos; Order Begets Order: Agentic Coding as Crystallisation

7 min read Original article ↗

Tal Rotbart

Press enter or click to view image in full size

TL;DR: Coding agents grow your codebase the way crystals grow on a substrate: each new layer copies the structure of the layer beneath it. An ordered core produces ordered growth. A chaotic core produces chaos, deposited at machine speed. The good news is that the same speed works in reverse. With the right guardrails and ratchets, agents can recrystallise a messy codebase almost as fast as they can wreck a clean one. Speed is neutral. Direction is the engineering.

Materials scientists have a name for what coding agents do to your codebase: epitaxy.

When you grow a crystal on a substrate, the new atoms don’t arrange themselves according to some ideal. They take their positions from the lattice beneath them. An ordered substrate produces ordered layers, stacking into a clean crystal. A disordered substrate produces disordered layers, and the defects propagate upward through everything built on top.

Agents work the same way, and more faithfully than we do. A human engineer layering onto a messy codebase exercises local judgement. They quietly tidy as they go, or at least wince and route around the worst of it. An agent pattern-matches on what it finds and continues it, at speed, without the wince. The existing structure of your codebase has stopped being background. It is now the strongest control input you have.

The seed crystal

Here’s the useful part of the metaphor. To grow a large ordered crystal from a supersaturated solution, you don’t need to arrange every atom by hand. You drop in a seed: a small, well-formed crystal whose lattice the rest of the solution copies outward.

The same holds for agentic delivery. You don’t need a perfect codebase before agents become productive. You need a deliberately built core whose patterns the agent replicates: a reference module that shows how services are structured, a test suite that demonstrates what coverage looks like here, an AGENTS.md that states the conventions in prose. These are decisions made once, early, that shape thousands of decisions made later by machines.

Which means the highest-value human work has moved. It is no longer depositing the layers. It is crafting the seed.

The quench

There’s a catch, and the metaphor names it precisely.

Crystal structure depends on cooling rate. Cool a melt slowly and atoms have time to find their ordered positions, and you get a crystal. Cool it fast, a rapid quench, and atoms freeze wherever they happen to be. You get glass: solid, functional even, but amorphous. No structure to build on.

Agentic speed is a fast quench. The property that makes agents valuable, the sheer rate of deposition, is the same property that locks in disorder before anyone can correct it. A human team accumulates tech debt over quarters, with time to notice and push back. An agent working on a chaotic substrate can deposit a quarter’s worth of amorphous mess in a week. Every dislocation in the layer below repeats in the layer above, mechanically, at machine speed.

Tech debt used to compound socially, through habit and broken windows. Now it compounds physically.

Zone refining

So far this reads like a warning. Here’s where it turns, because materials science also solved the reverse problem, and the solution maps beautifully.

Semiconductor-grade silicon is made by zone refining. You take a disordered, impure ingot and pass a narrow molten zone along it. As the zone moves, the material behind it recrystallises in order, and the impurities stay dissolved in the melt, swept along to the end of the bar, where you cut them off. Nobody remelts the whole ingot. The zone is small, the pass is repeatable, and each pass raises purity.

That is an agent-driven refactor done well. A bounded region of controlled change moving through the codebase. Order solidifying behind it. The mess concentrated, contained, and eventually removed. The agent that deposits chaos on a chaotic substrate is the same agent that recrystallises it, given one thing: a gradient.

Ratchets are the gradient

Zone refining only works because the thermal gradient is directional. The crystallised region behind the zone never remelts. Order propagates one way.

In software, the gradient is a ratchet: a rule that lets the boundary between order and chaos move in one direction only. You already know the mechanisms, though you may not have thought of them as a family:

  • A lint configuration that forbids new violations while tolerating existing ones, with a counter that only accepts a smaller number
  • A coverage threshold that rises with each release and never falls
  • An import ban on the legacy module, so new code physically cannot reach into the old world
  • A CI check that fails any change increasing the size of the deprecated directory
  • Contract tests on every service boundary, so the interfaces between recrystallised regions can’t silently drift
  • Higher-order, AI-based linting that reviews changes against your stated engineering patterns, catching structural violations no regex-based linter could express: a repository that bypasses the service layer, a handler that took on orchestration it shouldn’t own

Each of these says the same thing: the recrystallised region stays recrystallised. Without them, agents happily redeposit chaos on freshly ordered ground, because they pattern-match on whatever’s nearest, and the nearest thing might be the mess next door. The ratchet is what makes each pass permanent.

The mess funds its own repair

There’s one more gift hiding in the metallurgy, and it’s the hopeful one.

Recrystallisation in metals is driven by the strain energy stored in the defects themselves. The disorder holds the energy that powers its own repair. Give the material enough heat and the stored energy does the work.

Your codebase is the same, with one condition: you have to name the target lattice. Hand an agent a statement of your engineering patterns, the same guidance that powers your higher-order linting, and it becomes a remarkably good surveyor of deviation. Ask it to find every place a repository bypasses the service layer, every handler carrying orchestration logic, every duplicated implementation of the same domain concept, and it will sweep the entire codebase and hand you a catalogue: each instance located, described, and rankable by blast radius. This used to be the most expensive knowledge in the building. It lived in the heads of the two engineers who’d been there longest, assembled over years of walking the code, and it left when they did. Now it’s a pass you can run on Tuesday.

That’s the real meaning of the strain energy. The mess contains the information needed to fix the mess, and agents can finally read it, provided you’ve told them what order looks like. What was missing before was never awareness that the debt existed. It was the survey, and then the thermal budget to act on it. Refactoring energy was scarce because it competed with feature work for the same humans, and feature work always won.

Agents collapse both scarcities at once. Detection is now a query. Heat is now cheap. Deposition rate and annealing rate rose together, and the deciding variable is no longer effort. It is whether a gradient exists. An agent inside a ratchet, working from a named target lattice, anneals. An agent outside one deposits whatever it last saw.

Set up the pass

Speed is neutral. The same velocity quenches chaos into glass or drives a molten zone through the ingot, and the difference between the two outcomes is structure you put in place before the agent starts: the seed it copies from, the ratchets that hold each pass.

For years, a messy codebase was a verdict. It meant slow delivery for as long as anyone could see, because the energy to fix it would never be spared. That has changed. The mess is now a bar of impure silicon waiting for its first pass.

The question worth asking your team has changed with it: have you set up the pass?