How to Evaluate the Long-Horizon Engineering Capability of AI Coding Models
A practical framework for assessing whether AI coding models can sustain multi-turn, end-to-end work in real codebases: four evaluation dimensions, two task archetypes, common failure modes such as broken permission isolation, engineering practices to catch them, and a review checklist for adopting model-generated code in production.
1. Why Long-Horizon Tasks Matter for Evaluating Coding Models
The quality of a single completion or a single generated function no longer meaningfully differentiates models. What teams actually care about is whether a model can continuously work through a task inside a real project—with multiple modules, historical baggage, and security requirements—and deliver something that runs, can be tested, and can be handed over to a human. This capability can be called long-horizon coding capability.
When evaluating long-horizon capability, public leaderboard scores should only be used as a reference. Leaderboards typically rely on fixed problems and automated grading, which struggle to capture the following:
- Whether context remains accurate after dozens of interaction turns;
- Whether changes follow the existing directory structure, naming conventions, and interface contracts;
- Whether the model can diagnose the root cause from error messages instead of repeatedly trying the same fix;
- Whether the final state can be started, tested, and deployed directly.
Therefore, evaluation should focus on end-to-end completion in real engineering settings.
2. Breaking Down the Evaluation Dimensions
It is recommended to decompose long-horizon coding capability into four observable dimensions, each with clear pass criteria.
- Context understanding. The model should read the relevant files, locate entry points and dependency relationships, and only then start modifying code. You can record which files the model reads in its first pass to judge whether it identified the critical modules.
- Cross-module consistency. A single feature usually spans data structures, database migrations, the API layer, background jobs, and frontend pages. Checkpoints include whether field names, status enums, and error codes stay consistent across layers. For example, the number of field discrepancies between API documentation, data models, and frontend type definitions should be zero.
- Execution and verification. The deliverable should start up and pass unit tests, API tests, and the necessary end-to-end tests. UI features need to be exercised end to end in a real browser.
- Boundary and security awareness. Whether the model proactively considers constraints such as permissions, input validation, and resource isolation matters more than whether it can write the feature itself.
3. Designing Test Tasks
To cover both “understanding an existing system” and “turning documentation into a product,” test tasks can be designed in two categories.
Task 1: Adding a Constrained Feature to a Legacy Project
Suppose a project that has been running for years needs to support user-uploaded image assets, which can then be referenced in an interactive animation scenario. The requirement looks simple, but it involves the following constraints:
- Limits on the type, size, and quantity of uploaded files;
- Users can only access resources they uploaded themselves;
- The animation scenario is rendered via HTML and must prevent script injection;
- Asset paths must not be constructible in a way that reads other files on the server.
This kind of task tests whether the model can implement security constraints in code without breaking legacy logic.
Task 2: From Documentation to a Fully Playable Mini-App
The second type of task provides only a technical learning document and a product requirements document. The model must decompose the knowledge points on its own, design levels, implement the rules and progress persistence, and ultimately produce a learning mini-game that can be completed from start to finish.
This type of task tests document comprehension, requirement translation, and the ability to close the product loop. Evaluation should check whether the knowledge points are accurate, whether levels progress in order, whether saves persist after a page refresh, and whether the win condition can actually be reached.
4. General Observations from Real Testing
The fact that both task types can be completed to a runnable state shows that long-horizon coding capability can already support feature development at a medium scale. But there is still a gap between “runnable” and “shippable.”
In the first task type, the code passed the existing tests and the demo worked normally. During manual acceptance, however, a permission isolation problem surfaced: one resource endpoint only checked login status, not resource ownership, so any logged-in user could read other users’ assets by guessing identifiers. The automated tests did not cover this case because they only used a single account.
This case illustrates three points:
- Tests cover scenarios that have already been imagined; security vulnerabilities tend to live in the ones that have not;
- Permission logic should be an independent checklist item, not something verified incidentally through functional tests;
- For permissions, data isolation, and final delivery, manual acceptance cannot be skipped.
In the second task type, the main problems were the accuracy of how knowledge points were phrased and the reward logic of certain levels. These issues likewise require item-by-item manual review.
5. Engineering Practices for Permission Isolation and Asset Security
The problems above can be intercepted early through engineering measures. Below are several general practices.
1. Resource Access Must Verify Ownership
Every resource query should carry both the resource ID and the current user ID, with filtering done at the data layer.
def get_asset(asset_id: str, current_user_id: str, repo) -> Asset:asset = repo.find_by_id(asset_id)# Return "not found" for both missing and unauthorized resources,# to avoid revealing whether the resource existsif asset is None or asset.owner_id != current_user_id:raise NotFound("asset not found")return asset
2. Validate Uploaded Files at Multiple Layers
Relying on the file extension alone to determine file type is unreliable. It is recommended to also check file size and the file header (magic bytes), and to replace the stored filename with a server-generated random identifier.
ALLOWED_TYPES = {b"\x89PNG": "image/png", b"\xff\xd8\xff": "image/jpeg"}MAX_SIZE = 5 * 1024 * 1024 # 5 MBdef detect_image_type(head: bytes) -> str | None:for magic, mime in ALLOWED_TYPES.items():if head.startswith(magic):return mimereturn None
A real implementation should cover more image formats and limit pixel dimensions to guard against decompression-bomb-style resource attacks.
3. Prevent Path Traversal
When asset paths are influenced by user input, they must first be resolved to absolute paths and then confirmed to stay within the allowed root directory.
from pathlib import Pathdef safe_resolve(base_dir: str, relative: str) -> Path:base = Path(base_dir).resolve()target = (base / relative).resolve()if not target.is_relative_to(base):raise ValueError("path escapes storage root")return target
4. Isolate HTML Animation Scenarios
Pages used to render animations should run in a restricted environment and must not be able to access the main site’s login state. Common measures include:
- Using the iframe
sandboxattribute and removing unnecessary permissions; - Restricting external scripts and network requests through a Content Security Policy (CSP);
- Injecting assets as controlled URLs or data, rather than concatenating raw HTML from user input.
<meta http-equiv="Content-Security-Policy"content="default-src 'none'; img-src 'self' blob:; style-src 'unsafe-inline'; script-src 'self'">
The policy above is only a starting point; the actual values need to be adjusted based on the script and resource origins the scenario genuinely uses.
6. How to Manage Long-Horizon Coding Tasks
Getting a model to complete long tasks requires process management in addition to model capability.
- Task decomposition. Break requirements into independently verifiable milestones, each of which should leave the system in a runnable state.
- Write acceptance criteria first. Before coding, turn permissions, boundary inputs, and error paths into test cases, and let the model work toward passing them.
- Record changes. Require each round of changes to come with a change note covering the files modified, the rationale, and risks not yet covered.
- Tiered authorization. The model may modify business code, but changes involving secrets, permission configuration, and deployment scripts should require human approval.
- Retain audit trails. Keep the model’s operation logs and per-round test results so the source of problems can be traced afterwards.
7. A Review Checklist for Team Adoption
Before merging model-generated code into the main branch, teams should run through a consistent review checklist covering at least: ownership checks on every resource access, multi-layer validation on file uploads, path resolution against a fixed root, sandboxing and CSP for any HTML rendering surface, and manual acceptance for anything involving permissions or data isolation. Automated tests are the foundation, but the checklist is what closes the gap between “runnable” and “shippable.”
