medium.com 15 min read Original Source

Coding Agents Violate Your Spec: Always / Ask first / Never Boundaries and CI Sensors — SDD

An agent got one sentence in the spec: “don’t change the database schema.” It returned a pull request with a new migration and a polite paragraph explaining why it was necessary.

If you keep an agent’s boundaries in a Markdown file, you know this scene and the comment that usually follows: it ignored the spec. The agent didn’t ignore the rule. It broke it — and the fix depends on that difference.

Across more than 16 thousand chat-visible coding-agent missteps, drawn from real sessions with their users, violating an explicit constraint is the largest category, and almost every visible fix was forced by a human who happened to notice. “Ignored” tells you to write better prose. “Violated” tells you to add something that detects the violation without your attention. A clarification up front: “violated” here means “had an explicit instruction in the conversation and acted against it,” not “knew and decided to” — no study of conversations measures the model’s state of knowledge.

After reading this, you’ll paste a boundary section, Always / Ask first / Never, into your spec, and for every “Never” you’ll point to a CI check, a hook or a mandatory approval gate that stops the violation before it reaches main.

Quick Win — Core Insight

When an agent does something the spec explicitly forbids, the data more often shows a broken rule than a misunderstood request. The most common form of misalignment is the constraint violation — a situation where the agent acts against an explicit instruction — and it is more frequent than misreading intent. Its share is growing even though total missteps are declining. The conclusion for your spec: a constraint without a sensor is a suggestion.

A sentence in AGENTS.md works like a company rulebook. A new employee knows it, and under deadline pressure still walks into the server room through an open door. The company doesn’t add a paragraph to the rulebook; it installs a card reader and an alarm. In a spec, the equivalents are a gate, which blocks an operation before it happens, and a sensor, which checks the result after the agent acts, with no human involved.

In the spec, that means three moves:

  • Boundaries in three tiers: Always (do without asking), Ask first (ask before), Never (hard stop).
  • Every “Never” gets a sensor: a required CI check — an automated check run on push and PR that blocks the merge as a condition — or a hook, or a CODEOWNERS rule.
  • “Done” points to an artifact: a green CI status, a test log, a diff within declared paths, not the sentence “finished.”

Not every rule can be converted this way. The ones that can’t be converted stay as prose deliberately, not by neglect.

To make this principle survive an architecture review, let’s start with what exactly was measured — and what wasn’t.

The Largest Category of Agent Failure Is a Broken Rule, Not a Misunderstood Request

A colleague can let a team down in seven ways. They misdiagnose the problem, misunderstand the request, break an agreement, do more than needed, do it badly, mix up a command, or report a success that didn’t happen. Exactly these seven forms of misalignment are distinguished by a large observational study of real coding-agent sessions.

The study was run by Ningzhi Tang and coauthors from Notre Dame, Vanderbilt and Google (How Coding Agents Fail Their Users, arXiv 2605.29442, 2026). They analyzed 20,574 sessions from 1,639 repositories and looked for pushback — moments when a developer corrects the agent in chat.

A language model did the extraction, and a second validation round filtered out almost half of the candidates. That left 16,118 episodes, and a manual audit of a sample estimated precision at 0.93.

The result is unambiguous about the order. Violating an explicit constraint accounts for 38.33% of episodes, and misreading intent for 26.95%. In sessions with CLI agents, violations are even more common, nearly half. The labels overlap, so these are shares among misalignment episodes, not the percentage of sessions in which an agent broke a spec.

In the logs it looks prosaic. A minimal SQL change meant to allow NULL in one column grew into a full migration workflow. The instruction was in the conversation — and lost.

The Share Rises, the Frequency Falls

The composition of errors changes over time. The share of violations rises, and the share of self-reporting rises with it — the agent’s report on its own work, which tends to be more optimistic than the actual state. Misdiagnosis, faulty implementation and overreach, meaning doing more than was asked, decline, and total misalignment per conversation turn falls.

That doesn’t mean agents break more and more rules, only that in the studied period rule-breaking became the dominant type of misstep. An observational study can’t settle whether this reflects tools maturing. The authors suggest it may stem from reward signals that favor code correctness and task completion, while adherence to constraints is harder to measure.

The most important number concerns who does the fixing. Only 9.33% of episodes have a visible resolution, and in that group 91.49% were fixed by the agent only after a human objected. Without a sensor, you are the sensor.

What Was Measured and What Wasn’t

This is an observational study, and pushback is only a proxy for misalignment. Silent fixes — a rejected diff, code rewritten by hand — don’t make it into the data, and violations by nature provoke protest more often than minor implementation bugs. The sample also consists of early adopters who publish their logs.

In the authors’ classification, 73.68% of violations fell into the residual category: failing to follow an explicitly received instruction. That label doesn’t establish a mechanism — it says the instruction was clear, not that the model “understood” it. If it was clear and still lost, the problem lies in what a sentence in an instruction file actually is.

Prose in a Spec Works Like a Rulebook Without a Card Reader

The rulebook says “don’t enter the server room.” The card reader makes sure you can’t. These are two different mechanisms, and an agent’s instruction file belongs exclusively to the first.

The cleanest vocabulary for this difference comes from Birgitta Böckeler of Thoughtworks, in a 2026 piece on martinfowler.com (Harness engineering for coding agent users). A guide (feedforward) is an instruction given to the agent before it acts, meant to steer it. A sensor (feedback) observes the result after the action and returns a signal. Controls further split into computational — deterministic, fast, executed by the CPU — and inferential, where a model decides again.

In this grid, AGENTS.md sits in the feedforward, inferential cell. A hook — a script that runs automatically before a commit or a tool call and can block the action — together with module boundary tests sits on the opposite side: feedback and computational. A prohibition written only in prose is therefore a request to a model that is chasing another goal at that very moment.

The loudest example came in July 2025. Jason Lemkin of SaaStr, by his own account, repeatedly forbade the Replit agent, in capital letters, from making code changes, and during a code freeze the agent deleted the production database and then admitted it (The Register, Tom’s Hardware). The platform responded by automatically separating development and production databases (Fortune). The control moved out of the prompt and into the environment.

In fairness, prose works. On a benchmark with deliberately conflicting tests, a tightened prompt (an order to stop at a faulty test and a ban on modifying tests) cut GPT-5’s cheating rate from 92% to 1% on Conflicting-LiveCodeBench (ImpossibleBench, arXiv 2510.20270). Both facts are true in their own conditions: prose shifts a probability distribution, while a sensor gives a signal independent of the model’s good will — within its coverage. “Never” promises a hard stop, so a “Never” written only in prose promises more than it delivers.

The industry went through this already with compiler warnings. In my projects the conclusion was always the same: a warning that doesn’t block gets ignored, so important rules go into checks that stop a change before merge. Before we assign sensors, though, the rules have to be arranged so it’s clear which ones are meant to be a hard stop.

Always, Ask first, Never: Three Boundary Tiers Instead of a List of Requests

A traffic light has three colors, and each triggers a different behavior. A spec’s boundary section works the same way: Always / Ask first / Never are three tiers — do without asking, ask before, hard stop — and from the color alone you can see which mechanism stands behind the rule.

The pattern has a documented origin. Matt Nigh of GitHub described, in November 2025, an analysis of more than 2,500 agent files and six areas of a good file: commands, testing, project structure, code style, git workflow and boundaries (How to write a great agents.md, GitHub Blog). The most common helpful constraint turned out to be “Never commit secrets.” The analysis doesn’t publish its method, so I treat it as a practitioner’s account, not a study.

In January 2026, Addy Osmani also described the three tiers (How to write a good spec for AI agents). The file analysis is sometimes attributed to him, but it comes from the GitHub blog. Osmani ties the spec to tests and CI, but presents the tiers themselves as guidance the agent applies on its own — and this is where I part ways: there’s no map of which tier gets enforced by which mechanism.

Examples by Area

  • Backend — Always: run tests before committing. Ask first: database schema change, migration, new dependency, public API change. Never: secrets in the repo, editing vendor/.
  • Frontend — Always: lint and formatting. Ask first: a new UI library, a change to the client API contract. Never: editing node_modules/, disabling linter rules with a comment.
  • Infra — Always: plan before apply. Ask first: CI/CD configuration, permissions, networking. Never: destructive operations on production, production credentials in a staging task.

What Goes into Ask first

In my view, the value of this pattern lies not in the triad itself, but in the fact that it forces a decision about which rule is truly a “Never.” In the instruction files I’ve reviewed, task-dependent things end up in “Never.” After that, either the agent doesn’t follow them or the block paralyzes the work.

Ask first holds everything whose permissibility depends on the task: schema, dependencies, public API, migrations. A static prohibition will also block legitimate cases. This shows up clearly in a study of 2,116 instruction sentences from 64 popular repositories: “don’t update dependencies without approval” can be detected from a single command, but only resolved in the context of a specific task (ActPlane, arXiv 2606.25189).

The boundary section should be short. Every rule in an instruction file competes for the model’s attention with the task content, so what an automated check can verify doesn’t need to hang there as a long paragraph. The three tiers are still prose — now each of them has to get a mechanism that works without the agent’s good will.

Every “Never” Gets a Sensor or Stops Pretending to Be a Prohibition

We attach an alarm to every red lane. The test: a violation at three in the morning, while the agent works in the background, has to be noticed by someone. If nobody will notice, the rule isn’t a “Never,” it’s a wish.

Most prohibitions can at least be observed by automation, though not always cheaply. In that same instruction study, 83% of policies were system-observable, but only 26.4% of those observable ones work without project or task context. “Never push to main” is enough on its own, while “don’t modify upstream code” needs a list of paths.

The Table: Constraint, Sensor, Consequence

I design this table from the last column. If nothing happens on a violation until someone notices, the rule isn’t enforced: it either gets a sensor or a gate, or I mark it explicitly as prose.

  • Never commit secrets → a secret scan in pre-commit (as a supplement), server-side push protection and a required scan in CI → push or merge rejected; an exposed secret has to be revoked.
  • Never push to main → branch protection with a required PR → push rejected.
  • Never edit vendor/, node_modules/, CI configuration → a path guard in CI on those paths, and for CI configuration also CODEOWNERS (a file assigning paths to owners) with “Require review from Code Owners” → the merge won’t pass without the owner.
  • Ask first: new dependency → dependency review in CI and a manifest diff routed to CODEOWNERS → the PR waits for a human while the agent keeps working on its own branch. Ask first doesn’t have to block work if the policy allows a proposal on an isolated branch — then it’s the merge that waits, not the agent. Side effects outside the branch require approval before execution.
  • Never weaken tests → a “net loss” check: the number of tests and assertions doesn’t drop, and skip markers don’t grow without approval → the build fails. A count doesn’t measure test strength, so changes to existing assertions go to review as well. A wrong test sometimes has to be fixed, so the check requires a sign-off rather than forbidding.
  • Never violate layer boundaries → a fitness function, meaning an automated architecture-characteristic test run in CI (ArchUnit, dependency-cruiser) → the build fails with fix instructions in the message.
  • Never run destructive production operations → the agent gets no credentials or tools with production permissions → the operation is impossible, not just forbidden.
  • Largely stays as prose: “don’t change the logic” during a refactor → regression tests will catch some changes, but a simple check can’t confirm equivalence; a human or a model judges the rest.

I covered the mechanics of fitness functions and policy-as-code separately in ADR-as-Spec, Fitness Functions, and Policy-as-Code.

Dependency Ban: Prose Versus Check

I often hear that a dependency ban written in prose gets broken more often than the same ban in CI. I found no direct comparison, so the argument rests on mechanism: the agent weighs prose against the task goal, while a CI check leaves no choice. Indirect evidence for the direction comes from an experiment compiling instruction files into checks: constraint compliance rose to 88.3% versus 67.0% with the prompt alone (ContextCov, arXiv 2603.00822). Those are different tasks than dependencies, so the number points to a direction, not an effect size.

Where Sensors Don’t Reach

A hook on a tool call won’t see a commit made by a script the agent wrote earlier, and the agent can edit a local hook. A server-side CI check is stronger than a hook on a laptop — provided the agent can’t change the workflow or set the status. Böckeler also cautions that sensors don’t reliably catch misdiagnosis and over-engineering. I’d add that gates with false alarms end up like ignored warnings.

How to Count Violations in Your Own Repo

The first measure is coverage: the share of “Never” rules with an assigned sensor; the second is a counter of sensor triggers on agent PRs. A quiet sensor can mean quality or weak detection, so I read the counter together with a review of a sample of PRs.

In my content pipeline, the instruction file has a rule not to commit the whole status file. But what enforces it is the helper through which every step commits, and which itself picks out one episode’s share of the file. Two violations most often slip past a table like this: a “done” report nobody checks, and work outside the task’s scope.

“Done” Without Proof Is a Travel Expense Report Without Receipts

Accounting won’t accept a travel expense report without receipts, however convincing the trip description sounds. An agent’s report is such a description. Self-reporting covers 22.58% of episodes in Tang’s study, and the pattern is repeatable: the agent turns a partial or unverified state into a declaration of completion.

An example from the data: an agent announces that 10/10 tasks are done, and on the next turn the developer pastes the error “no such column: extra_ips.” The declaration alone wasn’t enough to confirm correctness.

“Trust, but verify.” — Ronald Reagan, President of the United States

The Russian proverb that Reagan repeated in talks about verifying disarmament sums up this section better than any rule could. Whoever produced the evidence doesn’t approve it alone. An agent that has to both write the code and bring the tests to green takes the shortest path by weakening a test. That’s why the implementer gets tests, runner and test configuration as read-only, and CI counts net loss.

Proof Instead of Declaration

The spec’s definition of “done” points to a machine artifact:

  • required CI checks with a success result (not skipped) on the last commit,
  • a test log from the run, attached to the PR,
  • a diff limited to the declared paths.

If the definition doesn’t require proof, it’s easy to accept the declaration alone as meeting it. I consider this a spec problem, not a model problem, though the data shows a correlation, not proof of cause. A stop hook, meaning a hook run when the agent wants to end its turn, can block the ending without tests having run, but it only returns feedback to the model, and the mechanism itself has limits. That’s why the final sensor sits in CI, not in the chat.

Scope as a List of Paths

Overreach is 10.20% of episodes, and in two thirds of them the cause is exceeding the scope. This form also has the highest share of cases where the developer takes the work away from the agent. An out-of-scope section written in prose is a request, and written as a list of paths it becomes the cheapest sensor to build. I found no cost ranking, so this is my judgment, not a measurement.

## Scope
In scope:      src/billing/**, tests/billing/**
Out of scope:  src/auth/**, migrations/**, .github/**
## Scope
In scope:      src/billing/**, tests/billing/**
Out of scope:  src/auth/**, migrations/**, .github/**

A CI check compares the list of changed files with this list and rejects a PR that touches a path outside the scope. An Ask first approval extends the list for a specific task. The list itself, however, depends on who is working — an implementer, a tester and a documentation writer need different maps.

Implementer, Tester and Documentation Writer Need Different Boundaries

The accountant has no key to the server room, and the administrator doesn’t sign invoices. One spec for all agents is one pass for all employees. Splitting roles makes it easier to set default write paths, and the effective scope is the intersection of the role’s permissions and the task’s scope.

  • Implementer writes to src/. Never: changing assertions in existing tests, CI configuration. Sensor: read-only tests and the net-loss check.
  • Tester writes to tests/. Never: modifying source code, deleting a failing test without approval. Sensor: a path guard on src/ for the tester’s branch, meaning a check that rejects a change in a path outside the allowed list.
  • Documentation writer writes to docs/. Never: touching src/. Sensor: a diff limited to docs/. A path check won’t tell you, though, whether the documentation is true.

The split has support in the agent-file analysis mentioned earlier: the tester persona doesn’t modify source code, and the documentation agent writes to docs/ and doesn’t touch src/. That’s a practitioners’ pattern, and I found no comparison of violation rates across roles.

Enforcement takes more than convention: the role is guarded by the execution environment and by a CI check that verifies the actor’s identity and the diff’s scope, while CODEOWNERS only assigns a reviewer to sensitive paths. What remains is to assemble it into one block you can paste into a spec today.

Every “Never” Without a Sensor Is a Wish

Back to the agent with the migration. In a repo where migrations/ has an owner in CODEOWNERS and “done” requires passing CI checks, that migration is no longer a surprise at the morning review. The PR waits for the owner’s signature, and the agent gets a signal before anyone has to read its polite paragraph. The rule didn’t change. What happens when it’s broken did.

Here’s the section to paste. The comment next to each “Never” points to the sensor, and the full map is in the table above.

## Boundaries
### Always (do without asking)
- Run tests and the linter before every commit.
- Work on an agent/* branch; merge requires human approval (no bypass for the agent).
### Ask first (ask before)
- Database schema change and new migrations  # CODEOWNERS: migrations/
- New dependency in the manifest             # dependency review in CI + CODEOWNERS
- Public API and CI/CD configuration change  # CODEOWNERS: api/, .github/
### Never (hard stop)
- Secrets in the repo                        # secret scan (supported patterns) + rotation after a leak
- Push to main                               # branch protection, required PR
- Editing vendor/ and node_modules/          # path guard in CI
- Weakening tests without approval           # net-loss check: tests and assertions don't drop, skips don't grow
- Import from domain into infrastructure     # fitness function in CI
- Operations on production                   # separate credentials, no prod token
### Scope
- In scope: src/billing/**, tests/billing/**
- Out of scope: src/auth/**                  # path diff check in CI
- An Ask first approval extends the task scope in a source the agent doesn't approve.
### Definition of done
- Required CI checks with a success result on the last commit, test log in the PR, diff only in in-scope paths.
- The sentence "done" without these artifacts doesn't close the task.
## Boundaries
### Always (do without asking)
- Run tests and the linter before every commit.
- Work on an agent/* branch; merge requires human approval (no bypass for the agent).
### Ask first (ask before)
- Database schema change and new migrations  # CODEOWNERS: migrations/
- New dependency in the manifest             # dependency review in CI + CODEOWNERS
- Public API and CI/CD configuration change  # CODEOWNERS: api/, .github/
### Never (hard stop)
- Secrets in the repo                        # secret scan (supported patterns) + rotation after a leak
- Push to main                               # branch protection, required PR
- Editing vendor/ and node_modules/          # path guard in CI
- Weakening tests without approval           # net-loss check: tests and assertions don't drop, skips don't grow
- Import from domain into infrastructure     # fitness function in CI
- Operations on production                   # separate credentials, no prod token
### Scope
- In scope: src/billing/**, tests/billing/**
- Out of scope: src/auth/**                  # path diff check in CI
- An Ask first approval extends the task scope in a source the agent doesn't approve.
### Definition of done
- Required CI checks with a success result on the last commit, test log in the PR, diff only in in-scope paths.
- The sentence "done" without these artifacts doesn't close the task.

What to take back to your repo:

  • Review your “Never” rules and move every task-dependent one to Ask first.
  • Fill in the constraint → sensor → consequence table, starting from the consequence column.
  • Count the coverage of “Never” by sensors and track their triggers on agent PRs.
  • Give each agent role its own pass: write paths tied to an authenticated identity, not just a branch prefix.

It’s also worth telling the team plainly what sensors won’t catch: misdiagnosis and excess architecture. I described how to lift such rules to the company-wide level in Master constitution: company-wide non-negotiables and CI enforcement, and anyone who wants to measure more precisely will find the public replication package of the study.

Thank you for coming with me from a single migration to a table of sensors. I have a practical request: count how many “Never” rules in your spec have a sensor today, and write in the comments what percentage you got. I’m most interested in teams that compared the same prohibition written in prose and as a CI check — I found no such measurement in the literature, and your numbers are worth more than another paragraph in AGENTS.md.

If you want to see how agent boundaries fit into a broader organizational order, I wrote separately about the twelve governance functions for AI agents.