LLM Code Evaluation: Why Complex Refactors Keep Failing
This article examines why strong code generation does not guarantee success on multi-step, cross-module refactoring tasks. It outlines three common failure modes—hallucinated root causes, shotgun-style edits, and skipped verification—and a separate set of issues seen in visualization and frontend tasks. It then proposes a reusable evaluation design with fixed variables and four metrics, plus four engineering guardrails: verification first, change budgets, falsifiable assumptions, and small reversible commits. The goal is predictable delivery in long-chain tasks, not impressive demos.
1. Why “Can Write Code” Is Not “Can Modify a Project”
In real software delivery, asking a model to generate a standalone function is no longer the hard part. The real challenge is performing structural, cross-module, multi-step changes on an existing codebase. Such tasks have three characteristics: a wide context span, verification that depends heavily on the toolchain, and correctness that accumulates with every step.
The original case is representative. A fairly large system-level language project required a change spanning six major steps. The execution plan was already detailed down to what each step should do and how to verify it. Yet within a very short time the model claimed two steps were complete, then attributed a compilation failure to a nonexistent “compiler cache problem.” After being corrected, it fell into random trial and error, modified thousands of locations without passing verification, and the task was eventually aborted.
This shows that the evaluation dimension for code generation is shifting from single-point correctness to long-chain convergence. The latter is exactly where engineering practice breaks down most often.
2. Three Typical Failure Modes
2.1 Hallucinated Attribution
Models tend to offer an external explanation for failure that sounds plausible but does not hold up technically, such as cache corruption, environment anomalies, or unavailable dependencies. The danger is that such attribution terminates the real investigation and leads developers into meaningless branches. The test is simple: any attribution must be falsifiable or confirmable by a single executable verification command. Explanations that cannot be verified should be treated as noise.
2.2 Shotgun-Style Modification
Without localization ability, the model degrades into random edits in many places: a line changed here, a block deleted there, hoping one of them happens to hit the problem. The result is a rapidly growing changeset, out-of-control review cost, and the real issue buried in unrelated diffs. The engineering stop-loss line should be explicit: when the changed lines of a single task exceed several times the planned estimate, abort immediately and roll back.
2.3 Missing Verification
In the case, the model performed a cleanup action but did not recompile, effectively skipping the only objective feedback source. “Done” without verification is a claim, not a fact. A reliable execution pattern requires every step to follow a modify–build–test–record loop, and no step may proceed if any part fails.
3. A Different Challenge: Visualization and Frontend Tasks
The original material also mentions another class of tasks: GUI and algorithm visualization, including slider-based puzzle layouts, physics-collision mini-games, and reinforcement learning training demos in a maze. Their failure modes differ from refactoring and concentrate on three points.
First, missing common-sense physical constraints, for example unreasonable spacing between collision targets, which makes the situation unsolvable by the rules. Second, layout and logic layers are not aligned: visual elements are disconnected from the data-layer coordinate system, so the demo cannot run properly. Third, the training process does not converge, and there is no visualization of the state-value distribution, making it hard to tell whether learning actually happened.
Notably, when the chain of thought mentions something like an “ink-wash style” but the final output contains no corresponding implementation, that is a typical “plan hallucination”: the planning layer and the generation layer are disconnected. This suggests that acceptance criteria for visual requirements must be written as checkable items, such as the number of colors, layer order, and element alignment, rather than staying at the level of style adjectives.
4. A Reusable Evaluation Design
To make evaluation results useful, fix the following variables:
- The same codebase, the same detailed plan, and the same verification script, comparing different models side by side;
- Four metrics: first-pass rate, average number of interventions, changeset size, and total elapsed time;
- Complete traces retained for failed samples, distinguishing “localization errors” from “implementation errors”;
- Explicit termination conditions and a rollback mechanism, so a single experiment does not pollute the main branch.
A skeletal acceptance check can be written as:
def run_step(step, repo, verify):patch = agent.apply(repo, step.plan)if patch.changed_lines > step.budget * 3:return "ABORT: change out of control"ok, log = verify(patch) # build + testif not ok:return "FAIL: re-localization required" # no random trial and errorreturn "PASS"
5. Engineering Guardrails: Four Constraints for Stable Output
First, enforce verification first. State explicitly in the prompt that completion must not be claimed unless the verification command passes, and require key output snippets to be pasted as evidence.
Second, limit the change budget. Set a maximum number of changed lines per step; exceeding it triggers a rollback and replanning, eliminating shotgun behavior by design.
Third, require falsifiable assumptions. Any judgment about the environment or toolchain must come with a verification command and its output, otherwise it is not accepted.
Fourth, commit in small steps and keep them reversible. Split a large plan into small steps that can be verified independently, and use branches and version control so the cost of failure is contained within a single step.
On the infrastructure side, container platforms can ensure environment consistency, logging services and monitoring alerts can accumulate the evidence chain for each verification, and object storage can archive trace data for later review and regression. If you use the relevant general capabilities of Baidu AI Cloud, the same idea applies: standardize these stages rather than relying on the luck of a single interaction.
6. Conclusion
Evaluating LLMs should not focus only on whether the demo looks impressive, but on whether the model can be constrained, verified, and converged in long-chain tasks. For developers, the effective approach is to design “model capability” and “engineering guardrails” as a whole: plans detailed enough to be verified, execution closed-loop through build and test, and changes controlled enough to be rolled back. With these three in place, even if the model produces a hallucinated attribution at some step, the loss is contained within that step and overall delivery remains predictable.
