CodeTaste: Can LLMs Generate Human-Level Code Refactorings?

The CodeTaste benchmark evaluates LLM coding agents on realistic refactoring tasks mined from open-source repositories. Research shows agents perform reliably when refactorings are specified but struggle to autonomously identify human-preferred structural improvements. A propose-then-implement decomposition improves alignment with human decisions, with verification combining repository test suites and custom static analysis using dataflow reasoning.

CodeTaste: Can LLMs Generate Human-Level Code Refactorings?

Large language model coding agents are advancing beyond basic code generation to tackle the more sophisticated challenge of software maintenance, as demonstrated by new research into their refactoring capabilities. The introduction of the CodeTaste benchmark reveals a critical performance gap: while models can execute prescribed refactorings, they struggle to autonomously identify the structural improvements human developers would choose, highlighting a key frontier for aligning AI with real-world software engineering practices.

Key Takeaways

  • Researchers have introduced CodeTaste, a new benchmark for evaluating LLM coding agents on realistic refactoring tasks mined from large-scale, multi-file changes in open-source repositories.
  • Experimental results show a clear gap: agents perform reliably when refactorings are specified in detail but often fail to discover the human refactoring choices when only given a general focus area for improvement.
  • A propose-then-implement decomposition improves an agent's alignment with human decisions, and selecting the best-aligned proposal before implementation yields further gains.
  • The benchmark combines repository test suites with custom static checks using dataflow reasoning to verify the removal of undesired patterns and introduction of desired ones.
  • CodeTaste is positioned as both an evaluation target and a potential preference signal for training and aligning future coding agents with human refactoring decisions.

Evaluating AI's Ability to "Taste" Good Code

The research paper, hosted on arXiv, investigates a core question in AI-assisted software development: can LLM coding agents not only generate functional code but also improve existing code's structure through refactoring? Refactoring—defined as behavior-preserving transformations that enhance maintainability and reduce complexity—is a daily task for human engineers but a complex challenge for AI, requiring deep understanding of code semantics and design principles.

The study's central contribution is the CodeTaste benchmark. Unlike synthetic or single-file tasks, CodeTaste is constructed from real, historical refactoring commits mined from large open-source repositories. This provides a realistic testbed of multi-file changes that human developers actually chose to implement. To score an agent's solution, the benchmark employs a dual verification system: first, it runs the repository's own test suite to ensure behavior is preserved; second, it uses custom static analysis checks that leverage dataflow reasoning to confirm the removal of specific "code smells" (like duplication) and the introduction of desired patterns.

The experiments evaluated "frontier models" (though specific models like GPT-4, Claude 3, or DeepSeek-Coder are not named in the abstract) across two key agentic scenarios. In the first, the agent is given a detailed specification of the exact refactoring to perform. In the second, more challenging scenario, the agent is only presented with a code focus area needing improvement and must discover and implement the appropriate refactoring. The results indicate a significant performance drop in the discovery task, underscoring the difficulty of replicating human design intuition.

The research also explores methods to close this gap. A two-stage propose-then-implement workflow, where the agent first generates multiple refactoring proposals and then executes the best one, showed improved alignment with human choices. The paper suggests that selecting the proposal most aligned with human preferences—using CodeTaste as a signal—before implementation can lead to even better outcomes.

Industry Context & Analysis

The CodeTaste benchmark arrives at a pivotal moment. The market for AI coding assistants is fiercely competitive, with tools like GitHub Copilot, Amazon Q Developer, and JetBrains AI Assistant boasting millions of users primarily for code generation and completion. However, their effectiveness in complex refactoring and architectural tasks remains a differentiator. For instance, while Copilot Chat can suggest refactorings, its success is often contingent on precise user prompts, mirroring the "detailed specification" scenario where CodeTaste found models to be competent.

The true test, as CodeTaste highlights, is an agent's ability to act autonomously as a proactive architect. This capability gap separates current tools from the vision of fully autonomous AI software engineers. The performance on discovery tasks can be contextualized with known benchmarks: while top models like GPT-4 and Claude 3 Opus achieve high scores on code generation benchmarks like HumanEval (pass@1 rates often above 85%), these tasks don't assess the nuanced design judgment required for refactoring. CodeTaste introduces a necessary, more demanding evaluation layer focused on software quality, not just functionality.

Technically, the use of dataflow-based static checks for scoring is a significant advancement over simpler metrics like code similarity or syntactic correctness. It allows the benchmark to verify that a refactoring genuinely improved the program's structure—for example, ensuring a extracted method doesn't create hidden dependencies—which is crucial for assessing long-term maintainability. This approach follows a broader industry trend of moving beyond output correctness to assess the quality of AI-generated code, as seen in research on code robustness and security.

Furthermore, the proposal that CodeTaste could serve as a preference signal for training connects directly to current alignment techniques like Reinforcement Learning from Human Feedback (RLHF). Companies like Anthropic and OpenAI invest heavily in RLHF to align model outputs with human values; CodeTaste provides a concrete, automated method to gather "human preference" data in the domain of code structure, potentially enabling more efficient training of models that share developers' "taste" for clean code.

What This Means Going Forward

For software development teams, this research signals the coming evolution of AI assistants from "powerful autocomplete" to collaborative maintenance partners. The ability to reliably suggest and implement human-aligned refactorings could dramatically reduce technical debt, allowing engineers to focus on higher-level design and innovation. Companies with large, legacy codebases stand to benefit immensely from tools that can systematically propose improvements validated against patterns of good practice.

For AI developers and companies building coding agents, CodeTaste establishes a new competitive benchmark. Success here will require moving beyond scaling model parameters and toward better integration of program analysis and software engineering knowledge. We can expect a wave of new agent architectures that incorporate dedicated planning modules for refactoring, possibly using techniques like chain-of-thought reasoning specifically tuned for code structure. The propose-then-implement strategy highlighted in the paper may become a standard pattern in these agents.

The market for AI-powered developer tools, already valued in the billions, will see further segmentation. While basic code completion may become a commoditized feature, advanced capabilities in code understanding, refactoring, and system design—validated by benchmarks like CodeTaste—will define the premium tier. Watch for announcements from major players citing performance on refactoring-specific benchmarks as a key differentiator in the next 12-18 months.

Ultimately, the trajectory suggested by this work is toward AI that doesn't just write code but understands and evolves software systems. The next frontier is not just functional correctness, but cultivating an AI's "sense" of good design—its CodeTaste. This will be essential for realizing the long-term promise of AI in managing and modernizing the world's ever-growing, and increasingly complex, software infrastructure.

常见问题

本文基于 arXiv cs.AI 的报道进行深度分析与改写。 阅读原文 →