TL;DR
AdaptEval is the first dedicated benchmark designed to evaluate how well Large Language Models (LLMs) adapt code snippets mined from Stack Overflow to fit specific target GitHub repositories. The benchmark reveals that while modern LLMs excel at simple interface adjustments, they struggle with complex logic customization and frequently prioritize their pre-training biases over explicit user instructions.
What Problem Does This Paper Address?
Software developers frequently reuse code snippets from online communities like Stack Overflow. However, these snippets rarely work out-of-the-box; they must be adapted to fit the naming conventions, architectural patterns, and logic of the target codebase.
While LLMs have shown impressive capabilities in code generation (e.g., writing functions from scratch) and program repair, their ability to perform context-aware code adaptation has remained largely unassessed. Existing benchmarks either evaluate isolated code generation (like HumanEval) or full repository-level issue resolution (like SWE-bench), missing the nuanced middle ground of snippet transplantation.
Building an adaptation benchmark is uniquely challenging because real-world developer intents and step-by-step adaptation requirements are rarely documented in commit histories. AdaptEval addresses this gap by reconstructing real-world adaptation tasks with multi-granularity annotations and fine-grained test suites.
Methods
The authors constructed AdaptEval using a rigorous bottom-up pipeline:
- Reuse Case Collection: They mined over 2,400 Python repositories on GitHub to find functions containing explicit Stack Overflow links. They paired these functions with the corresponding online code snippets.
- Clone Detection & Cleaning: Using the SourcererCC tool, they filtered out exact matches (Type-I clones) and kept only snippets that underwent actual modifications (Type-II and Type-III clones).
- Adaptation Extraction: They utilized the AST-differencing tool
GumTreeto break down code changes into distinct, localized edits. - Multi-Granularity Annotation: Human annotators categorized and described the edits at two levels: Task-level (high-level developer intentions) and Adaptation-level (step-by-step instructions).
- Two-Tier Testing Framework: To evaluate LLM outputs, they built a testing framework consisting of function-level tests (to check overall code correctness) and adaptation-level tests (using mock objects to verify if specific, intermediate edits were executed correctly).
Datasets
The paper introduces AdaptEval, a benchmark consisting of:
- 164 adaptation tasks written in Python.
- 523 individual adaptations categorized into three taxonomies: Method Signature (MS), Logic Customization (LC), and Refactoring (RE).
- 1,079 manually constructed unit tests achieving high test sufficiency (92.95% branch coverage and 94.38% line coverage).
Key Insights and Ideas
- The Instruction-Following Conflict: LLMs suffer from a tug-of-war between their internal pre-training knowledge and external instructions. For example, when explicitly told to name a method using
camelCaseor a specific string, models often default back to standard Pythonsnake_casedue to strong biases picked up during pre-training. - Granularity Matters: LLMs perform drastically better when given step-by-step instructions rather than high-level goals. They struggle to reason out an entire adaptation strategy independently.
- Reasoning Models Overthink: Advanced reasoning models (like DeepSeek-R1) significantly outperform standard models when no instructions are provided because they can infer intent from context. However, when given explicit instructions, they sometimes fail because they "overthink" the prompt, second-guessing the user instructions and falsely assuming the developer made a mistake.
Key Results
The authors evaluated six instruction-tuned LLMs (including GPT-4o, DeepSeek-V3, Gemini-2.0-Flash) and three reasoning LLMs (DeepSeek-R1, Claude-3.7-Sonnet, QwQ-32B):
- Overall Performance: In the most ideal setting (where models receive full repository context and step-by-step instructions), LLMs successfully solved between 34.15% and 59.15% of the tasks. GPT-4o achieved the highest overall task-level correctness (59.15%).
- The Instruction Boost: Providing step-by-step adaptation instructions (AReq) instead of high-level task descriptions (TReq) yielded a massive performance leap, increasing the
pass@1rate by an average of 34.84%. - Type-Specific Strengths: LLMs excel at modifying Method Signatures (up to 86.87% accuracy for GPT-4o) but struggle heavily with Logic Customization (dropping to ~64%), which requires deeper semantic understanding.
- Reasoning LLM Superiority in Zero-Requirement Settings: When forced to adapt code blindly without any explicit requirements (the
NoReqsetting), reasoning models like DeepSeek-R1 improved thepass@1score by up to 102% compared to standard models, demonstrating a superior capacity to read implicit contextual cues from the codebase.
Limitations and Future Work
- Language Constraint: AdaptEval is currently limited strictly to Python codebases.
- Source Constraint: The benchmark only evaluates the pipeline of moving code from Stack Overflow to GitHub, ignoring other common reuse sources (like internal documentation or alternative forums).
- Scale: While highly curated, the benchmark contains 164 tasks, which the authors plan to expand to cover more diverse real-world software engineering scenarios and multiple programming languages.
Summary updated