Abstract
Automated Program Repair (APR) faces significant challenges when synthesizing patches for real-world software systems. While Large Language Models (LLMs) have emerged as powerful "copilots" for coding tasks, they often treat programs as simple sequences of tokens, remaining ignorant of the underlying semantic constraints of the target language. This leads to the generation of statically invalid patches that cannot compile, wasting computational resources. We present Repilot, a framework that fuses LLMs with semantic Completion Engines to guide the repair process. By pruning infeasible tokens and proactively completing code fragments, Repilot significantly improves the validity and correctness of generated patches. Evaluation on Defects4J benchmarks demonstrates that Repilot outperforms state-of-the-art techniques, fixing up to 47% more bugs than previous LLM-based approaches.
Introduction
The software engineering community has recently seen a paradigm shift with the introduction of Large Language Models (LLMs) like CodeT5 and InCoder. These models act as automated "copilots," assisting in everything from code completion to Automated Program Repair (APR). However, a fundamental gap remains: LLMs are primarily statistical engines. They predict the next token based on probability rather than a formal understanding of programming language semantics.
In the context of APR, this lack of semantic awareness results in "statically invalid" patches—code that may look syntactically correct but fails to compile because it references non-existent variables, violates type constraints, or calls methods with incorrect signatures. These invalid candidates consume the limited "patch budget" and hinder the practicality of LLM-based repair tools.
The Repilot Framework
Repilot addresses this gap by creating a synergy between the statistical power of LLMs and the formal precision of Completion Engines—the same technology that powers intelligent autocompletion in modern Integrated Development Environments (IDEs).
Guided Search Space Pruning
During the autoregressive generation process, Repilot monitors the LLM's token suggestions. Before a token is finalized, Repilot queries a Completion Engine to verify if the token is semantically feasible within the current code context. If the engine determines the token is invalid (e.g., a variable name not in scope), Repilot prunes that token by zeroing out its probability. This forces the LLM to sample from the remaining valid search space, ensuring that the generation process stays within the bounds of the language's formal rules.
Active Completion
Beyond mere pruning, Repilot takes an active role in generation. If the Completion Engine identifies that there is only one possible valid completion for a code fragment—such as a specific, long identifier or a mandatory keyword—Repilot bypasses the LLM's sampling process and proactively fills in the code. This is particularly effective for "rare tokens" or complex identifiers (e.g., asEndTag) that LLMs often struggle to generate correctly across multiple sub-word tokens.
Efficiency and Memorization
To maintain performance, Repilot utilizes a Trie-based memorization structure. This stores rejected token prefixes, preventing redundant queries to the Completion Engine for paths already known to be invalid. For larger LLMs, the overhead of this semantic check is negligible compared to the inference time of the model itself.
Experimental Evaluation
Datasets and Baselines
Repilot was evaluated using the industry-standard Defects4J benchmarks, specifically focusing on single-hunk bugs:
- Defects4J 1.2: 138 bugs.
- Defects4J 2.0: 135 bugs.
The framework was compared against 19 existing APR tools, ranging from traditional template-based systems (e.g., TBar) to neural machine translation (NMT) models (e.g., RewardRepair) and pure LLM approaches (e.g., AlphaRepair).
Performance Results
Repilot demonstrated a significant leap in repair capability:
- Bug Fixing: It successfully fixed 66 bugs in Defects4J 1.2 and 50 bugs in Defects4J 2.0. This represents a 27% and 47% improvement, respectively, over the previous state-of-the-art LLM baseline, AlphaRepair.
- Compilation Rate: One of the most striking results was the stability of the compilation rate. While traditional LLM tools often see their compilation rates drop to 10-30% as they explore more candidates, Repilot maintained a compilation rate of approximately 60%. This efficiency allows the tool to find correct fixes much faster within a fixed computational budget.
Discussion and Insights
Repilot essentially provides an "IDE for AI." Just as human developers rely on real-time feedback from their IDEs to avoid trivial errors, AI agents require a similar feedback loop to bridge the semantic gap. By fusing statistical intent with formal rules, Repilot ensures that the creativity of the LLM is grounded in the reality of the codebase.
Furthermore, the framework proved to be model-agnostic. It enhanced the performance of both Encoder-Decoder and Decoder-only architectures, suggesting that as LLMs continue to evolve, the Repilot framework can continue to provide a performance "multiplier" by enforcing semantic correctness.
Limitations and Future Work
While highly effective, the current implementation of Repilot is optimized for Java. Extending the framework to dynamically typed languages like Python presents a challenge, as "validity" is often harder to determine through static analysis alone. Additionally, the current study focused on single-hunk bugs; future iterations will explore the complexities of multi-file and multi-hunk repairs.
Conclusion
Repilot demonstrates that the future of automated programming lies not just in larger models, but in the intelligent fusion of statistical learning and formal methods. By "copiloting the copilots," Repilot transforms LLMs from text generators into semantically-aware repair engines, setting a new standard for Automated Program Repair.
Summary updated