Evaluating LLM Capability and Delivering Reliable Refactoring Work

    This article examines how to assess large language model performance in complex software refactoring, especially during final-stage work where existing constraints and partially completed migrations dominate. It breaks down the real capabilities behind subjective impressions of "smartness" — constraint adherence, reasoning over dependency chains, and separating analysis from implementation — and proposes a practical evaluation framework plus a workflow for reliable delivery. It also explains how to interpret capability fluctuations in real-world usage. The goal: treat LLMs as evaluable engineering participants whose output can be verified, not just admired.

    1. From “Seems Smarter” to “Can It Reliably Complete the Task?”

    In AI-assisted programming, the final stages of a refactoring project are often a better test of a large language model’s real capabilities than building a feature from scratch.

    The reason is that finishing work does not start from a blank page. It starts from a system already containing many design decisions, historical constraints, and partial modifications. The model must not only understand the current code, but also judge which behaviors should be preserved, which structures can be adjusted, and whether existing changes have introduced new risks.

    A typical task may simultaneously include the following requirements:

    • Keep external calling conventions and return results compatible;
    • Finish incomplete module migrations;
    • Clean up duplicated logic without expanding the scope of changes;
    • Handle exception paths and resource release;
    • Add tests and explain the verification basis;
    • Follow existing directory structure and coding conventions;
    • Avoid touching business logic unrelated to the current goal.

    The ability to recite these requirements one by one does not mean the model can consistently follow them while modifying code. The real question is: when multiple constraints interact, can it maintain consistent judgment and check global consequences after making local changes?

    Therefore, evaluating an LLM should not stop at whether its answers are “deeper,” its wording “more concise,” or its tone “more confident.” The more valuable question is: under real engineering constraints, does it reduce omissions, rework, and manual intervention, and ultimately produce a deliverable that can be reviewed?

    2. The “Feel” of a Capable LLM Is Really a Combination of Abilities

    Developers sometimes describe a usage experience as feeling more “LLM-like.” That subjective impression can be kept, but it should be decomposed into observable engineering dimensions rather than treating a change in experience as evidence of a change in model scale.

    2.1 Constraint adherence in long contexts

    Context capacity and effective use of context are not the same thing.

    A system being able to accept a large amount of text only means the input can be accommodated. Whether it can accurately identify key constraints and then consistently enforce them during subsequent modifications still needs to be verified empirically.

    For example, suppose the user states at the beginning that “exception types must not change.” The model may correctly understand this midway through, yet later, for the sake of simplifying the code, unify different exceptions into one generic error. It received the constraint but did not stably maintain it.

    The focus should therefore be on observing:

    • Whether previously stated restrictions are overlooked;
    • Whether current requirements are confused with already-rejected approaches;
    • Whether local optimizations break global contracts;
    • Whether the model can detect conflicts between two requirements;
    • Whether it proactively asks for confirmation when information is insufficient.

    What is being measured here is consistency of constraint enforcement, not the ability to recite information.

    2.2 Reasoning completeness over long dependency chains

    Complex refactoring requires the model to reason continuously along dependency relationships.

    For example, changing a data structure may successively affect serialization results, cache contents, caller-side logic, and historical data reading. If the model only checks direct call sites, it will miss behavior changes further downstream.

    Good performance is not a lengthy analysis, but the identification of key causal chains: where the change occurs, through which boundaries the impact propagates, which points must be verified, and which risks remain unresolved.

    Developers should require the model to provide reviewable reasons, assumptions, and evidence, rather than treating length of explanation as a proxy for reasoning quality.

    2.3 Analysis ability and implementation ability must be evaluated separately

    Being good at locating problems does not mean being good at producing workable solutions.

    A model may accurately point out that “module responsibilities are tangled,” yet propose a large-scale split that turns a locally fixable problem into a cross-module rewrite. Or it may correctly identify a resource leak but only release resources on the normal path, missing the exception path.

    Therefore, capability evaluation should distinguish at least four stages:

    1. Whether the real problem was identified;
    2. Whether the mechanism producing the problem was explained;
    3. Whether a fix satisfying the constraints was proposed;
    4. Whether the fix was proven effective without introducing obvious regressions.

    Looking only at the first two stages tends to overestimate the model’s engineering value. Reliable delivery requires all four stages to form a closed loop.

    2.4 Communication efficiency and technical depth must be retained together

    A shorter answer may mean more efficient expression, or it may mean necessary checks were omitted. The two must not be conflated.

    A high-quality concise answer retains the goal, the reasons for modifications, verification results, and remaining risks. A low-quality concise answer typically contains only conclusions like “fixed” or “should be fine.”

    In actual collaboration, a fixed reporting structure can be used:

    • What problem this change solves;
    • Which areas the change touches;
    • Why the current approach was chosen;
    • Which checks have been executed;
    • Which checks have not been executed;
    • What uncertainties remain.

    This structure both reduces ineffective narration and lets developers quickly judge whether the deliverable is trustworthy.

    3. Why Final-Stage Refactoring Especially Exposes Model Weaknesses

    3.1 Locally correct code does not mean correct system behavior

    Refactoring usually requires internal structural changes while keeping external behavior unchanged.

    This means “the code runs” is only the lowest bar. Return values, exception semantics, execution order, state changes, and resource lifecycles may all count as behavior that must be preserved.

    For example, after merging two duplicate functions, the main flow may still pass tests, but one caller previously depended on a specific failure-handling behavior. If the merge ignores that difference, a behavioral regression results.

    Refactoring verification should therefore be organized around behavioral contracts, not merely syntax checks or a few normal-path tests.

    3.2 Existing changes create complex intermediate states

    An unfinished project often contains both old and new structures simultaneously: some calls have been migrated, while others still use the old path; the new abstraction is in place, but old logic still carries certain boundary behaviors.

    If the model assumes the entire project has already adopted the unified architecture, it may prematurely delete compatibility code. Conversely, if it treats all old code as untouchable, the refactoring stays at the level of superficial tidying.

    A more robust approach is to first identify the migration state, then determine which logic belongs to the target structure, which is temporary transition, and which still has actual calls depending on it. Without this information, the cleanup scope should not be expanded.

    3.3 Bug fixes and structural optimization interfere with each other

    When a single change simultaneously includes defect fixes, interface adjustments, naming cleanup, and performance optimization, review difficulty increases significantly. Once a regression appears, it is hard to tell which category of change caused it.

    The priority should be to split the work into small, independently verifiable steps: first pin down behavior, then fix defects, then adjust structure, and finally handle non-essential optimizations. Not every project must follow exactly this order, but each step should have a clear purpose and verification boundary.

    4. Building a Capability Evaluation Framework for Complex Tasks

    Rather than judging a model by one brilliant answer, prepare a fixed set of tasks and observe its performance over time.

    4.1 Build a task set covering real difficulties

    The task set should include different types of problems:

    • Multi-file call-relationship analysis;
    • Local refactoring with compatibility requirements;
    • Defects where both normal and exception paths exist;
    • Constraint-adherence tasks with irrelevant background noise;
    • Tasks requiring information confirmation before a plan is made;
    • Tasks requiring correcting an original plan based on test failures.

    It is best to prepare reviewable acceptance criteria for each task in advance. Without objective acceptance criteria, evaluation degenerates into comparing preferences about writing style.

    4.2 Record outcome metrics, not just answer quality

    The following metrics can be used:

    Constraint adherence: Of the explicitly stated requirements, which were correctly executed, and which were omitted or violated? Critical constraints should be flagged separately so that satisfying many minor requirements does not mask serious violations.

    Task completion: Did the modifications pass the agreed verification, and did they actually solve the target problem?

    Manual intervention: How many key reminders did the developer need to supply? Did the developer have to point out basic dependency relationships or missing exception handling?

    Rework: After the first round of modifications, were new defects introduced? Was it necessary to roll back part of the plan?

    Review cost: Does understanding and confirming the change require reading a lot of irrelevant content?

    Delivery cost: Includes service cost, waiting time, number of retries, and manual review time.

    These metrics do not need to be compressed into a single score. For tasks involving data consistency or security boundaries, critical errors usually matter far more than average performance.

    4.3 Use repeated testing to identify variance

    A single success or failure may be influenced by task wording, context organization, and generation randomness.

    A better approach is to repeat representative tasks under conditions as consistent as possible, recording the range of outcomes and typical failure modes. If conditions change — for example, input materials are updated, available tools change, or task length grows — record that too.

    This makes it possible to distinguish whether the underlying capability changed overall, or whether certain task types or context structures are simply more prone to triggering failures.

    5. A Workflow for Letting Models Finish Refactoring Reliably

    5.1 Establish a task contract first

    Before the task begins, organize information into four categories:

    • Goal: what must be accomplished this time;
    • Invariants: which behaviors must not change;
    • Allowed scope: which modules may be modified;
    • Acceptance criteria: how completion will be judged.

    For example, “optimize error handling” is too vague. A more executable and reviewable formulation is: “Keep the existing exception types unchanged, fix the resource-release issue on exception paths, and verify both normal and failure scenarios.”

    A task contract should not contain large amounts of historical discussion unrelated to the current change. Relevant background can be kept, but it should be presented separately from the mandatory requirements.

    5.2 Analyze first, then approve the modification scope

    For high-risk tasks, avoid letting the model immediately make large-scale modifications.

    Instead, first require it to submit:

    • A brief description of the current call relationships;
    • Problems found and supporting evidence;
    • Proposed locations for modification;
    • Behaviors that may be affected;
    • A verification plan;
    • Assumptions requiring human confirmation.

    After the developer confirms, move into implementation. This catches wrong directions at low cost, before analysis errors spread across multiple modules.

    5.3 Reduce risk through small batches of changes

    Each batch should revolve around one explainable goal; avoid performing lots of unrelated cleanup at once.

    Small batches are valuable not just for easy rollback but, more importantly, for causal traceability: if a test fails, it is easier to locate the specific change. The model can also correct its plan based on clear feedback instead of continuing to guess amid a large pile of modifications.

    However, splitting must not break necessary atomicity. Changes that must be applied together to keep the system working should be treated as one complete batch, with their interdependency stated.

    5.4 Verification results must distinguish facts from suggestions

    The model “suggesting running the tests” is not the same as the tests having been run. Reading the code and concluding that something “should be compatible” is not the same as compatibility having been confirmed.

    The delivery notes should clearly distinguish:

    • Checks executed and passed;
    • Checks executed and failed;
    • Checks not executed due to environment or permission limitations;
    • Judgments based only on static reading.

    Test design should also avoid letting the model unilaterally define correctness. Key behaviors should be grounded in existing contracts, confirmed business requirements, or independent review, so that implementation and tests do not both rest on the same mistaken assumption.

    5.5 Keep a human gate for high-risk modifications

    For changes involving permissions, data deletion, money handling, concurrency state, or irreversible migrations, retain manual approval and stricter verification.

    The model can take on analysis, patch drafting, and test suggestions, but strong performance on other tasks must not be taken as evidence that it is equally reliable at high-risk boundaries.

    6. How to Objectively View Fluctuations in Usage Experience

    Developers may observe that the same type of task performs differently at different times, that the model starts missing requirements, or that more reminders are needed. Such experiences are worth recording, but one should not conclude from the phenomenon alone that the underlying model was swapped or its capability was deliberately reduced.

    Factors that can influence results include changes in context organization, input truncation, generation settings, changes in available tools and permissions, and increased task complexity. Service configuration or version changes can also have an effect, but without reliable information, these should be treated as hypotheses to verify, not established conclusions.

    When investigating, a layered approach can be used:

    1. Check whether the input is complete and key requirements are clear;
    2. Use shorter tasks of the same type to confirm baseline performance;
    3. Compare tool access, environment, and settings for consistency;
    4. Repeat fixed tasks under identical conditions;
    5. Record visible configuration or version changes;
    6. Adjust task scope and manual review intensity based on actual quality.

    A higher price also does not directly prove stronger reasoning capability or more stable output. Cost may be tied to different resources and service arrangements; the actual value still needs to be validated through real tasks.

    For a team, the most important thing is not predicting how long some ideal experience will last, but maintaining processes that still work when quality drops: shrink modification batches, add constraint summaries, increase verification, roll back promptly, and switch to manual handling when necessary.

    7. Conclusion: Treat the Model as an Evaluable Engineering Participant

    The value of an LLM in complex refactoring should not be determined by one deep analysis or one smooth modification, but by sustained, verifiable delivery performance.

    The capabilities that truly matter are maintaining consistent judgment under multiple constraints, identifying key impacts along long dependency chains, converting correct analysis into appropriately scoped modifications, and honestly reporting verification boundaries.

    Correspondingly, developers need to provide clear contracts, control the modification scope, establish independent acceptance criteria, and continuously record quality fluctuations.

    When model output is incorporated into such an engineering closed loop, “seeming smarter” can translate into less rework, lower review cost, and more reliable system delivery.