arXiv:2610.24790cs.SEOct 2026

Manuscript Offprint

arXiv:2610.24790

When LLM-Generated Refactorings Ripple: An Empirical Study of Repository Adoption Readiness

Muhammad Waseem, Aakash Ahmad, Pekka Abrahamsson

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Muhammad Waseem, Aakash Ahmad, and Pekka Abrahamsson

Abstract—Large Language Models (LLMs) are increasingly used to refactor existing source files to improve their structure and maintainability. Existing evaluations mainly measure file-local outcomes, such as smell reduction, compilation, or test success. However, these outcomes do not reveal whether a candidate changes contracts, dependencies, or caller assumptions that affect its adoption within the surrounding repository. To address this gap, we conduct 1,500 generation attempts across 150 production files from 15 open-source Java repositories, five LLM configurations, and two dependency-aware generation conditions: single-prompt refactoring and LangGraph-based multi-agent refactoring. Of these attempts, 1,455 yield complete candidates eligible for analysis. We evaluate these candidates using local changes, repository-facing structural indicators, detected caller impact, the behavioural-equivalence indicator, and available test evidence, and categorize them as LOW-RISK, REVIEW-NEEDED, HIGH CONTRACT/DEPENDENCY RISK, or INCONCLUSIVE. The results show that 1,365 candidates (93.8%) are classified as having High contract/dependency risk, whereas 106 (7.3%) have at least one detected broken downstream caller and 290 (19.9%) have a false behavioural-equivalence indicator; only eight satisfy the Low-risk criteria. Within the reason-covered subset, the High-risk rate decreases under more conservative dependency-delta thresholds, while 60 of the 65 candidates with conclusive targeted-test outcomes pass, including 50 classified as High risk. Paired analyses of 705 complete pairs identify no statistically significant generation-condition difference in the principal risk indicators, although model configurations differ in specific detected risk channels. These findings suggest that practitioners should treat LLM-generated refactorings as candidates requiring staged repository-level verification, while future research should validate screening and extraction precision and strengthen compilation, behavioural, and coordinated multi-file verification.

Index Terms—Code refactoring, empirical software engineering, large language models, program verification, repository-level analysis, software maintenance.

1 INTRODUCTION

Refactoring improves the internal structure of software while preserving its externally observable behaviour [1], [2]. It can improve maintainability and facilitate future changes, but an incorrect transformation may introduce regressions, integration problems, or unintended behavioural changes [3], [4]. Large Language Models (LLMs) are increasingly used to refactor existing source files by interpreting code-quality problems and generating context-sensitive revisions [5]. Recent empirical studies show that LLMs can produce useful refactoring suggestions, reduce detected code smells, and improve file-local quality indicators in some settings [6], [7]. Unlike a mechanically specified refactoring operation, however, an LLM-generated output is a candidate whose suitability for repository integration must be established before adoption.

The central problem is that evidence of improvement within the edited file does not show whether the candidate preserves the properties on which the surrounding repository depends. Java files expose methods and constructors to callers, depend on imported types, implement interfaces, participate in inheritance structures, and use annotations that may control framework behaviour. A change to any of these elements can affect code beyond the edited file, even when the candidate reduces local smells or appears structurally cleaner. Repository-level code-generation research similarly emphasizes that realistic changes require context from multiple files and must account for dependencies and constraints distributed throughout a repository [8].

Consider a candidate that decomposes a long method and removes a locally detected smell but also changes the signature of a public method or constructor. The edited file may appear improved, while existing callers can no longer invoke it correctly. Similarly, changing an annotation, implemented interface, or dependency may alter how the class is instantiated, discovered, or used elsewhere. Figure 1 illustrates this distinction between file-local improvement and repository-level verification. A structural warning does not by itself demonstrate semantic failure, but it identifies a repository-facing change that may require inspection, coordinated modification, compilation, or testing before adoption.

Existing studies provide important evidence about LLM refactoring capability, local quality improvement, compilation, testing, and behaviour preservation in controlled settings [6], [7]. Repository-aware and multi-agent workflows further use retrieval, specialized roles, and tool feedback to improve candidate generation and verification [9], [10], [11]. Nevertheless, limited evidence is available about the repository-facing properties that remain in generated candidates. In particular, it remains unclear how frequently

Muhammad Waseem and Pekka Abrahamsson are with Tampere University, Finland. E-mail: {muhammad.waseem, pekka.abrahamsson}@tuni.fi.

Aakash Ahmad is with the School of Computing and Engineering, University of Derby, UK. E-mail: a.abbasi@derby.ac.uk.

a) Process-centric

b) Code-centric

Figure

Fig. 1. Local improvement and repository-level verification of an LLM-generated refactoring candidate. A candidate may improve the edited file while changing a public contract, caller-used API, dependency relation, framework-sensitive construct, or downstream caller assumption.

candidates alter contracts and dependencies, how often these changes coincide with detected caller or behavioural impact, and whether single-prompt and multi-agent generation produce different risk profiles when evaluated on the same files and models. This gap matters because adoption decisions require developers to assess not only whether a file improves, but also whether the resulting change can be reviewed, integrated, compiled, tested, and trusted within the surrounding system.

To examine this gap, we conduct an empirical study of LLM-generated Java refactoring candidates. The study covers 15 open-source repositories and 150 production files selected to combine local refactoring need with observable repository exposure. For each selected file, we attempt candidate generation with five LLM configurations under two dependency-aware conditions: single-prompt refactoring and LangGraph-based multi-agent refactoring. This design produces 1,500 generation attempts, of which 1,455 yield complete candidates eligible for analysis, comprising 706 single-prompt and 749 multi-agent candidates. The two conditions receive the same selected files and repository dependency context, enabling matched comparisons across 705 complete file-model pairs.

We evaluate each eligible candidate using complementary forms of evidence. File-local measures characterize the generated edit, while repository-facing indicators capture changes to public and protected contracts, caller-used APIs, dependencies, annotations, inheritance relations, implemented interfaces, and detected downstream callers. The behavioural-equivalence indicator and available targeted-test outcomes provide additional evidence about behaviour preservation. Based on the evidence produced by the verification pipeline, candidates are categorized as Low-risk, Review-needed, High contract/dependency risk, or Inconclusive. These categories support candidate screening and review prioritization; they are not treated as independently validated judgments of semantic correctness. We further compare the generation conditions and model configurations and examine exploratory associations between source-file exposure, generated changes, and the resulting screening and observed-impact outcomes. The research questions are presented in Section 3.1.

This paper makes the following contributions.

• We formulate and operationalize a repository-level evaluation perspective for LLM-generated refactoring that distinguishes file-local improvement, structural screening, detected caller impact, and behavioural verification evidence.

• We conduct a controlled study of 1,500 generation attempts across 15 Java repositories, 150 production files, five LLM configurations, and two dependency-aware generation conditions. To the best of our knowledge, this is the first paired empirical study examining whether multi-agent orchestration changes repository-level ripple-risk and verification evidence under matched file and model conditions.

• We provide the generation and verification implementation, raw study records, final analysis dataset [12], and analysis scripts [13] to support reproduction of the quantitative analyses and artifact-level inspection where the required candidate artifacts are available.

The remainder of this paper is organized as follows. Section 2 reviews related work. Section 3 describes the study design and analysis procedures. Section 4 presents the empirical results, and Section 5 discusses their implications. Section 6 examines threats to validity, and Section 7 concludes the paper.

References (37)