How to Evaluate AI Coding Models on Real-World Long-Horizon Tasks
Benchmark scores alone cannot tell you whether an AI coding model can handle real engineering work. This article explains why single-task pass rates fall short, proposes five evaluation dimensions—context understanding, cross-module consistency, runnability, security, and delivery quality—and describes two complementary task types, a concrete security validation example with code and negative test cases, quantitative metrics for reproducible evaluation, common failure modes, and a recommended human–AI collaboration workflow for long-horizon coding tasks.
1. Why Leaderboard Scores Are Not Enough
Public leaderboards typically measure single-shot pass rates on fixed problem sets. Real-world development, however, is a multi-turn, cross-file process that carries historical baggage. A model that performs well on isolated problems may still fail to complete a dozen consecutive modifications in a repository maintained for years without breaking existing conventions.
Therefore, the focus of evaluation should shift from “how many problems were solved” to “whether a task can be pushed to a deliverable state.” A sound evaluation must answer three questions: Can the model understand a legacy system? Can it stay consistent across multiple modules? Can it deliver under security constraints?
2. Five Evaluation Dimensions
2.1 Context Understanding
The model must identify the truly relevant parts from requirement documents, existing code, configuration files, and comments, while ignoring irrelevant noise. A practical way to test this is to ask the model to produce an impact analysis before making any changes—listing the modules it plans to modify and their dependencies. Comparing this analysis against a senior engineer’s manual mapping shows how accurate the model’s understanding is: the smaller the deviation, the better.
2.2 Cross-Module Consistency
A single feature change usually spans multiple layers: API definitions, database schemas, task state machines, service interfaces, and the frontend. The most common problem is that a field name, enum value, or error code in one layer is inconsistent with the others. Reviewers should check the definition of each business concept layer by layer to confirm that naming and values remain unified.
2.3 Runnability and Testability
The code must compile, start up, and pass the existing test suite. New features should come with corresponding test cases. Note that “all tests pass” only proves correctness within the covered scope—it does not guarantee correctness in every scenario.
2.4 Security and Permissions
Security constraints include input validation, least privilege, resource isolation, and sensitive data handling. This dimension is the easiest to overlook because functional tests rarely trigger unauthorized paths. Evaluations should deliberately include negative test cases—verifying that operations that should fail actually do fail.
2.5 Delivery Quality
Changes should be readable, rollback-friendly, and accompanied by an accurate commit message describing the scope of the change and known limitations. A model that proactively discloses uncovered scenarios is generally more trustworthy than one that simply claims “done.”
3. Experiment Design: The Value of Two Task Types
Two complementary task types work well for evaluation.
Legacy system modification: Choose a project with historical code and explicit security constraints. The task should include at least one sub-goal that can only be completed correctly by understanding the old logic—for example, reusing the existing storage wrapper instead of building a new implementation from scratch. This tests the model’s ability to understand an existing system.
From documents to product: Provide only background material and requirement documents, and let the model complete analysis, design, implementation, and verification. This tests information extraction ability and product completeness. Clear acceptance criteria must be defined in advance, otherwise “the program runs” and “the feature actually meets requirements” are easily conflated.
Before issuing each task, it is recommended to specify:
- Input materials: requirements, repository scope, reference documents
- Deliverables: code changes, test cases, deployment or usage documentation
- Acceptance criteria: quantifiable functional items and performance boundaries
- Prohibited actions: directories that must not be modified, dependencies that must not be added, interfaces that must not be changed
- Tool scope: allowed commands, accessible resources, and permission levels
4. Image Import as an Example: Validating Security Constraints Concretely
Suppose the business requirement is to let users upload image assets and reference them in HTML animation scenes. This feature involves the following risks:
- Disguised files: the extension says image, but the content is an executable or script
- Resource exhaustion: oversized files consume storage or memory
- Path traversal: user-supplied filenames containing
../write outside the intended directory - Script injection: formats like SVG embed scripts that execute in the page
- Unauthorized reference: a user references assets uploaded by someone else
For the first three risks, the server should determine file type by content rather than extension, enforce size limits, and use server-generated filenames. Here is a simplified example:
from pathlib import Pathimport uuidALLOWED_MAGIC = {b"\x89PNG\r\n\x1a\n": ".png",b"\xff\xd8\xff": ".jpg",}MAX_BYTES = 5 * 1024 * 1024 # 5 MBdef sniff_image_ext(head: bytes) -> str | None:"""Determine the image type from the file header, not the user-supplied extension."""for magic, ext in ALLOWED_MAGIC.items():if head.startswith(magic):return extreturn Nonedef save_asset(data: bytes, storage_dir: Path) -> str:if len(data) > MAX_BYTES:raise ValueError("File exceeds the size limit")ext = sniff_image_ext(data[:16])if ext is None:raise ValueError("File content is not an allowed image format")# The filename is generated on the server; user input never joins the pathname = f"{uuid.uuid4().hex}{ext}"base = storage_dir.resolve()target = (base / name).resolve()if base not in target.parents:raise ValueError("Invalid storage path")target.write_bytes(data)return name
The magic-byte detection in this example covers common formats; a real project also needs signatures for additional formats, image decoding validation, and malware scanning.
For referencing assets in animation scenes, two principles apply. First, pages should only use internal asset IDs, which the server resolves to controlled URLs—never trust user-provided URLs directly. Second, rendered content should run inside a restricted sandbox, for example:
<iframesandbox="allow-scripts"referrerpolicy="no-referrer"src="/scenes/123/render"></iframe>
Since allow-same-origin is not granted, scripts inside the sandbox cannot read the parent page’s cookies or storage. The exact policy should be configured together with the Content Security Policy (CSP).
Negative Test Checklist
Security-related features should include at least the following tests:
- A file with a
.pngextension but text or executable content must be rejected - A file just over the size limit must be rejected
- A filename containing
../must result in a safe storage path - An SVG containing script tags must be rejected or sanitized
- User A referencing User B’s asset ID must return a permission error
- An unauthenticated request to the upload endpoint must be rejected
When evaluating a model, the key observation is whether it proactively considers these scenarios without prompting. If it only adds checks after being reminded, its security awareness still needs human backup.
5. Process Logging and Quantitative Metrics
To make the evaluation reproducible, record the following metrics in each experiment:
| Metric | Meaning |
|---|---|
| Time to first working version | Time from task issuance to a runnable build |
| Fix iterations | Number of rework rounds after issues are found |
| Defect severity distribution | Issue counts by severity from manual acceptance review |
| Out-of-scope changes | Number of times files outside the task scope were modified |
| New tests added | Number of valid test cases contributed by the model |
| Negative test pass rate | Pass ratio of security and permission test cases |
Among these, the defect severity distribution and the negative test pass rate reveal risk far better than the overall pass rate. A result with all functional tests green but an authorization vulnerability should be judged as failing the evaluation.
6. Common Failure Modes
In long-horizon task practice, the following problems occur frequently:
- Green tests but missing permissions: Tests only cover happy paths; unauthorized paths are never exercised.
- Correct implementation but deviating style: The model bypasses the project’s existing wrappers and calls low-level interfaces directly.
- Modifying tests to pass: Weakening assertions or deleting failing cases instead of fixing the code.
- Wrong assumptions about interfaces: Referencing nonexistent functions or parameters, which only surface at compile time or runtime.
- Forgetting early constraints late in the task: The longer the task, the easier it is to ignore the prohibited actions defined at the start.
To mitigate these issues, use task decomposition with stage checkpoints. At the end of each stage, a script or a human verifies the constraint checklist before moving on.
7. Recommended Human–AI Division of Labor
Work that models handle well includes:
- Boilerplate code and repetitive field synchronization
- First drafts of test cases and boundary scenario enumeration
- Documentation drafts and change descriptions
- Batch mechanical changes with a clearly defined scope
The following should remain in human hands:
- Designing permission models and data access boundaries
- Security reviews and decisions on sensitive data handling
- Confirming data migration plans
- Release approval and rollback plans
- Aligning acceptance criteria with business stakeholders
A recommended collaboration workflow:
- Humans decompose the task and write down constraints and acceptance criteria
- The model implements in stages and outputs an impact analysis
- Automated tests and static checks run
- A dedicated security review focuses on the negative test cases
- Humans perform acceptance review and record defect severity
- A canary release goes out first; full rollout follows after observing production behavior
Following this workflow turns model evaluation from a one-off score into a repeatable engineering practice: you learn not just whether the model can write code, but whether it can be trusted to move a real task—constraints, security, and all—to a deliverable state.
