Compound Engineering With Codex: Keeping Agents Honest
How I keep AI-assisted engineering from becoming a pile of plausible diffs: committed instructions, bounded specs, tests, reviews, and records left behind.
A one-line instruction can hide three weeks of assumptions. I've watched a coding agent turn a harmless-sounding request into clean changes across models, controllers, views, and tests that compiled and passed, while silently inventing an ownership rule nobody on the team had approved.
Agents write code fast, yet the real work is leaving the repository easier to understand for the next change. Engineering compounds when a decision, a test, or a database constraint from today's task makes tomorrow's run safer and cheaper to review.
The repository has to remember what I will forget
Work starts before the prompt by committing operating instructions next to the code. In one iPhone repository, AGENTS.md states that the data model lives in Swift code and never in an .xcdatamodeld file, so diffs stay readable and an agent can edit the schema directly. That single rule carries real consequences: schema changes stay additive, shipped fields are never renamed or retyped, and nobody introduces a second model format out of habit.
In the same app, every Core Data save or delete goes through saveSurfacingErrors() with a visible alert, never try? context.save(). When someone logs a medical observation, dismisses a sheet, and sees a success state, a swallowed save error loses user data quietly; putting that rule and its reason in the repository stops an agent from reverting to the default pattern.
Another project uses AGENTS.md purely as a router: load the product, design, and architecture notes before changing runtime behaviour, load the safety document for trust, privacy, billing, authentication, or user-generated content, and keep backend and mobile architecture separate. Telling an agent to read twenty documents guarantees it will ignore half of them, so I keep AGENTS.md short and put domain rules beside the code they govern. Committed instructions are production material too, and I've seen an agent follow a stale guide into a bug because nobody deleted the old boundary note after an architecture change.
Write the change boundary before the diff
For anything larger than a contained fix, I write a short spec under openspec/ before touching code. A useful boundary states what will be true when the change lands, what must stay unchanged, which files are in scope, what is excluded, and how we'll verify it. Asking an agent to "add this feature" invites it to invent product policy.
On an education platform I work on, educators deliver sequenced course material, volunteers accept opportunities, administrators moderate student work, and educator identity stays strictly separated from anonymous student feedback. A small request can touch completion state, roles, signed public links, reporting, and a questionnaire engine, so "wire up feedback" lets the agent grab whichever responsibility it meets first. With a written spec in place, any mismatch between code and plan forces a clear question: did the plan go stale, did the implementation miss a condition, or did the requirement shift?
I don't write specs for typos, whereas authentication, money, background jobs, destructive actions, and data shape always get a written boundary. I also reject opportunistic framework migrations, redesigns, or premature abstractions when an agent gets bothered by three similar lines, because a tidy-looking diff is still harder to review and roll back.
Tests make the behaviour checkable
Generated code reads confidently, which makes runnable contracts essential. I write tests that name the required behaviour at the layer where the risk lives: request tests for authorisation boundaries, model tests for invariants, or system tests when a bug sits between a Turbo response and a Stimulus controller.
On the education platform, unique database indexes enforce one active delivery per user and course, one completion per delivery, step, and user, one volunteer match per request and volunteer, and one rating per entry. A framework validation fails when two requests race, so the database has to reject the duplicate state and a test has to prove the UI surfaces that rejection cleanly.
The property operations platform taught the same lesson through its bulk importer, which pages source records, stores raw snapshots, projects canonical rows, retries failures, and resumes from a persisted cursor. The cursor advances only after the root record finishes importing, and older imported snapshots can never overwrite a newer webhook update. During the historical migration, our strongest contract lived outside the unit suite: a read-only integrity check built a per-property manifest and refused to mark the source safe to delete while a backfill remained incomplete, catching cover images and meter photographs that lacked a UUID. I ask agents to update tests only when product behaviour changes, never to duplicate a flawed assumption across two files; the longer version of that discipline is in tests as contracts for AI agents.
More output moves the bottleneck into review
Agents don't deliver a fixed speed multiple, because the real bottleneck shifts straight into code review. An agent can draft a migration, a background job, a controller, and tests in one pass, yet I still read every query, transaction boundary, index, ownership check, error path, and retry rule. Unreviewed generated code looks right on the surface while hiding policy in the wrong layer, swallowing errors, or leaving a background job non-idempotent.
I review in a fixed order:
- Reread the request and the spec boundary.
- Inspect changed surfaces first: routes, schema, permissions, external writes, job enqueues, and APIs.
- Check the tests for plausible failure modes they still miss.
- Read the local implementation last.
Small tasks keep diffs small enough to hold in my head, and whenever a review comment repeats across tasks, I push it into the repository: invariants become tests or database constraints, routing rules go into architecture notes, and recurring procedures move into the agent guide.
Memory has to be specific enough to be useful
Agent-memory directories, task notes, and archived handoffs help me locate integrations and see what was already tried, yet memory goes stale fast. I treat the running code and tests as first truth, followed by database constraints, current architecture notes, agent memory, and finally old prompts. When those disagree, I resolve the conflict before writing a line of code, and I write memory entries with concrete boundaries: "the public student survey uses a purpose-bound signed token with an expiry; don't replace it with a session requirement" gives the next engineer or agent something actionable, whereas a vague summary does not.
Start with a narrow behaviour, load the authoritative repo instructions, put non-trivial changes in a bounded spec, run the matching tests, and inspect every policy choice hiding in the diff. If you're evaluating whether an AI-heavy codebase is safe to buy or inherit, the technical due diligence checklist walks through how to verify it.