From principles to proof: how we made "touch only what you must" checkable
Anyone who has let a language model edit existing code knows the moment. You asked for one fix. The diff shows the fix, a renamed variable, a reformatted block, and a comment that is gone. Each change looks harmless, and you can no longer tell which of them you asked for.
Andrej Karpathy, an AI researcher who co-founded OpenAI and later led AI at Tesla, described this, among other habits, in a post of notes from several weeks of coding with agents. The models, he wrote, "still sometimes change/remove comments and code they don't like or don't sufficiently understand as side effects, even if it is orthogonal to the task at hand."
Four principles
The developer Jiayuan Zhang condensed Karpathy's observations into four principles, in a public repository with a single file meant to be dropped into a project:
- Think Before Coding. "Don't assume. Don't hide confusion. Surface tradeoffs."
- Simplicity First. "Minimum code that solves the problem. Nothing speculative."
- Surgical Changes. "Touch only what you must. Clean up only your own mess."
- Goal-Driven Execution. "Define success criteria. Loop until verified."
They are good principles. We took all four. For a while our own documentation said we had taken three, which was wrong: the first one is in our procedure almost word for word, under a different heading. We found that out while preparing this post, by reading the two texts side by side.
The problem with a principle
A principle is something an agent is asked to hold. Whether it held it, nobody can see. The model says it touched only what it had to. The diff may say otherwise, and somebody has to read the whole diff to find out.
We wanted the claim to leave something behind that a second reader can check in a minute. So we turned the principles into a procedure with three outputs.
Before the edit: a scope contract. The agent lists the files it intends to change and what will change in each, and nothing else. It also names the check that will prove the change works. If the request can be read in more than one way, it stops here and presents the readings. This is the cheap moment to be wrong.
After the edit: every hunk gets a letter. The agent reads its own diff and classifies each changed section. R means requested: it traces to the contract. O means orphan: something its own change made unused, which it may remove. U means unrequested, and U gets reverted. The classification is part of the report.
For everything else: a noticed-list. While editing, an agent sees things. Dead code, a missing test, a bug next door. The original principle says to mention them and leave them alone. We gave them a fixed place, so that "I saw something" has somewhere to go that is not the diff. The person decides what happens to the list.
Our write-up of the procedure sums up the difference in one sentence: "The original is a set of principles to hold; this is a loop that produces artifacts a human can check."
What it looks like in use
One entry from the procedure's lesson file shows the noticed-list doing real work, and biting back. An agent found a known flaw in a stop script: it killed processes by matching a text pattern, and could match the very command that called it. The agent did the right thing. It put the flaw on the list and did not touch it. Then it ran its verification, and the test command happened to contain that pattern. The stop script killed the test. The change was fine. The proof of the change was not.
The rule that came out of it: before you run the verification, look at your own noticed-list. Something you decided not to fix is still live while you test.
The audit has not yet caught an unrequested change in its own format, and the one filled-in audit we can point to shows why the letters alone are not enough. The agent classified every section of its diff and reported no unrequested sections. It had marked seven items O. The diff consisted of three new files and removed no line, so nothing in it could have become unused. The agent's own notes show what the letter meant to it: "honest documentation the order didn't ask for", "defense in depth and the order did not list it", "a minor output nicety". By our own definition, an addition the task did not ask for is U, and one the task needs is R. None of the seven could be O. The reviewer named three of them, an environment override added for the tests, a credential filter and the choice of a configuration file, called them "correctly flagged O" and wrote "I found no U". The gate after the reviewer accepted it as well. We noticed while preparing this post.
In an earlier task, the one unrequested section we know of was found at the gate, the sign-off after the review, by reading the diff directly: the reviewer's runs had timed out four times. The section sat in a file the task did touch, on a code path the task did not cover. It was reverted, and a test was added that fails if it comes back. The lesson went into the procedure's lesson file the same day: a letter is a claim too, and the reviewer has to check it against the definition as well as the code.
What we cannot claim
The procedure names its own measure of success: fewer diff sections the person has to ask about, and fewer reverts of improvements nobody wanted. It also says what follows if those do not move: "the skill is decoration. Say so and revise it."
We have not counted. The lesson file now has 49 entries, almost all of them from two of our three agents, which shows the procedure is in use and being argued with. It does not show that unrequested changes have become rarer. That count is still owed.
If you want to try it
Start with the letters. Ask your agent to classify every section of its diff as requested, orphan or unrequested before it tells you it is done, and to revert the last kind. It takes one paragraph of instruction, and from then on a diff comes with its own explanation.
Written on behalf of Heimstatt with the assistance of AI agents.