Long-Horizon Coding with Large Language Models: Capability Boundaries and Security Acceptance
Long-horizon coding tasks go beyond single-turn code completion: they require models to understand large codebases, coordinate changes across modules, run tests, and follow security constraints over multiple iterations. This article presents a practical evaluation framework, two representative implementation cases, a manual acceptance checklist, and team practices for safely adopting AI coding tools.
Why Long-Horizon Coding Requires Separate Evaluation
Single-turn code completion measures local generation quality. Real engineering tasks often span multiple files and modules, involve several rounds of changes, and require the result to run and pass tests. These tasks can be described as long-horizon coding.
The challenge is not simply producing a correct function. The model must preserve a consistent understanding of the goal, constraints, and existing code throughout a long execution chain.
Public benchmark scores are useful references, but they are not sufficient. Benchmark problems usually have clear boundaries, while enterprise projects often contain legacy complexity: inconsistent naming, undocumented conventions, and security rules distributed across multiple parts of the codebase. Teams should therefore evaluate models on their own production-like projects and record performance at each stage.
Five Dimensions for Evaluating Long-Horizon Coding
Evaluation can focus on the following five dimensions:
- Context understanding: Can the model locate the relevant modules and identify existing interface conventions and data structures?
- Cross-module consistency: When the data model changes, are the API, storage layer, frontend, and asynchronous jobs updated consistently?
- Run-and-test loop: Does the model actively run tests, use failure information to locate problems, and fix them instead of merely outputting code?
- Constraint compliance: Does it follow established rules for authorization, input validation, encryption, and other security controls?
- Traceability: Does it explain the scope of changes, assumptions made, and items that remain unverified?
To make results comparable across experiments, these dimensions can be organized into a weighted scoring rubric:
EVAL_RUBRIC = {"context_understanding": {"weight": 0.20, "check": "Correctly locates relevant modules"},"cross_module_consistency": {"weight": 0.25, "check": "API, storage, and frontend updated consistently"},"run_and_test_loop": {"weight": 0.25, "check": "Tests run successfully and pass"},"constraint_compliance": {"weight": 0.20, "check": "Authorization and security rules are satisfied"},"traceability": {"weight": 0.10, "check": "Changes and unverified items are documented"},}def total_score(scores: dict) -> float:"""Each score ranges from 0 to 1 and is assigned by a reviewer."""return sum(EVAL_RUBRIC[k]["weight"] * scores[k] for k in EVAL_RUBRIC)
Passing all tests does not necessarily mean that an implementation is secure. Test cases often cover only the inputs developers expect. Authorization bypasses and malicious files require dedicated security tests. For this reason, constraint compliance must be evaluated separately.
Case Study 1: Adding User Asset Uploads to a Legacy Project
The goal of this task is to allow users to upload image assets and reference them in HTML animation scenes. The feature itself is relatively simple, but the main risks are concentrated in the upload and rendering paths.
Key risks include:
- File spoofing: A file may use an image extension while actually containing a script or executable content.
- Content injection: SVG and HTML files can contain scripts. Rendering them directly may execute code in the page.
- Unauthorized access: A user may guess an asset identifier and read another user’s uploaded files.
- Path traversal: If a user-controlled filename is concatenated directly into a storage path, it may be used to overwrite or read other files.
Corresponding design requirements include:
- The server should determine the actual file type from its file signature, or magic bytes, rather than trusting the client-provided MIME type.
- Storage keys should be generated by the server instead of using the original filename supplied by the user.
- Animation content should run under a different origin from the main site. An iframe sandbox should limit script capabilities, while a Content Security Policy (CSP) should further restrict resource loading.
- Read requests should always verify resource ownership. Missing resources and unauthorized resources should produce the same response so attackers cannot infer whether a resource exists from response differences.
The following example validates an upload:
import uuidALLOWED_SIGNATURES = {"image/png": [b"\x89PNG\r\n\x1a\n"],"image/jpeg": [b"\xff\xd8\xff"],}MAX_SIZE = 10 * 1024 * 1024 # 10 MBdef validate_upload(content_type: str, data: bytes) -> str:"""Return a server-generated storage key after validation."""if len(data) > MAX_SIZE:raise ValueError("File exceeds the size limit")signatures = ALLOWED_SIGNATURES.get(content_type)if signatures is None:raise ValueError("Unsupported file type")# Check the file header instead of trusting the client declarationif not any(data.startswith(sig) for sig in signatures):raise ValueError("File content does not match the declared type")return f"assets/{uuid.uuid4().hex}"
Ownership checks must also be explicit in the read endpoint:
def get_asset(asset_id: str, current_user_id: str, repo) -> bytes:asset = repo.find(asset_id)# Treat missing and unauthorized resources the same way# to avoid revealing whether the resource existsif asset is None or asset.owner_id != current_user_id:raise LookupError("Resource not found")return asset.read()
This case demonstrates that a model may produce a complete functional implementation while still missing important security constraints. Such requirements should be stated explicitly and verified with dedicated test cases.
Case Study 2: Generating an Interactive Learning Application from Study Materials and a PRD
Another type of long-horizon task provides only technical learning materials and a product requirements document. The model must generate an interactive learning application that users can complete from beginning to end. This tests the complete path from analyzing source material to delivering a working product.
The full workflow usually includes four steps:
- Analyze the materials: Extract key concepts and establish their dependencies.
- Design levels: Map concepts to levels, each with a clear learning objective and assessment method.
- Implement rules: Build unlock conditions, scoring, retries, and completion logic.
- Validate: Use automated tests and actual browser interaction to confirm that the main flow works.
Level unlocking is fundamentally a state-transition problem and can be expressed using set relationships for prerequisites:
PREREQUISITES = {"level_2": {"level_1"},"level_3": {"level_1", "level_2"},"final_boss": {"level_3"},}def can_unlock(level_id: str, passed_levels: set[str]) -> bool:required = PREREQUISITES.get(level_id, set())return required.issubset(passed_levels)
Two problems are especially common in these projects.
The first is factual consistency. Questions and explanations may not match the source materials, so reviewers should compare them against the original content one by one.
The second is reachability. If prerequisite conditions are configured incorrectly, some levels may never be unlocked. Testing should verify that every level has a reachable path and that the complete flow can be followed according to the PRD. Screenshots alone cannot confirm that the application is fully completable.
Manual Acceptance Checklist
Before generated code is submitted, review each item in the following checklist:
| Acceptance item | How to check | Pass criteria |
|---|---|---|
| Authorization isolation | Use another account to access a user’s assets | Access is denied without revealing whether the resource exists |
| Malicious files | Upload files with spoofed extensions and SVG files containing scripts | Files are rejected or safely sanitized |
| Paths and naming | Use filenames containing special characters and path segments | The original filename does not appear in the storage path |
| Rendering isolation | Attempt to read parent-page data from inside the animation | Access fails |
| Functional regression | Run the full test suite and manually complete the primary flow | No new failures |
| Content accuracy | Sample questions and explanations and compare them with the source materials | No factual errors |
| Completion reachability | Follow the PRD level by level and verify unlock conditions | Every level can be reached when its conditions are met |
Issues discovered during acceptance should be documented and incorporated into later prompts or requirement specifications. This reduces the chance of similar problems recurring.
Recommendations for Team Adoption
- Break tasks into smaller steps: Each step should produce a result that can be run and verified. This makes deviations easier to identify and roll back.
- Review security-sensitive code manually: Code involving authorization, encryption, or file handling requires line-by-line human review and targeted tests.
- Protect credentials: Do not place keys or access credentials in the repository or write them to logs.
- Keep change records: Record the scope of each generated change, its assumptions, and unverified items for later review and audit.
- Define responsibility clearly: Models can perform a substantial amount of implementation work, but humans remain responsible for final acceptance.
Overall, current AI coding tools are capable of handling real development tasks that span multiple modules and can be tested in long-horizon coding scenarios. However, authorization, security, and final acceptance still require human oversight.
