Evaluating Long-Horizon Coding: From Legacy Refactoring to Secure Acceptance
A practical framework for evaluating how well AI coding models handle long-running engineering tasks, including legacy-code changes, cross-module consistency, runnable delivery, security constraints, and human acceptance. It covers secure asset uploads, end-to-end product implementation, permission isolation, automated verification, and the limits of model-generated code.
Introduction
AI-assisted programming has evolved from single-file completion to cross-module, long-horizon engineering tasks. Models must understand existing code, apply consistent changes across multiple components, and leave the system in a runnable and testable state. Compared with short tasks, long-horizon work is more likely to expose problems such as lost context, forgotten assumptions, or attempts to bypass constraints simply to make tests pass.
This article presents an evaluation framework for engineering teams. It covers key evaluation dimensions, two representative scenarios, and the boundaries of human acceptance.
1. What to Evaluate in Long-Horizon Coding
Leaderboard scores measure average performance on standardized tasks, but they do not always reflect performance in real-world projects. Engineering teams should focus on four dimensions.
1.1 Context Understanding
After reading an existing codebase, can the model identify established conventions such as directory structure, naming style, error-handling patterns, and data flow?
A useful test is to provide a requirement that must be implemented by following the existing logic. Observe whether the model reuses established utility functions or creates a separate implementation of the same capability.
1.2 Cross-Module Consistency
A single feature may involve data structures, database migrations, APIs, background jobs, and frontend pages. Evaluation should verify that fields are aligned across layers and that state transitions are complete.
A common failure mode occurs when an API is updated but the frontend or a background task continues to read the old data structure.
1.3 Runnable and Testable Delivery
“Runs successfully” is the baseline. Dependencies, builds, startup procedures, and core workflows must be reproducible in a clean environment.
Passing tests is necessary but not sufficient. Teams should also verify whether the tests genuinely cover the new logic and whether assertions were modified merely to accommodate the implementation.
1.4 Constraint Compliance
Security, authorization, performance budgets, and compliance requirements are hard constraints. They should be stated explicitly in the task description and verified separately during acceptance. Functional tests alone should not be expected to cover them.
2. Scenario One: Safely Introducing User Assets into a Legacy Codebase
A representative requirement is to let users upload image assets and reference them in HTML animation scenes. The main risks are file-type spoofing, path traversal, and unauthorized access to referenced resources.
2.1 Upload Validation Should Be Layered
A file extension is only a hint and must not be the sole validation method. A reasonable implementation should include:
- Checking that the extension is on an allowlist;
- Verifying that the file header, or magic bytes, matches the extension;
- Limiting file size before storage;
- Storing files in a dedicated directory;
- Generating filenames on the server instead of using user-supplied names.
The following is an illustrative implementation using only the Python standard library:
from pathlib import PathALLOWED_SUFFIXES = {".png", ".jpg", ".jpeg", ".gif"}MAX_SIZE = 5 * 1024 * 1024 # 5 MBMAGIC = {".png": b"\x89PNG\r\n\x1a\n",".jpg": b"\xff\xd8\xff",".jpeg": b"\xff\xd8\xff",".gif": b"GIF8",}def validate_upload(path: Path, upload_root: Path) -> None:resolved = path.resolve()# Prevent path traversal: the target file must be inside the upload root.if upload_root.resolve() not in resolved.parents:raise PermissionError("Path traversal detected")suffix = resolved.suffix.lower()if suffix not in ALLOWED_SUFFIXES:raise ValueError("Unsupported file type")if resolved.stat().st_size > MAX_SIZE:raise ValueError("File is too large")# Verify that the file content matches its extension.with resolved.open("rb") as f:head = f.read(8)if not head.startswith(MAGIC[suffix]):raise ValueError("File content does not match its extension")
This code is only a starting point for the validation layer. A production system may also require malware scanning, image re-encoding, and storage quotas. The appropriate combination depends on the application’s threat model.
2.2 Use IDs for References Instead of Paths
HTML scenes should reference an asset’s internal ID. The server can resolve that ID to a controlled URL during rendering.
This prevents users from placing arbitrary paths directly in scene content and makes it easier to handle asset deletion or permission changes consistently.
2.3 Isolate the Rendering Environment
An animation page is effectively executable frontend code. Rendering should take place in a restricted sandbox, with a Content Security Policy (CSP) used to limit external scripts and network requests.
Asset URLs should be restricted to the same origin or to explicitly approved storage domains.
2.4 Perform Authorization Checks on the Server
Hiding a button in the frontend is not access control. Every time an asset is read, a preview is generated, or a scene is exported, the server should verify that the current user belongs to the workspace or project associated with that asset.
3. Scenario Two: From Learning Materials to a Playable Product
Another type of task provides only learning materials and a product requirements document, then asks the model to build a learning game that users can experience from start to finish.
This scenario evaluates requirements decomposition and product implementation, so its evaluation priorities differ from those of the first scenario.
3.1 Decompose Before Coding
The model should first produce a module list covering the level structure, knowledge-point mapping, state storage, scoring rules, and completion conditions.
After decomposition, each module can be implemented separately, with verifiable acceptance criteria defined for each one. Generating the entire codebase without first breaking down the work often leads to substantially higher rework costs later.
3.2 Completion Conditions Must Be Automatically Verifiable
“Users can actually complete the game” should be converted into executable checks, such as:
- A complete path from the starting point to the endpoint is traversable;
- Every key branch has a clearly defined outcome and feedback;
- After save-state restoration, the state matches the state before interruption;
- Invalid input does not leave the workflow stuck.
Using a script to simulate the complete flow is more reliable than performing a few manual clicks and also makes regression testing easier.
3.3 Content Accuracy Requires Independent Review
When concepts from learning materials are restated in questions and hints, meaning can drift. Teams should maintain a mapping between knowledge points and questions, then review each mapping manually or with independent validation logic.
This helps prevent inaccurate explanations from becoming part of the product.
4. Common Root Causes of Authorization Isolation Issues
Feature completeness does not guarantee correct authorization. Permission problems often remain in peripheral code paths. Common root causes include:
- Authorization checks are implemented only in the UI, with no validation at the API layer;
- Asset queries omit tenant or project conditions, allowing unauthorized reads;
- Cache keys do not include user context, causing different users to receive the same result;
- Exception branches return detailed error messages that expose internal paths or data structures;
- Batch APIs omit checks that already exist in single-item APIs.
During acceptance, teams can use two test accounts for cross-account verification. Account A should attempt to access Account B’s asset IDs, scenes, and export results. Each attempt should be rejected with a consistent error response.
These tests should be included in the automated test suite and run during regression testing after every relevant change.
5. The Boundaries of Human Acceptance
The primary value of models in long-horizon tasks is reducing repetitive work, accelerating cross-module changes, and completing test cases. The following areas still require human ownership:
- Final confirmation of the authorization model and data-isolation strategy;
- Security review of code, especially input handling, file operations, and rendering logic;
- Execution of user-data migrations and irreversible operations;
- Decisions about business rules and content accuracy.
A team should treat model output as a draft that requires review. Acceptance criteria should be defined in advance, and completion should be determined by people against those criteria—not declared by the model itself.
6. Practical Recommendations
- Write structured task descriptions for long-horizon work, including goals, constraints, non-goals, and acceptance cases.
- Add security checks to the continuous integration pipeline, such as dependency scanning, static analysis, and authorization regression tests.
- Preserve rollback points at each stage so problems can be isolated after broad changes.
- Record the scope of every change so that human reviewers can inspect the work incrementally.
