Le secrétaire de Fernand

Step 10: Freeze what the code does before a refactor you can't review

Step 10: Freeze what the code does before a refactor you can't review

The tenth step of the harness I put around my coding agents: freeze what the code does in a snapshot before a refactor you can't review, and lock it.

2 min read

Part of the series: Codebase Harness, Step by Step · View all parts

Previously in this series: Step 9: A model per phase

Before a refactor you can't review, freeze what the code does today. In May an agent was about to rewrite the loop that runs every plan in my orchestrator. I could read neither version. So the first phase wrote down what the old one did.

Böckeler's grid

Two dimensions. A guide acts before the agent, a sensor after. Each is inferential, judged by a model, or computational, decided by a program. Inferential guides are what the agent reads, AGENTS.md, a skill, a plan, sharper written in the literature's words; computational guides are deterministic tools, a codemod, a generator, a command that acts in the agent's place, code mode, where the agent writes a program instead of a string of actions, a language server. Inferential sensors are a review by a model or a person; computational sensors are the type checker, the linter, tests and fitness functions. Each practice moves a judgement toward computation, and the computational sensor is the optimum.

Inferentiala model judges, your attention follows
Computationala program decides, without your attention
Guidesbefore the agent acts
  1. 4 · literature in skills
  2. 5 · skills
toward computation
a codemod · a generator · a command (CLI) · code mode · a language server
Sensorsafter the agent acts
a review by a model or a person
toward computation
the optimum
  1. 1 · type checker
  2. 2 · linter
  3. 3 · dead code
  4. 6 · fitness functions
  5. 7 · plan in phases
  6. 8 · files per phase
  7. 9 · model per phase
  8. 10 · snapshottoday

In Birgitta Böckeler's grid of guides and sensors, the snapshot is a computational sensor written before the code it judges: a contract, as long as the agent cannot rewrite it. The series' map: Guides and Sensors: Mapping Your Attention to Free It

How it went

The first phase ran the old code on two scenarios, a clean run and a run paused by a rate limit, and stored every trace event, in order, as a snapshot. The commit calls it the contract the refactor must preserve byte for byte.

Then one rule for every later phase: change anything except that file. If the snapshot breaks, the refactor broke something. Fix the code, never the snapshot.

Nothing enforced that rule but my attention: I checked each phase's files for that one path. Months later it became a tool, a list of files no phase of a run may change, refused before the write where the agent's provider allows it.

The literature calls it a characterization test, after Michael Feathers' Working Effectively with Legacy Code: Characterization test Approval tests and golden masters are the same idea: Approval Tests

If you want an example, here is the commit: github.com/lbdremy/phax/commit/be920b1b28d866607cf6a9538d66fcc6fe3db73a

A thought after reading?

If you would like to discuss about this article, you can write to me here. I share because I care and I want to learn. Please teach me with care.

Send me an emailremy@lesecretairedefernand.co