The Capability Boundaries of LLMs in Legacy System Modernization
This article examines where large language models actually struggle in legacy codebases: not writing code, but respecting undocumented constraints and existing contracts. It breaks legacy bug fixing into four observable capability layers, outlines an evaluation design that scores change intrusiveness alongside functional fixes, and provides prompt and tool permission constraints that enforce restraint. Common failure modes and practical rollout advice are included.
1. The Real Difficulty Is Reading Established Facts, Not Writing Code
Most discussions of LLM coding ability stop at “can it write a function.” The genuinely expensive engineering task is different: locating an intermittent defect in a legacy system that has no documentation, inconsistent naming, overlapping responsibilities, and comments long out of sync with the implementation, then fixing it safely.
These tasks are hard because the codebase carries a large body of established facts — compromises made to hit deadlines, branches kept for backward compatibility with old data, checks that look redundant but serve as a safety net. The model is not facing a blank canvas; it is facing an existing contract that has to be respected.
So the maturity of an AI coding tool in a legacy system cannot be judged by how clean its generated code looks. It has to be judged by whether the model shows restraint when information is incomplete and constraints are unwritten. One failure mode is widely observed in the industry: the model does turn the tests green, but the implementation is too aggressive — it rewrites data structures, changes field semantics, or deletes branches it considers “useless,” and ends up breaking the existing data flow. On a scorecard this may read as “fixed”; in production it is a more severe regression.
2. Breaking “Fixing the Mess” Into Four Observable Capability Layers
To compare models objectively, split the task into layers that can be observed independently instead of relying on a vague “strong/weak” verdict.
The first layer is cross-file context retrieval and localization. A defect often shows up as an error in file A while the root cause sits in an implicit convention in file C. The model needs to initiate searches on its own, read both callers and callees, and find the actual write point rather than guessing locally within the current file.
The second layer is change impact analysis. Before fixing anything, the model should be able to answer: what are the call entry points for this logic, which persisted structures depend on it, are there serialization compatibility issues, and will historical data be misread by the new logic.
The third layer is semantics-preserving minimal change. This is the dividing line between “usable” and “dangerous.” An acceptable strategy keeps the existing data structures and external behavior unchanged and only adjusts control flow or boundary conditions. An unacceptable strategy refactors, renames, or swaps the storage model.
The fourth layer is the verification loop: whether the model can write regression cases itself, run the existing tests, and read logs and iterate on failure, rather than producing one output and declaring the work done.
3. Evaluation Design: Making Scores Correspond to Real Risk
Conclusions published online vary widely, mostly because scenarios and weightings differ. To get results with engineering value, define the constraints and scoring criteria explicitly.
- Task sampling: draw from real historical defect tickets and keep the original code style, with no cleanup.
- Closed environment: allow retrieval and modification only inside the given codebase; forbid filling in facts from external memory.
- Change whitelist: explicitly declare that data structures, persistence formats, and public API signatures must not change; any violation is an automatic failure.
- Dual-track scoring: score functional repair and change intrusiveness separately, with lower intrusiveness earning a higher score.
- Regression verification: require all existing tests to pass as the baseline, and require new cases to cover the path that triggered the original defect.
A sample constraint declaration can be written as configuration so the model sees it at every step:
task: legacy_bugfiximmutable:- data_schema # persistence structures must not change- public_api_sign # public signatures must not change- field_semantics # field semantics must not changeallowed_edit:- control_flow- boundary_condition- error_handlingscoring:functional_pass: 0.6minimal_diff: 0.3regression_green: 0.1hard_fail_on_schema_change: true
Under criteria like these, it is not surprising that several models all “fix successfully.” The real difference shows up in the shape of the diff: one model changes seven lines of boundary conditions, another rewrites three hundred lines and adjusts the caching structure along the way. The former can be reviewed, rolled back, and shipped; the latter requires a human to inspect it line by line for hidden damage.
4. Prompt and Tool Constraints: Writing Restraint Into the Process
Model behavior is shaped largely by context and tool permissions. What works in practice is turning “prove first, then act” into a hard requirement.
1. Use only retrieval results from within the codebase as the source of truth, and cite the file and line number for every conclusion.2. When stating a root cause hypothesis, list at least two candidate causes that were ruled out, with the reason for ruling each out.3. Before submitting a patch, output an impact list: call entry points, dependent data structures, compatibility risks.4. If the fix requires changing the data model, stop and request confirmation; do not decide on your own.5. The patch must include a minimal regression case, and existing tests must be run; on failure, read the logs and keep iterating.
Tool permissions need the same narrowing: restrict the writable scope to specified directories, block irreversible bulk rewrites and dependency upgrades, and put a confirmation gate on file deletion and renaming. These constraints do not limit the model’s capability; they keep risk decisions in the human review step.
5. Common Failure Modes and How to Avoid Them
The first is aggressive refactoring, where the implementation is replaced in the name of being “more elegant.” Guard against it with a diff line-count threshold alert and static checks for structural changes.
The second is data semantics drift, where the field name stays the same but the meaning changes and old data is misread by new logic. Guard against it by requiring the review checklist to answer explicitly how historical data stays compatible.
The third is hallucinated fixes, calling interfaces that do not exist or assuming configuration items that do not exist. Guard against it by requiring every conclusion to carry a file and line reference; anything that cannot be referenced counts as unverified.
The fourth is tests bending to the implementation, where the model edits assertions to make cases pass. Guard against it by listing new and modified test files separately for human confirmation.
6. Recommendations for Engineering Adoption
When introducing AI coding tools into a real project, use a small-step authorization strategy: open read and write access on low-risk defect tickets first, measure the first-pass rate and the amount of human rework, then expand gradually to cross-module tasks. Build the observability foundation at the same time — logging, monitoring and alerting, and distributed tracing — so the model and engineers work from the same source of truth. If the codebase is large, use a container platform to build isolated verification environments so every patch runs the full regression in a consistent environment.
The conclusion is not mysterious: in legacy modernization, the gap between models is not mainly about whether a fix can be made, but about how much it costs to make it. When evaluation constrains data structures and interfaces to be immutable and folds change intrusiveness into the score, capability tiers separate naturally. For a team, rather than chasing leaderboard positions, it is better to build up the constraints, verification, and review process — that is what turns AI coding capability into delivery quality reliably.
