RefactorBench: Evaluating Stateful Reasoning in Language Agents Through Code

Dhruv Gautam, Spandan Garg, Jinu Jang, Neel Sundaresan, Roshanak Zilouchian Moghaddam

Introduction

While language model (LM) agents have demonstrated impressive capabilities in solving isolated software engineering tasks, they often struggle with long-horizon planning and maintaining consistency across complex codebases. Most existing benchmarks, such as SWE-bench, are derived from real-world GitHub issues that are predominantly focused on bug-fixing. However, bug-fixing often allows agents to rely on a "reproduce-and-repair" loop that does not necessarily require a deep, persistent understanding of the entire system's state.

To address this, researchers have introduced RefactorBench, a handcrafted benchmark of 100 multi-file refactoring tasks. RefactorBench is designed to expose the "stateful reasoning" failures of current agents, specifically their tendency to lose track of progress during complex, multi-step transformations. By evaluating how agents handle structural changes across nine popular Python repositories, the study reveals a significant gap between human performance and current AI capabilities, while proposing a "state-aware" architectural shift to bridge it.

The Challenge: Context Flooding and Memory Decay

The core difficulty in multi-file refactoring lies in stateful reasoning. Unlike a bug fix, which might be localized, a refactor (such as renaming a class or updating a function signature used across a project) requires the agent to maintain a complex mental model of dependencies.

The authors identify two primary failure modes in current agents:

  1. Context Flooding: Long trajectories of error messages, linting results, and tool outputs can quickly saturate a model's context window. For instance, a single linting error can generate over 1,400 tokens of output. When these outputs accumulate, the original task instructions are often pushed out of the effective context, leading the agent to forget its objective.
  2. Linear Decay of Memory: Through synthetic experiments involving iterative updates to user preferences, the researchers demonstrated that an LM's ability to reconstruct the current state of a system decreases almost linearly as the number of actions increases.

RefactorBench: A New Evaluation Framework

RefactorBench consists of 100 tasks across major Python open-source projects, including Django, Flask, FastAPI, and Ansible. To ensure a robust evaluation, the benchmark departs from brittle "exact match" string comparisons. Instead, it employs AST-based unit testing. By parsing the code's Abstract Syntax Tree (AST), the framework can verify that the required structural changes were implemented correctly without being distracted by trivial formatting differences.

To test the impact of prompt clarity, each task includes three levels of natural language instructions:

  • Lazy: Vague or minimal instructions.
  • Base: Succinct, standard instructions.
  • Descriptive: Detailed, step-by-step guidance.

State-Aware Interfaces: History is Not State

A key contribution of the paper is the distinction between history and state. In a standard agent setup, the model is provided with a raw transcript of every command and observation. The authors argue that this transcript is often too noisy for effective reasoning.

They propose State-Aware Interfaces, where the system maintains an explicit, externally computed summary of the current environment (e.g., a list of modified files and specific lines edited). This summary is prepended to every turn in the conversation. This allows the agent to condition its next move on the current state of the codebase rather than trying to reconstruct that state from a messy and potentially truncated conversation history.

Key Results and Insights

The experimental results highlight a stark contrast between human developers and AI agents:

  • The Human-AI Gap: A human developer, given a five-minute limit, solved 87% of the tasks. In contrast, the baseline SWE-agent (powered by GPT-4) solved only 18% using base instructions.
  • The State-Aware Advantage: Implementing the state-aware interface led to a 43.9% relative improvement in task completion. Furthermore, the completion rate of individual subtasks (verified by AST tests) increased by 71%.
  • Instruction Sensitivity: Agents proved highly sensitive to the level of detail provided. Performance jumped from 12% on "Lazy" instructions to 27% on "Descriptive" instructions, suggesting that current models still rely heavily on explicit guidance to navigate complex state spaces.
  • The "Bug-Fix" Bias: A qualitative finding revealed that many agents are "overfit" to the bug-fixing paradigm. When presented with a refactoring task, agents frequently attempted to write "bug reproduction scripts" even when no bug existed, simply because their training or prompting was centered on GitHub-style issue resolution.

Conclusion and Future Work

RefactorBench demonstrates that state management is a primary bottleneck for current language agents in software engineering. While providing explicit state summaries significantly boosts performance, a large gap remains between AI and human-level refactoring.

Future work will look to expand RefactorBench to statically typed languages and explore the use of "critic" models to verify refactors in real-time. Additionally, the state-aware approach provides a promising foundation for multi-agent coordination, where multiple models can operate on a shared codebase by referencing a unified, externalized representation of the system state.

Summary updated

BibTeX
@inproceedings{gautam2025refactorbench,
  author = {Dhruv Gautam and Spandan Garg and Jinu Jang and Neel Sundaresan and Roshanak Zilouchian Moghaddam},
  title = {{RefactorBench: Evaluating Stateful Reasoning in Language Agents Through Code}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=NiNIthntx7},
}
Figure