← Latest papers
💻 computer science

SWE-Refactor: A Repository-Level Benchmark for Real-World LLM-Based Code Refactoring

This paper introduces SWE-Refactor, a comprehensive repository-level benchmark comprising 1,099 validated Java refactorings designed to overcome limitations in existing datasets and evaluate the capabilities of nine LLMs, revealing that current models struggle significantly with complex, compound refactoring tasks.

Original authors: Yisen Xu, Jinqiu Yang, Tse-Hsun, Chen

Published 2026-02-04
📖 4 min read☕ Coffee break read

Original authors: Yisen Xu, Jinqiu Yang, Tse-Hsun, Chen

Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer

Imagine you have a massive, old library filled with books written in a very specific language (Java). The books work perfectly, but the stories are messy: chapters are too long, characters are named confusingly, and some scenes are scattered across different rooms. Code refactoring is the process of cleaning up these books to make them easier to read and maintain, without changing the actual story or the ending.

For a long time, we've been teaching computers (specifically, Large Language Models or LLMs) how to write new stories from scratch. But teaching them how to fix existing stories without breaking the plot is much harder.

This paper introduces SWE-Refactor, a new "exam" designed to test how good these AI computers are at cleaning up code. Here is the breakdown in simple terms:

1. The Problem: The Old Exams Were Flawed

Before this, researchers tried to test AI on code cleaning, but the tests had three big problems:

  • Too Simple: They only asked the AI to do tiny, single-step fixes (like renaming one variable), ignoring complex jobs that require moving whole chapters around.
  • Noisy Data: Sometimes the "correct answer" provided in the test wasn't just a cleanup; it included fixing bugs or adding new features. This confused the AI: "Am I supposed to clean the room, or also paint the walls?"
  • Missing Context: Real code is like a web; changing one line often affects ten others. Old tests didn't give the AI enough of the "big picture" (the whole library) to understand the connections.

2. The Solution: A Real-World "Gym" for AI

The authors built SWE-Refactor, a massive, high-quality training ground and exam.

  • Real Human Work: Instead of making up fake examples, they looked at 18 real, popular Java software projects. They found 1,099 times where human developers successfully cleaned up code.
  • Pure Cleaning: They used special tools to filter out any changes that weren't just cleaning. If a developer fixed a bug while cleaning, that example was thrown out. They only kept the "pure" cleanups.
  • The Full Library: They didn't just give the AI one page; they gave it the whole book, the map of the library, and the list of who reads what, so the AI understands the context.
  • The "Gold Standard" Check: To make sure the AI didn't cheat, they check three things:
    1. Does the code still compile (do the pages hold together)?
    2. Do all the tests still pass (does the story still make sense)?
    3. Did the AI actually do the specific cleaning task requested, or did it just write something that worked?

3. The Exam Results: AI is Good at Small Tasks, Bad at Big Ones

The authors tested 9 different AI models (including famous ones like GPT-4o and DeepSeek) on this new exam.

  • The Generalists Win: The big, general-purpose AI models (like GPT-4o) did much better than the smaller, specialized coding models. It seems understanding the "big picture" is more important than just knowing syntax.
  • Simple vs. Complex: The AI was decent at simple, single-step cleanups (like "Extract Method," which is like taking a paragraph out of a long chapter and making it a new, short chapter).
  • The Compound Challenge: The AI struggled significantly with compound refactorings. These are jobs that require multiple steps at once, like "Take this paragraph, move it to a different chapter, and rename the character."
    • The Analogy: Imagine asking a robot to move a heavy sofa. It can do it. But if you ask it to "Move the sofa, paint the wall behind it, and rearrange the rug," it often forgets a step or messes up the order.
    • The Stat: Even a very advanced AI agent (OpenAI Codex) only succeeded about 39% of the time on these complex, multi-step tasks.

4. How to Help the AI Succeed

The paper also tested if giving the AI more help would work:

  • Retrieval (RAG): Giving the AI examples of similar cleanups helped a little.
  • Multi-Agent Workflow (The Team Approach): This was the winner. Instead of one AI doing the work, they set up a "Developer AI" to write the code and a "Reviewer AI" to critique it and ask for changes. This "team" approach solved the most problems, showing that AI needs to check its own work to handle complex tasks.

Summary

SWE-Refactor is a new, strict, and realistic test for AI code refactoring. It proves that while AI is getting good at small code fixes, it still struggles with complex, multi-step renovations that require understanding how different parts of a software project connect. The authors released all their data and results so other researchers can use this "gym" to train better AI for the future.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →