Writing
Loop Engineering: The Feedback Loop Matters More Than the Code
AI has cut the cost of writing code. It hasn’t cut the cost of being wrong. That cost is set by how quickly and honestly we find out.
By Ka Lun Chan · Engineering leadership · AI / Delivery / Leadership
What is loop engineering?
Loop engineering is building software around short, repeatable feedback loops: understand the problem, plan, build, test, review, learn, and repeat. With AI coding agents, the engineer’s main job becomes designing the feedback the agent works against.
It isn’t an official methodology. There’s no manifesto or certification. I use the term as a practical name for something good teams already do, which matters more now that an agent can run the build and test steps dozens of times an hour.
- 01 UnderstandThe problem, in the user’s words, agreed with whoever asked for itPerson
- 02 PlanA small plan someone has read before any code existsPerson, agent drafts
- 03 BuildOne small change against the planAgent
- 04 TestTests written from the acceptance criteria, run by CIAgent and CI
- 05 ReviewA person reads the change and tries the behaviorPerson
- 06 LearnProduction errors, usage, support ticketsPerson, agent summarizes
Repeat: what Learn finds becomes the next Understand. A failed test goes back to Build; a failed review usually goes back to Plan.
Asking an agent to write code and accepting what comes back is one pass through the middle of that loop, with nothing at either end. Nobody checked the problem going in, and nobody checked the result coming out. Loop engineering puts both ends back and makes each step produce a signal you can act on.
The important part is the quality of that signal. An agent that iterates ten times against a weak test suite gets very good at passing weak tests. More iterations don’t make software better. Better feedback does.
We’ve been doing this for decades
Software engineering has always been more than writing code. It’s understanding a problem, making decisions, checking assumptions, delivering something that works and learning from what happens next. Most of our best practices are feedback loops of different lengths:
- Test-driven development: seconds to minutes. Does this function do what I said it would?
- Continuous integration: minutes. Does my change still work with everyone else’s?
- Code review: hours. Does another engineer understand it and agree with the approach?
- Agile iterations: a week or two. Did we build what the business needed?
- Monitoring and observability: continuous. Is it working for real users right now?
- Incident reviews: after something breaks. Why did our other loops miss it?
- Customer feedback: weeks to months. Did it solve the problem?
None of this is new. I made the same argument about design and requirements in forward engineering isn’t new. What’s changing is how fast the inner loops can run, and that puts new pressure on the outer ones.
How AI changes the loop
The traditional loop looks like this:
Engineer → write code → run tests → debug → review → deploy
With an agent like Claude Code or Codex, it looks more like this:
Engineer defines the outcome → AI plans → AI implements → automated validation → AI fixes → human reviews → deploy
The engineer has moved to both ends. More of the time goes into defining the outcome, the constraints and the checks up front, and into reviewing behavior at the end. The middle runs faster than any person could run it.
| Dimension | Traditional | Agentic |
|---|---|---|
| Who writes the code | The engineer | The agent, against a plan the engineer approved |
| Where engineers spend time | Implementing and debugging | Defining outcomes, constraints and checks, then reviewing |
| Cost of one iteration | Hours to days | Minutes |
| What limits speed | Typing and debugging | Review capacity and test quality |
| Main failure mode | Slow delivery, bugs found late | Fast delivery of the wrong thing |
| What a passing build proves | Roughly what the engineer meant to test | Only what the tests check, which the agent may have written |
The last row matters most. When the same agent writes the code and the tests, a green build tells you the two agree with each other. It doesn’t tell you either one matches what the customer needed. That’s why an agent shouldn’t be allowed to keep changing code without checks it can’t influence and a limit on how long it can keep trying.
Vibe coding, agentic engineering and loop engineering
I compared the first two in vibe coding vs. agentic engineering. Loop engineering is the third piece, and it isn’t a separate method so much as the part that makes the second one work.
| Approach | Primary focus | Main risk |
|---|---|---|
| Vibe coding | Generate working code quickly | Little understanding or validation of what was built |
| Agentic engineering | Delegate implementation tasks to AI agents | The wrong outcome, delivered by a run that succeeded |
| Loop engineering | Validate and improve the outcome on every pass | Poor feedback that reinforces a wrong assumption |
Agentic engineering asks who does the work. Loop engineering asks how we’ll know the work is right, at every step, and what happens when it isn’t.
When the feedback is wrong
A fast loop with bad feedback produces wrong answers faster. These are the failure modes I watch for:
- The agent fixes symptoms. A test fails, it adds a special case, the test passes, and the bug underneath stays.
- Tests pass but check the implementation, not the business requirement.
- The agent changes unrelated code to make its change fit.
- Each fix adds a layer, and the solution keeps getting more complicated.
- Acceptance criteria were vague, so the agent built a reasonable reading of them that nobody wanted.
- The agent grades its own work, with no independent check.
- An engineer sees green checks and merges without trying the feature.
Here’s a hypothetical that combines several of these. An agent builds appointment booking for a business with customers in more than one time zone. It stores every slot in UTC, and its tests confirm that a booking for 9:00 UTC is saved as 9:00 UTC. Every test passes. The review looks clean. But the booking page shows available slots in the server’s time zone, so a customer three hours away picks “9:00,” thinking it’s their morning, and arrives at the wrong time.
The code did what the tests said. The tests checked storage, and nobody had written down that customers must see slots in their own time zone. A successful execution loop doesn’t mean a successful engineering outcome. The fix starts with an acceptance criterion and a test written from the customer’s side of the screen.
Smaller loops, smaller changes
I prefer small user stories and small pull requests, and AI makes that preference stronger. The bigger the change, the longer the loop, and the more it costs to be wrong. Small changes give you:
- Feedback in minutes or hours instead of at the end of a sprint
- Reviews someone can read carefully
- Less risk per deployment
- Debugging where the cause is one of a few changed lines
- Rollback that undoes one thing
- A team that knows what changed
An agent can produce a 3,000-line pull request in the time it takes to get coffee. Nobody reviews 3,000 lines carefully, so that pull request has effectively skipped review. Continuous delivery depends on keeping each change small enough that the loop closes quickly. I wrote about the team side of this in smaller user stories and pull requests.
What humans still own
AI can help with every item on this list. Accountability for each one stays with the engineering team:
- Understanding the actual business problem
- Architecture decisions, including the ones to not build at all
- Security and compliance
- Acceptance criteria
- Weighing tradeoffs
- Production readiness
- Deciding when a solution is good enough
The last one is easy to miss. An agent will keep improving something as long as you let it. Someone has to decide that the change does what it needs to, at a cost that makes sense, and stop.
A practical loop engineering workflow
Here’s how I’d run a hypothetical feature, letting customers book appointments, with Claude Code or Codex.
- 01 Define the expected behaviorWhat a customer can do, written as acceptance criteriaHuman gate
- 02 List constraints and edge casesTime zones, double booking, cancellations, permissions. The agent can suggest moreHuman gate
- 03 Agent proposes a small planFiles it will touch, data changes, tests it will addAgent
- 04 Review the planApprove, narrow or reject before code existsHuman gate
- 05 Implement one pieceOne slice, inside the approved filesAgent loop
- 06 Run unit, integration and E2E testsIn CI, against tests the agent cannot editAgent loop
- 07 Analyze failures, propose fixesUp to three attempts per failure, then stop and reportAgent loop
- 08 Human acceptance testingSomeone books, moves and cancels a real appointment on a previewHuman gate
- 09 Deploy with monitoringBehind a flag, with alerts on booking errorsHuman gate
- 10 Evaluate production feedbackErrors, abandoned bookings, support ticketsHuman gate
Three failed attempts at step 7 send the work back to step 3 with a person.
The pattern is that people approve direction and agents iterate inside it. Steps 1 to 4 decide what we’re building and how. Steps 5 to 7 are where automated iteration pays off, because the agent is working against checks a person already agreed with. Steps 8 to 10 confirm it worked for a real user.
The guardrails I’d set before step 5:
- Iteration limits. Three attempts at the same failure, then stop and report what was tried. Repeated failure usually means the plan is wrong, and more attempts won’t fix a plan.
- Scoped changes. The plan names the files and directories the agent may change. Anything outside that is a new conversation.
- Independent checks. Tests come from the acceptance criteria and the agent can’t edit them without approval. CI runs them, not the agent’s own report.
- Escalation. When the agent hits a limit, touches authentication or payments, or wants to change a test, a person decides.
- Written instructions. Project rules in a CLAUDE.md or AGENTS.md file, so every session starts with the same constraints.
Review scales with risk. A copy change can lean on automated checks. Anything touching permissions, money or customer data gets a person, which I covered in code review doesn’t start with a pull request. Unlimited loops also cost real money in tokens and time, as I worked through in the hidden cost of AI coding.
What this means for engineering leaders
If AI cuts implementation time, the bottleneck moves somewhere else. On most teams it moves to:
- How clear the requirements are
- Architecture decisions
- Review capacity
- Test quality
- Deployment safety
- Coordination across teams
That changes what to invest in. A team that doubles its code output without improving its tests or adding review capacity has built a bigger queue in front of review.
It also changes what to measure. Lines of code, pull request counts and agent iterations were weak measures before AI, and they’re now trivial to inflate. I’d look at:
- Lead time to deliver useful functionality
- Change failure rate, how often a release causes a problem
- Time to recover when one does
- Escaped defects that customers find before we do
- Rework, changes that exist to fix recent changes
- Customer outcomes, whether the feature solved the problem it was built for
The first three come from DORA’s delivery metrics. All of them describe how well the loop works, which is why they’re harder to game than activity counts. More on how I run teams in how I run engineering.
My perspective
Over more than 20 years in software engineering, I’ve watched the tools change many times: languages, frameworks, infrastructure models, cloud platforms, and now AI coding agents.
The basic problem hasn’t changed. We still need to understand what we’re building, why we’re building it, and whether it works. AI makes each trip around the loop faster. Engineering judgment decides whether those trips are heading somewhere useful.
Short answers
What is loop engineering?
Loop engineering is a feedback-driven way to build software: understand the problem, plan, build a small change, test it, review it, learn from the result, and repeat. With AI coding agents, it means designing the checks an agent runs against, so each iteration is judged by evidence that the outcome is right. It is a practical framework, not a formal methodology.
What is the difference between loop engineering and agentic engineering?
Agentic engineering is delegating implementation work to AI agents inside a structured lifecycle. Loop engineering is the discipline of designing the feedback those agents work against: acceptance criteria, independent tests, review points, iteration limits and production signals. Loop engineering is what makes agentic engineering reliable.
Do more AI iterations produce better code?
No. An agent that keeps iterating against weak tests gets better at passing those tests, not at solving the problem. The quality of the feedback decides whether iterations move toward the right outcome, so improving the checks is usually worth more than adding attempts.
How do you stop an AI coding agent from looping forever?
Give it an iteration limit (for example, three attempts at the same failure), a defined set of files it may change, tests it is not allowed to edit, and a rule to stop and report when it hits the limit. Repeated failure usually means the plan or the requirement is wrong, which is a decision for a person.
How should engineering leaders measure productivity with AI agents?
Measure outcomes at the team level: lead time to useful functionality, change failure rate, time to recover from failures, escaped defects, rework and customer outcomes. Lines of code, pull request counts and agent iterations measure activity and are easy to inflate with AI.
Code got cheaper. Being wrong didn’t.
AI has reduced the cost of writing code. The cost of building the wrong thing is still there, and it shows up later and bigger when the feedback is weak.
The goal isn’t to generate more code. It’s to shorten the distance between an idea and a validated outcome.