TL;DR
Current code completion benchmarks evaluate large language models (LLMs) on coarse, isolated tasks that fail to reflect real-world software development. This paper introduces Codev-Bench, a developer-centric, repository-level benchmark automatically generated by an agentic system (Codev-Agent) using insights from actual industrial usage data. The framework evaluates LLMs across fine-grained scenarios, revealing critical gaps in how models handle context and generation boundaries.
What Problem Does This Paper Address?
While LLMs excel at generating standalone functions or classes (as tested by classic benchmarks like HumanEval), real-world code completion is a different beast. Developers usually trigger completion tools mid-line or mid-block, requiring the tool to understand both the preceding code and the trailing context (the suffix).
Existing benchmarks suffer from three major flaws:
- Coarse Granularity: They treat code completion like general code generation rather than the granular, line- or block-level suggestions developers actually encounter.
- High Maintenance Costs: They rely heavily on manual human annotation, making it difficult to update benchmarks and avoid data leakage as LLMs train on newer open-source code.
- Lack of Execution Context: Standalone test cases fail to leverage repository-level context and existing unit tests to verify if the generated code actually works.
To bridge this gap, the authors analyzed real user data from an industrial code assistant to redefine evaluation criteria and built an automated pipeline to generate realistic test cases.
Methods
The authors first analyzed business data from Alibaba's TONGYI Lingma code assistant to map out real-world usage patterns, discovering that nearly half of all completions are full lines and 68.51% are general statements rather than entire functions.
Using these insights, they developed Codev-Agent, an automated, agent-based system designed to construct the benchmark without human intervention:
- Automated Crawling: It discovers up-to-date, highly-starred, non-forked repositories.
- Environment Setup: It leverages an LLM (Qwen) to read README files, generate environment installation commands, and iteratively debug setup errors until the repository's unit tests run successfully.
- Hybrid Call Chain Analysis: It combines static Abstract Syntax Tree (AST) parsing with dynamic data flow tracing during unit test execution to map out how code components interact.
- Sample Generation: It automatically masks specific code blocks (statements, loops, functions) that are actively triggered by unit tests, creating realistic completion prompts.
Datasets
The paper introduces Codev-Bench. The initial release evaluates models across 10 Python repositories containing 862 code files and 191 existing test cases. This pipeline yields 296 distinct code blocks evaluated across four distinct developer scenarios:
- Full Block Completion: Completing a block given unbroken surrounding context.
- Inner Block Completion: Completing a partial block (including cases where no completion is needed).
- Incomplete Suffix Completion: Completing code when the subsequent code in the file is missing or incomplete.
- RAG-Based Completion: Utilizing a Retrieval-Augmented Generation module to pull relevant context from other files in the repository.
Key Insights and Ideas
- The "Stopping" Struggle: A major user experience issue identified is that LLMs often struggle with stopping criteria. Even when they generate the correct code, they continue generating extraneous lines, which breaks unit tests and frustrates developers.
- Edit Similarity is Deceptive: The authors found that Edit Similarity (Levenshtein distance) correlates poorly with actual functional correctness (test pass rates) in three out of four scenarios. A model might achieve a high similarity score but fail completely due to a single incorrect character or an extra block.
- Specialized Code LLMs Rule: Smaller, specialized code models operating in Fill-In-the-Middle (FIM) mode consistently outperform massive general-purpose LLMs because they are natively architected to handle both prefix and suffix context.
Key Results
The authors evaluated several state-of-the-art models using the Pass@1 metric (whether the first generated snippet passes the unit tests):
- Full Block Completion (Scenario 1): Specialized code models dominated. Codegemma-7b led with an average Pass@1 of 53.85%. General LLMs completely failed (0.00%) at function-level completions, with the exceptions of GPT-4 (15.38%) and GPT-4o (23.08%).
- Inner Block Completion (Scenario 2): Code LLMs excelled here, with Deepseek-coder-v2-lite scoring a perfect 100% on function completions, and Codegemma-7b leading overall at 77.36%.
- The Suffix Bottleneck (Scenario 3): When the trailing suffix was missing or incomplete, performance cratered across the board. Codegemma-7b still held the top spot but only managed a meager 6.86% average Pass@1, highlighting a massive blind spot in current LLM capabilities.
- RAG Effectiveness (Scenario 4): Providing repository context via RAG boosted general LLM performance significantly; Llama-3.1-405b jumped to a 40.38% pass rate, though it still trailed Codegemma-7b (55.77%).
Limitations and Future Work
The primary limitation of the current Codev-Bench release is its exclusive focus on the Python language. Additionally, the repository scale is currently restricted to 10 repositories due to storage and environment overhead constraints.
Moving forward, the authors plan to extend Codev-Agent to support multiple programming languages to build a diverse, multilingual dataset, while refining the agent to capture even more complex, multi-file developer workflows.
Summary updated