A spec without a harness is a document nobody enforces
Two terms keep getting mixed up in AI coding: spec-driven development and harness engineering. They answer different questions. A spec decides what one change must do before the agent starts. A harness is everything arou
Two terms keep getting mixed up in AI coding: spec-driven development and harness engineering. They answer different questions. A spec decides what one change must do before the agent starts. A harness is everything around the agent except the model: what it reads, what it may touch, which checks run on its output, and what happens when one fails.
Teams that let agents write real code end up needing both, and each one fails in a predictable way without the other.
Where the term came from
Birgitta BΓΆckeler's article on martinfowler.com defines a harness as "everything in an AI agent except the model itself". The term took off in February 2026, when OpenAI's Ryan Lopopolo described a five-month experiment in which a small team shipped an internal product with zero manually written lines: about a million lines and roughly 1,500 merged pull requests. The engineers' job, in the post's words, became "to design environments, specify intent, and build feedback loops that allow Codex agents to do reliable work."
Two ideas from that post matter most here:
- The repository is the system of record. "From the agent's point of view, anything it can't access in-context while running effectively doesn't exist." A decision made in Slack is invisible to the agent until someone writes it into the repo.
- Invariants are enforced mechanically. Custom linters and structural tests check the rules, and the lint messages are written as fix instructions for the agent.
Spec and harness, side by side
| Spec-driven development | Harness engineering | |
|---|---|---|
| Question it answers | What must this change do? | How do we make any change trustworthy? |
| Scope | One change or feature | The whole repository, for its whole life |
| Main artifacts |
spec.md, tasks.md, acceptance criteria |
AGENTS.md, linters, structural tests, test harness, CI |
| Changes when | Every new feature | The same failure happens twice |
| Failure if missing | People argue about intended behaviour in code review | People agree on the behaviour but cannot prove it cheaply |
BΓΆckeler splits a harness into guides, which steer the agent before it acts, and sensors, which observe after it acts so it can correct itself. A functional spec is on her list as a guide. It is the only guide that changes with every feature, which makes it the most important one for behaviour.
Make every spec section produce a check
When you write a section of the spec, decide which harness control it feeds:
| Spec section | Harness control |
|---|---|
| Context, goal, non-goals | Linked from AGENTS.md so the agent reads it first |
| Allowed files | CI fails if the diff touches anything else |
| Acceptance criteria AC-1β¦n | Each has a test that names it; CI fails if one is missing |
| Edge cases | Fixtures and factory states that reproduce them |
| API contract | Contract tests generated from the OpenAPI document |
| Rollback | A feature flag exists and defaults off |
The two rows that catch the most agent mistakes, allowed files and acceptance criteria, fit in one short script. It reads the spec, fails when the diff leaves the allowed list, and fails when a criterion has no test that mentions it. We ran it against a sample repository on bash 3.2, the version macOS ships:
#!/usr/bin/env bash
# Usage: scripts/spec-gate.sh <change-name> [base-ref]
# Fails if the diff leaves the spec's allowed files, or an AC has no test.
set -euo pipefail
spec="specs/active/$1/spec.md"
base="${2:-origin/main}"
status=0
allowed=$(sed -n '/^## Allowed files/,/^## /p' "$spec" | sed -n 's/^- //p')
while read -r file; do
grep -qxF "$file" <<<"$allowed" || { echo "out of scope: $file"; status=1; }
done < <(git diff --name-only "$base"...HEAD)
for ac in $(grep -o 'AC-[0-9]\+' "$spec" | sort -u); do
grep -rqw -- "$ac" tests/ || { echo "no test mentions $ac"; status=1; }
done
exit "$status"
It expects the spec to carry an ## Allowed files list of exact paths and criteria numbered AC-1, AC-2, and so on. The -w flag matters: without it, a test named after AC-10 would satisfy AC-1. As a pull request check, with the branch name used as the change folder:
name: spec-gate
on: pull_request
jobs:
gate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: scripts/spec-gate.sh "$GITHUB_HEAD_REF" "origin/$GITHUB_BASE_REF"
It does not prove the tests are good. It proves the agent stayed inside the boundary and did not skip a criterion.
One change, with and without the harness
Take "retry refunds when the payment gateway times out". The spec is short:
## Acceptance
- AC-1: a gateway timeout retries once with the same idempotency key
- AC-2: a second timeout leaves the refund pending, no duplicate refund_id
- AC-3: every attempt writes an audit event
## Allowed files
- src/billing/refund-worker.ts
- tests/refund-worker.test.ts
- specs/active/refund-retry/evidence.md
This is the kind of failure the harness is for. The agent writes a plausible retry loop and a test that mocks the gateway to succeed on the second call. The test passes, AC-2 is never exercised, and the agent adds a helper to src/billing/ledger.ts because it seemed tidy. Without a harness, review catches some of that, late.
With a harness, the same run hits three sensors before a human looks. The scope gate flags ledger.ts. The AC check reports that no test mentions AC-2. And the gateway mock is part of the test harness rather than something each test improvises, so it already has a "times out twice" state and the missing test costs the agent one line.
How each fails without the other
A spec without a harness is a document nobody enforces. The agent mostly follows it and drifts at the edges: an extra field, a refactor outside scope, a criterion quietly dropped. Each of those is found in human review, the most expensive place to find it and the one that scales worst as agents open more pull requests. A note in OpenSpec's community schema catalog says it plainly: "OpenSpec only checks that artifacts exist."
A harness without a spec is a fast, green pipeline pointed at the wrong target. Lint passes, the tests are thorough, and the feature does something nobody asked for. Anthropic's March 2026 post on harness design found a related trap: "When asked to evaluate work they've produced, agents tend to respond by confidently praising the work." Its fix was a separate evaluator grading against criteria agreed before coding started, which is a spec by another name.
A one-week starter
For a team that already writes specs, in order of return:
- Make
AGENTS.mda short map to where specs, architecture notes and commands live. - Give every spec numbered criteria and an allowed-files list.
- Add the spec gate above to CI.
- Build one real test-harness layer: fixtures, a mock server, or a one-command environment bootstrap, whichever your agents stumble on most.
- Add an evidence section to the PR template: test names per criterion, logs.
- When the same agent mistake shows up twice, add a guide (a line in
AGENTS.md) or a sensor (a lint or a test).
The full article covers the prompt, context, harness and loop layers, the test-harness layers in more detail, and links to every source quoted here: Harness engineering vs spec-driven development.
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.