The last mile problem for AI coding agents
Coding agents optimise for finishing the task, not your scope, so drift builds up. Write scope as a contract, turn criteria into tests and verify continuously.
Coding agents optimise for finishing the task, not your scope, so drift builds up. Write scope as a contract, turn criteria into tests and verify continuously.
Test AI like software: real cases, code checks for what must hold, a calibrated LLM judge for the rest, human audits, and a release gate on every change.
A chatbot answers; an agent plans steps and uses tools to do the work. Start read-only, add approvals for irreversible actions, enforce the user's permissions.
A recurring report. A slow review. A prototype that needs to work in the real world.
AI coding agents struggle to ship software because they optimise for finishing the task in front of them rather than matching the scope you intended. Each individual decision looks reasonable enough, yet small deviations compound across a codebase (a gap we call agent drift) until checking whether the code is actually what you wanted becomes the bottleneck.
We see the same pattern across teams using Claude Code, Codex, Cursor and GitHub Copilot: code arrives in minutes, pull requests swell, reviews turn into archaeology and delivery barely speeds up. The fix is to treat scope as a contract the agent works to, and check its work against that contract continuously instead of waiting for review.
Key takeaways
Because software delivery was never bottlenecked on typing. The hard parts are choosing the right behaviour, integrating it safely, keeping it maintainable and proving it does what people expect. Agents are very good at writing code, and increasingly good at running tests and fixing their own errors. What they can't know is what your organisation considers in scope, which trade-offs it has already accepted, and which "improvements" it would rather leave alone.
So effort shifts out of writing and straight into verification. If you don't change how you control scope, you end up with more code and less confidence. A 2,000-line change produced in twenty minutes can take a reviewer longer to untangle than it would've taken to write the 300 lines that were actually needed.
Drift isn't a moral failing of the model or sloppy prompting. It's the predictable result of autonomy without constraints, driven by three forces.
Agents are useful because they make decisions: which files to touch, which abstraction to introduce, whether to bump a dependency, how to test. Each choice makes sense in isolation. By the time a person reviews, the code reflects an architecture nobody agreed to. The longer an agent runs unsupervised, the more decisions compound.
Code review matters, but it's a late-stage check. Reviewers see a diff; they rarely see the chain of intent behind it (what the requirement was, what was ruled out, which trade-offs were accepted and what proves the behaviour is right). On a large agent-written change, review turns into forensics.
Drift shows up as rework: clarifying scope after the code already exists, unwinding over-engineering, retrofitting tests and patching edge cases under deadline pressure. Every hour saved in generation gets spent again in verification, usually by your most senior engineers.
Make scope the source of truth, and write it in a form a machine can check against. Scope documents aren't new; what's new is treating them as a contract the agent is held to, with a person approving any deviation deliberately.
This has become a mainstream pattern. GitHub released Spec Kit, an open-source toolkit for "spec-driven development", in September 2025, and AWS's Kiro editor (built around writing requirements and a design before code) reached general availability in November 2025. Both make the same bet: write the specification first, let the agent build to it, and verify the result against it. You can adopt the discipline without committing to any particular tool.
| Option | When to use | Trade-offs |
|---|---|---|
| Scope gap | The requirement is unclear, under-specified or missing acceptance criteria | If you build anyway, you ship the wrong thing faster and pay for rework later |
| Code gap | The scope is clear, but the code or tests don't satisfy it yet | If you can't map evidence to scope, you can't merge or release with confidence |
The shift in workflow is simple to state. The old loop was: write a ticket, hand it to the agent, review whatever comes back. The new one is: write a scope contract, let the agent work within it, check alignment continuously, and have a person approve any deviation.
Short, explicit and testable. Here's a worked example for a small feature, written in plain Markdown sitting right in the repository next to the code:
# Export cases to CSV ## In scope- A "Download CSV" button on the case list for users with the case:read permission.- Columns: case reference, status, opened date, assigned officer.- Respects the filters currently applied to the list. ## Out of scope- Other formats (Excel, PDF).- Changes to the case list's layout or filters.- Any refactor of the existing table component. ## Acceptance criteria1. With no filters, the file contains every case the user can see, and no others.2. With a status filter, the file contains only cases with that status.3. Dates are ISO 8601 (YYYY-MM-DD).4. A user without case:read sees no button and gets 403 from the endpoint. ## Terms- "Assigned officer" means the current assignee, not the creator.The out-of-scope list does the heaviest lifting. Without it, an agent will happily fill the space with extras: a tidy-up of the table component it touched, a second export format, a new utility module. Each acceptance criterion should turn into a test before the feature is called done, and the agent can write those tests first.
Split the discipline into two phases. You can run both with a Markdown template and a few checks before buying any tooling.
Phase 1: write scope as a contract
Phase 2: close the gaps, with evidence
A second model can help with phase 2. Hand a reviewing agent the scope contract and the diff, and ask it to list every change that no criterion requires. It won't catch everything, but it turns "read 2,000 lines" into "judge a dozen flagged deviations", and it's cheap to run on every commit. Use its list to focus a human reviewer rather than treating it as a final verdict.
Keep the human alignment layer separate from execution. People write and approve scope on their own machines; the agent runs in an isolated environment with a fresh checkout, short-lived credentials and no access to production secrets, with every action logged. Hosted coding agents work this way by default, and you can build the same shape yourself.
Put a scope file in the repository for every non-trivial change, with an out-of-scope list and numbered acceptance criteria. Have the agent turn those criteria into tests first, then implement. Run it in an isolated environment, keep diffs small, and add an automated deviation check against the scope file on every commit. Review the scope as closely as you review the code; it's now the cheaper place to catch mistakes.
Then measure whether it's actually helping: rework, review time and lead time, before and after. The same discipline applies to the AI features you ship, not just the code you write with AI; see how to evaluate AI systems.
We help engineering teams tighten the loop from scope contract to verified pull request: keeping speed gains without letting agent output overwhelm code review. How we run AI-assisted delivery →