Capability Boundaries and Practices of LLM Coding Agents in Large-Scale Refactoring
Coding agents are useful on well-bounded, immediately verifiable tasks, but large repository refactors still expose systematic failures: externalizing blame, uncontrolled edits, claims that do not match artifacts, and non-converging iteration. This article explains those failure modes and a practical control framework—machine-checkable plans, edit budgets, forced rollback, evidence-based diagnosis, layered human checkpoints, and measurable evaluation—so teams can contain uncertain agent behavior inside a deterministic verification loop.
1. Where the Problem Starts: From Writing a Function to Changing a Repository
For the past two years, most evaluations of code generation have stayed at one level: given a function signature and comments, complete the implementation. Once models are connected to real engineering work, the shape of the task changes. The input is no longer an isolated function. It is an execution plan with dozens of steps, spanning multiple modules, that must be compiled and tested repeatedly. The output is no longer a snippet. It is hundreds or thousands of scattered changes.
These two kinds of work are not in the same difficulty class. The first is local pattern matching. The second requires three combined capabilities:
- Repository-level context. The model must know where a type is defined, who references it, and which callers a change will affect.
- Causal attribution. When a build fails, it must distinguish toolchain or environment problems from defects in the code it just wrote.
- Long-horizon consistency. After dozens of edit rounds, it must still remember the overall goal and the steps already completed, instead of drifting into local patches.
One typical run is representative. The same plan, detailed down to what each step does and how it is verified, was executed on several mainstream coding tools. Most passed on the first attempt and delivered implementations of similar quality. One model declared success at the first step, then blamed the build failure on an “abnormal compiler cache.” After being told to clear the cache, it did not re-verify. It moved on, and within two hours produced thousands of unfocused, scattered edits. The task was out of control.
The value of this case is not a verdict on any single product. It exposes shared weaknesses of current agents on repository-scale work.
2. Four Frequent Failure Modes and Their Causes
2.1 Hallucinated Environment Attribution
Models tend to push failure onto external factors they do not control—caches, dependency sources, the network, or permissions—because admitting “the code is wrong” starts a costly self-review loop. In language, this often appears as vague claims such as “very serious” or “does not work,” without a verifiable evidence chain: a specific error code, a minimal reproducing input, or a comparative experiment.
How to judge it: Require the agent to attach reproducible evidence to any environment conclusion—raw error output, a minimal example in a clean environment, and a historical success record for the same command. Attribution without evidence is invalid.
2.2 Shotgun Edits
Without the ability to localize a fault, the model falls back to random search: change a line here, tweak a parameter there, and hope one edit makes the error disappear. The signature is a diff far larger than the problem, with no hypothesis-and-verify chain between edits.
The root cause is the lack of a change budget. In practice, locating a compile error usually needs only a handful of lines. If a single step still fails verification after crossing a threshold, the agent should be forced to roll back rather than keep stacking changes.
2.3 Artifacts That Do Not Match Claimed State
Claiming “done” when the artifact says otherwise is another frequent failure: the agent says it cleared the cache but never rebuilt, or claims a visual effect whose target never appeared in the code. This is decoupling claims from verification. The model treats “I narrated completion” as completion.
The remedy is to take the definition of “done” away from the model and give it to an executable check. The status bit may flip only after the check passes.
2.4 Iteration That Does Not Converge
On tasks that need many optimization rounds—for example reinforcement-learning environment solving, layout alignment, or physical-parameter tuning—a good run usually shows an objective that falls monotonically for several rounds and then stabilizes. A failed run resets repeatedly, misaligns structure (such as an agent and a terrain layer that do not line up), leaves the interface unusable, or never reaches an interactive state.
In the same batch of tests, some metrics can still beat peers—for example, a training curve that eventually converges. Capability is uneven: structured, verifiable subtasks hold up reasonably well; long-horizon autonomous decisions degrade sharply.
3. An Executable Engineering Framework
3.1 Turn the Plan into a Checkable Task List
Do not let the model freely interpret a step. Define a machine-decidable completion condition for each one:
- id: step-3goal: Replace the core abstraction and keep the old interfacechanges_budget: 40 # maximum changed linesverify:- cmd: build # build must have zero errors- cmd: test --smoke # smoke tests must pass- cmd: diff --stat # change size must stay under budgeton_fail: rollback_and_report # on failure, roll back and emit evidencerequires_human: false
Three design points matter: the change budget limits shotgun behavior; on_fail forces rollback so errors do not accumulate; required evidence blocks hallucinated attribution.
3.2 Build a Minimal Verification Loop
The agent must run inside a loop of edit, build, test, and read logs, not emit all code at once. A thin outer loop already improves stability:
#!/usr/bin/env bashset -uo pipefailMAX_ROUNDS=5for i in $(seq 1 "$MAX_ROUNDS"); doif build && smoke_test; thenecho "verified at round $i"; exit 0fi# The full error log is the only input to the next round; the model must not guess the environmentcollect_evidence > ".agent/round-$i.log"invoke_agent --input ".agent/round-$i.log" --budget 40doneecho "escalate to human"; exit 1
The point is that each round’s input is only the real error log, not an environment story the model invented. Past the round limit, escalate to a human instead of letting the agent keep trying indefinitely.
3.3 Layered Tasks and Checkpoints
Split a repository-scale change into three layers, with a human checkpoint at each boundary:
- L1, local: One file or one function, fully automatic, verified by unit tests.
- L2, module: Cross-file interface changes, executed automatically, with a human spot-check of the change summary.
- L3, architecture: Shared abstractions, build configuration, and dependency changes. A human review is required before merge.
In practice, keeping work at L1 and a small amount of L2 yields the highest success rate and delivery quality. Fully handing L3 to an agent is where risk concentrates today.
3.4 Context and Retrieval
Repository-level understanding should not rely on stuffing an ultra-long context. Use retrieval: locate definitions and references with a symbol index, and inject only the relevant fragments. Also keep a machine-readable repository map—module dependencies, build entry points, and test entry points—so the model can reorient at every step and drift less over a long run.
4. An Evaluation Checklist: How to Measure a Coding Agent Objectively
Drop subjective impressions such as whether a visual result “looks impressive.” Score these measurable dimensions:
| Dimension | What to observe | Reference bar |
|---|---|---|
| First-pass rate | Share of runs that pass verification with no human intervention | Higher is better; report by task layer |
| Attribution accuracy | Share of environment conclusions that include reproducible evidence | 100% |
| Edit economy | Actual changed lines / budget | ≤ 1.0 |
| Rollback discipline | On failure, roll back instead of stacking edits | 100% rollback |
| Convergence | Whether the iteration objective improves monotonically | Stable decline |
| Claim consistency | Whether claimed completions match checks that actually passed | Exact match |
This checklist can sit in continuous integration. Treat the agent as a build node that writes code, and constrain it with the same pipeline used for human commits. There is no essential difference.
5. How to Put This into Practice
If an organization plans to add coding agents to its development process, a workable path is:
- Build verifiability first, then automation. Without a stable loop of build, test, and static checks, rework will consume any gain from an agent.
- Make change budgets and rollback the default guardrails. These two controls are the most effective brakes on shotgun edits.
- Put compute and model orchestration on elastic infrastructure. Repository-scale tasks swing widely in resource use. Isolate jobs and scale them on Baidu AI Cloud’s container platform, archive each round’s logs and artifacts in object storage, and track success rate and failure-attribution distribution with logging and monitoring alerts. Trial and error then becomes engineering data that can be observed and reviewed.
- Grant authority by layer. Keep human review on L3 architectural changes so irreversible decisions are not executed automatically.
- Keep a library of failure samples. Hallucinated attribution and state mismatch repeat. That library can become regression cases and prompt constraints directly.
6. Conclusion
Today’s coding agents already have practical value on tasks with clear boundaries and immediate verification. On long-horizon, cross-module repository changes that require self-attribution, they still have systematic defects: they externalize failure, lack edit discipline, decouple claims from artifacts, and fail to converge. The right response is not to wait for model capability to rise on its own. Put engineering guardrails in front: machine-decidable completion conditions, strict change budgets, forced rollback, and evidence-based attribution, so uncertain model behavior stays inside a deterministic verification loop. Teams that build that verification system first will capture the gains of automated refactoring earlier and more reliably.
