The HDD loop
The loop works like this. The agent gets a task and produces a result. Sensors (a test, a linter, a review) check the result. If everything passes, the task is closed. If a sensor finds a mistake, a person changes the agent’s environment, the harness: adds a line to the instructions, a test or a hook. The next task runs with that rule, and the mistake does not repeat.
Mitchell Hashimoto's principle: when the agent makes a mistake, change the harness so that mistake can't happen again Faros
A prompt fixes one request, context fixes what the model knows, the harness fixes every following run. Example: the agent edits code and does not run the tests.
Stages as described by Faros and marmelab
The table shows one mistake (the agent edits code and does not run the tests) and three ways to fix it. Prompt: add “run the tests after the edit”. That works for one request only, and the next one starts from scratch. Context: write the same into the project instructions file. The model reads it but may skip it. Harness: add a hook that runs the tests itself after every edit. It runs without the model, so the fix holds in all following runs.
How a harness is laid out: 3 × 3
Three domains of the loop and three contexts in each — nine canons. Every canon has exactly one domain and one context.
The matrix reads as three questions. Expectation: what the result should be (for example, “after the edit the tests pass”). Observation: what it actually turned out to be, which a sensor records. Loop: compares the two and decides what to do. Each of the three rows has three kinds of support: spec (what must be true), skill (how to act) and memory (what to lean on). The words “domain” and “canon” are just names here: a domain is a row of the matrix, a canon is one cell, for example the Expectation spec. The diagram below shows the direction of links: Expectation and Observation feed the Loop, and it yields either a patch (fix the action) or a revision of the rules. There is no link back to the Loop, so the domains do not tangle into each other. The memory modes: snapshot is a table updated when a new measurement arrives; live means the data is taken from the live system (for example through MCP) each time and is not stored.
The double loop
The double loop answers the question of what exactly to change after a mistake. Take the same mistake: the agent did not run the tests. In a single loop you remind the agent, it runs the tests, and the rules stay as they were. In a double loop you ask which rule allowed the mistake and change it: now a hook runs the tests after every edit. The idea comes from the theory of organizational learning (Chris Argyris and Donald Schön): a single loop corrects the action, a double loop revises the rules the action followed from. Wikipedia: Double-loop learning.
The loop applies to itself: every run ends with the residual risk, never with a “done” status.
Changing the rules after every complaint is risky: the harness starts to sprawl from chance edits. So the Loop applies four checks. If the fixes only plug holes and predict nothing new, they are replaced by one rule. If there are several complaints, first test whether they share a cause. A new rule is accepted only if the old cases are still explained with it. A rule without an outside check is dropped, but the record says what was dropped and why. The caption under the cards means the Loop applies to itself too: a run ends with a statement of the residual risk.
Guides and sensors
Checks in a harness split by two features. The first is when they fire. Guides work before the agent acts and set the course: types, code templates, instructions, specs. Sensors work after the action and catch deviations: tests, a linter, an AI review. The second feature is how a check is built. Computable checks (types, tests, linter) fire in seconds and do not err within their rule. Checks through AI (an AI review, a model judge) are more flexible and more expensive, so they are kept for meaning: style, clarity, fit to the intent.
Split as described in Birgitta Böckeler, martinfowler.com
Three check layers
Checks are laid out in three layers. Code quality: style, formatting, types, simple errors. Architecture: module boundaries and dependencies between them, speed requirements. Behavior: whether the product does what the user needs. The bars in the picture show how well that layer has been learned to be checked automatically: the first bar is almost full, behavior has the shortest.
Layer maturity as assessed by Birgitta Böckeler, martinfowler.com
Earlier is cheaper
Any check fires at some moment, and the earlier it does, the cheaper the mistake is to fix. The picture shows four moments: before the agent works (instructions and specs), at write time (hooks and a linter), in CI (an automatic build and tests when code is pushed to the repository) and in a human review. The $ signs show the rising price of a mistake.
Tests are run by engines such as QUnit, Jest and Vitest. How they differ and which to take is covered in the article Vitest vs Jest: which to pick for a JavaScript project, and when QUnit is enough. Behavior rules that ordinary tests cannot check are found by a model in Quint.
Where people matter
The harness takes over routine checks: style, types, tests, module boundaries. A person decides what a formal check cannot cover: architecture, product questions and new rules. The numbers in the picture show an example ratio: 36 checks for the harness and 6 for a person.
"A good harness keeps the human in the loop and directs their attention to where it matters most" — paraphrasing Birgitta Böckeler, martinfowler.com
HDD and specs
A spec and a harness complement each other. The spec answers “what should come out”, the harness checks that exactly that came out. In the picture the spec sets the needed result, the harness checks it, and code is accepted by the results of checks rather than by reading every line.
"Specs define the target state, the harness is the control system" — Loiane Groner. More on specs in the talk Spec-Driven Development in practice
Where to start
A harness does not have to be designed whole. Start with five steps: the first two set up the environment at once, the other three start the “mistake → rule” loop. A progress file is needed when a task is longer than one session: it holds a list of features with a status, and a new agent session continues from the same place.
- 1
- 2Linter and tests after every edita hook the agent runs itself before handing over the result
- 3An agent mistake logevery mistake fixed by hand gets a line with its cause
- 4Mistake → ruleonce a week, move log entries into instructions, tests or hooks
- 5A progress file for long tasksa feature list with statuses and the commit history, so a new session picks up where the last one stopped Anthropic