Code-SPA: Style Preference Alignment to Large Language Models for Effective and Robust Code Debugging

Tengfei Wen, Xuanang Chen, Ben He, Le SunACL 2025

Abstract

Large language models (LLMs) have demonstrated impressive capabilities in coding tasks like code generation and debugging. However, code from real-world users is often poorly styled, containing various types of noise, such as structural inconsistencies, stylistic deviations and flawed test cases. To investigate this, we first simulate poorly styled code using eight types of code perturbations, and then demonstrate that the debugging performance of existing LLM-based methods significantly declines on such inputs. Furthermore, to address this, we propose a novel debugging method called Code-SPA, which aligns noisy code with the well-structured style familiar to LLMs, mitigating the impact of stylistic inconsistencies. Specifically, Code-SPA extracts the model’s preferred coding style from a reference snippet, then adjusts the input code by Concrete Syntax Tree (CST)-based transformations and LLM-assisted refinements before debugging. By aligning the code style preference, Code-SPA enhances the debugging performance of both code-specific and general-purpose LLMs on both poorly and well-styled code across the HumanEval, MBPP and EvalPlus datasets.

Introduction

While Large Language Models (LLMs) have revolutionized automated code generation and repair, they exhibit a surprising sensitivity to the stylistic quality of their input. Most existing research evaluates these models on "clean," well-structured code. However, real-world software development is characterized by "noisy" code—snippets with inconsistent naming conventions, non-standard indentation, or redundant logic.

Impact of code style on LLM debugging performance.

As illustrated in Figure 1, an LLM that successfully debugs a well-styled function may fail when presented with the exact same logic written in a cryptic, poorly formatted style. This "stylistic noise" acts as a cognitive distractor, causing the model's debugging performance to drop significantly. The core challenge addressed by this research is making LLM-based debugging robust to the messy reality of human-authored code.

Methodology: The Code-SPA Pipeline

To address this brittleness, we introduce Code-SPA (Style Preference Alignment), a framework that reformats buggy code to match a model's internal "style preference" before attempting a fix. The process follows a three-stage pipeline:

The three-stage Code-SPA pipeline: Style Extraction, Style Preference Alignment, and Code Debugging.
  1. Style Extraction: The system first prompts the LLM to solve the target task independently to generate a "Reference Code" snippet. This snippet represents the model's "natural" coding style. Using a Concrete Syntax Tree (CST) parser and rule-based matching, Code-SPA extracts specific stylistic features such as indentation length, naming conventions (e.g., snake_case), and comment placement.
  2. Style Preference Alignment: The buggy input code is then transformed to align with the extracted style. This involves deterministic structural alignment (fixing indentation and spacing via LibCST) and LLM-assisted refinement, where the model rewrites the code to adopt preferred semantic styles (like descriptive variable names) while strictly preserving the original logic and the underlying bug.
  3. Code Debugging: Finally, the LLM receives the aligned, "cleaned" buggy code along with the failing test case to perform the actual repair.

Experimental Setup

We evaluated Code-SPA across several benchmarks, including HumanEval, MBPP, and their more rigorous counterparts in EvalPlus. To test robustness, we created synthetic "noisy" datasets by injecting eight types of perturbations, ranging from removing semantic meaning in variable names (NoSems) to adding redundant print statements (RedStmts). We also tested the framework on real-world human-authored bugs using HumanEvalPack-Fix and cross-language generalization with HumanEval-X-C++.

Key Results and Insights

Code-SPA demonstrates superior performance and robustness across various models and scenarios:

  • Superior Performance: On the MBPP+ dataset using DeepSeek-Coder-6.7B, Code-SPA achieved a 65.3% Pass@1 score, outperforming the vanilla debugging baseline (64.6%) and significantly exceeding advanced methods like INTERVENOR (61.9%).
  • Consistency Across Models: The benefits were consistent across multiple model families, including Llama 3 (8B), Qwen 2.5 (7B), and CodeLlama (13B).
  • Robustness to Mixed Noise: While standard debugging methods saw performance drops of 5-7% when multiple noise types were combined, Code-SPA remained stable, typically showing less than a 1% decline.
  • The Importance of Naming: Analysis revealed that "semantic noise"—the loss of descriptive variable names—is the most detrimental factor for LLM debugging, far outweighing structural issues like poor indentation.

Conclusion

Code-SPA bridges the stylistic gap between human-written code and the internal preferences of LLMs. By "speaking the model's language," Code-SPA reduces the cognitive load on the LLM, allowing it to focus on logical repair rather than parsing messy syntax. While the method introduces some computational overhead due to additional LLM calls, the resulting gains in debugging accuracy and robustness make it a promising approach for real-world automated software engineering.

Summary updated

BibTeX
@inproceedings{wen2025code,
  author = {Tengfei Wen and Xuanang Chen and Ben He and Le Sun},
  title = {{Code-SPA: Style Preference Alignment to Large Language Models for Effective and Robust Code Debugging}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2025},
  url = {https://openreview.net/forum?id=m4VWI1nbpF},
}
Figure