Evaluating AI Coding Ability: From Contamination Control to Reliable Verification

    Code generation benchmarks built on public repositories suffer from data contamination, narrow task distribution, and low difficulty, making scores unreliable. This article explains how to design a trustworthy evaluation system covering zero-contamination task construction, diversity and complexity metrics, verifier error control, and sound statistical reporting, with practical guidance for building internal benchmarks.

    1. Why Code Ability Evaluation Needs a Redesign

    Evaluation of code generation models has long relied on historical issues and patches from public repositories. This approach has three obvious flaws.

    First, evaluation data easily leaks into training corpora. Code, issues, and commit histories from public repositories are crawled at scale. If test problems or their reference solutions appear in training data, a model’s score may reflect memorization rather than the ability to solve new problems.

    Second, the task distribution is too concentrated. A large share of problems comes from a small number of popular projects, and the languages and problem types skew toward common scenarios. Such datasets can hardly reflect the diversity of real enterprise codebases.

    Third, tasks lack difficulty and scores have low discriminative power. When most problems are small, single-file fixes, all kinds of models achieve similar results. Scores get compressed into a narrow band, and ranking changes are easily masked by random fluctuation.

    A credible evaluation system must therefore address four problems at once: contamination, diversity, complexity, and verification reliability. Missing any one of them makes scores unreliable as a basis for engineering decisions.

    2. Constructing Zero-Contamination Tasks

    The core of zero contamination is ensuring that problems are created after the model’s training data cutoff, or written entirely from scratch by the evaluation team. Common practices include:

    • Having engineers rewrite requirements and defects based on real development scenarios, rather than copying public issues directly;
    • Keeping a construction record for each problem, including creation time, reference implementation, and dependency versions;
    • Running overlap detection between problem text and public corpora; problems exceeding the threshold go to manual review or are discarded.

    The example below uses n-gram overlap ratio as a rough check of whether problem text resembles corpus content. In practice, the corpus is very large and requires indexing or hashing for acceleration.

    1. def ngram_set(text: str, n: int = 13) -> set[str]:
    2. tokens = text.split()
    3. return {" ".join(tokens[i:i + n]) for i in range(len(tokens) - n + 1)}
    4. def overlap_ratio(task_text: str, corpus_docs: list[str], n: int = 13) -> float:
    5. task_grams = ngram_set(task_text, n)
    6. if not task_grams:
    7. return 0.0
    8. hit: set[str] = set()
    9. for doc in corpus_docs:
    10. hit |= task_grams & ngram_set(doc, n)
    11. return len(hit) / len(task_grams)

    Detection results can only serve as a screening signal. A low overlap ratio does not prove a problem was never seen during training, so it must be combined with time-window checks and manual review.

    3. Improving Diversity and Real-World Complexity

    3.1 Multi-Dimensional Task Coverage

    A problem set should cover at least the following dimensions:

    Dimension Examples
    Programming language Multiple mainstream languages, including statically and dynamically typed ones
    Repository source Multiple independent projects, avoiding a single code style
    Task type Bug fixes, feature extensions, refactoring, test completion
    Context scale From single-file edits to cross-module, multi-file changes

    When diversity is insufficient, a model may perform well on one language or one type of problem while hiding weaknesses elsewhere. Reporting scores stratified by dimension makes these differences visible.

    3.2 Quantifying Complexity

    Complexity should not rely on subjective judgment alone. Objective metrics can be recorded for each problem:

    • The number of files and lines of code that need modification;
    • The number of modules involved in the fix path;
    • The length of context that must be read to understand the problem;
    • The number of key decision points in the reference solution.

    Only when these metrics span a wide range can the problem set separate models of different capability levels.

    4. Verifier Design and Sources of Error

    The verifier decides whether a problem passes. Its errors directly change rankings, so it matters as much as the problems themselves.

    False positives occur when an incorrect patch is judged as passing. Common causes are overly loose test assertions or tests that fail to cover edge cases. A model may fix only the surface symptom and still pass the tests.

    False negatives occur when a correct patch is judged as failing. Common causes include tests that depend on implementation details, unstable environments, unreasonable timeout thresholds, or defects in the tests themselves.

    Common methods for reducing error include:

    1. Maintaining a set of hidden tests that are not publicly visible, and updating them regularly;
    2. Manually reviewing critical problems to check whether tests only verify implementation details;
    3. Running tests in a fixed container environment, locking dependency versions and random seeds;
    4. Counting timed-out cases separately instead of directly marking them as failures.

    The example below shows how to run a test command in a subprocess. The command is passed as a list without shell parsing to avoid injection risks.

    1. import subprocess
    2. def run_hidden_tests(repo_dir: str, test_cmd: list[str], timeout: int = 600) -> bool:
    3. env = {"PATH": "/usr/bin:/bin", "PYTHONHASHSEED": "0"}
    4. try:
    5. proc = subprocess.run(
    6. test_cmd,
    7. cwd=repo_dir,
    8. capture_output=True,
    9. text=True,
    10. timeout=timeout,
    11. env=env,
    12. )
    13. return proc.returncode == 0
    14. except subprocess.TimeoutExpired:
    15. return False

    This example still needs to be combined with container isolation and resource limits. In production, evaluation code should run in a sandbox isolated from the host, with network access restricted.

    5. Statistical Methods and Interpreting Results

    The pass rate of a single run involves randomness. The same model may differ by several percentage points across runs. Therefore, when reporting results:

    • Sample each problem multiple times and take the average pass rate;
    • Report confidence intervals instead of a single number;
    • Report results under different inference budgets separately;
    • Label the dataset version to avoid direct cross-version comparisons.

    The example below uses the Wilson interval to estimate the confidence range of a pass rate, which is more stable than the normal approximation for small samples.

    1. import math
    2. def wilson_interval(passes: int, trials: int, z: float = 1.96) -> tuple[float, float]:
    3. if trials == 0:
    4. return (0.0, 0.0)
    5. p = passes / trials
    6. denom = 1 + z**2 / trials
    7. center = (p + z**2 / (2 * trials)) / denom
    8. half = z * math.sqrt(p * (1 - p) / trials + z**2 / (4 * trials**2)) / denom
    9. return (center - half, center + half)

    If two models’ confidence intervals overlap substantially, their ranking difference should not be over-interpreted. Leaderboard position changes need to be read together with interval width and dataset version.

    6. Recommendations for Team Adoption

    Public benchmarks provide a reference, but teams need internal evaluations tailored to their own codebases. The following steps can guide the process:

    1. Select problem sources: Extract tasks from internal repositories’ historical defect tickets and code review records, ensuring data is properly anonymized;
    2. Define acceptance criteria: Write tests for each problem, specify pass conditions clearly, and record the reference solution;
    3. Build a pipeline: Automate problem loading, model invocation, patch application, test execution, and result aggregation into one workflow;
    4. Run regular regressions: After switching models or adjusting prompts, re-evaluate with the same problem set and compare confidence intervals;
    5. Keep manual spot checks: Sample a proportion of passing results in each round to check for false positives.

    The goal of evaluation is to support engineering decisions. As long as problems are trustworthy, verification is reliable, and statistics are rigorous, evaluation results can genuinely reflect a model’s value in real development work.