Long-Horizon AI Coding: A Practical Guide to Evaluation and Secure Delivery

    This guide explains how to evaluate AI coding tools on multi-step engineering tasks. It covers the gap between generating code and delivering a working, secure system, the main difficulties of long tasks, two task types for evaluation, and practical methods for securing user asset imports, verifying learning apps, and running a controlled delivery process.

    1. Shifting the Focus from Generated Code to Trustworthy Delivery

    Once AI coding enters real development workflows, the key question is no longer whether a tool can produce a correct piece of code. The question is whether it can complete complex tasks reliably under existing engineering constraints.

    Real project requirements rarely stand alone. Adding a user asset import feature can affect data structures, API contracts, background jobs, asset storage, page interactions, and the rendering pipeline. A module that works correctly does not mean the whole system works. A system that runs does not mean its permission boundaries and error paths have been verified.

    Four levels need to be distinguished:

    • Code can be generated: The tool produces a local implementation from a description.
    • Features can run: The main flows execute, and modules connect to each other.
    • Requirements can be accepted: Normal, error, and boundary scenarios behave as expected.
    • Results can be delivered: Security, maintenance, monitoring, and rollback meet project requirements.

    These levels cannot replace one another. In particular, “all tests pass” only shows that the system passes the existing test set. It does not prove that the test set covers all critical risks.

    One key lesson from the source material is that a complex task can run successfully while manual review still finds a serious permission isolation defect. This should not be dismissed as a one-off implementation mistake. It is an engineering problem that must be considered when evaluating AI coding ability.

    2. What Makes Long-Horizon Coding Difficult

    1. The challenge is maintaining constraints, not reading more files

    Long tasks come with a large amount of context: requirement documents, existing code, database schemas, API definitions, error logs, and test feedback. Reading this information is only the first step. The harder part is keeping key constraints in mind across multiple rounds of changes.

    For example, a user’s assets must belong to that user. This rule cannot appear only in the upload endpoint. It must also apply to:

    • asset list queries;
    • asset detail reads;
    • scene bindings;
    • background job execution;
    • preview and export;
    • deletion, invalidation, and retries of historical jobs.

    If ownership is checked only at the entry point, later access by resource ID can create an authorization bypass. One core part of long-horizon coding ability is turning a local constraint into an invariant that holds across the entire flow.

    2. Cross-module changes test dependency management

    A requirement might add a new field to an API. That field must then flow through data validation, the persistence model, task messages, execution logic, and frontend state.

    Common failures rarely involve a layer that the tool cannot implement at all. More often, one step in the chain is missing. For example:

    • The API accepts a new parameter, but the background job does not pass it along.
    • The page shows a “processing” state, but cannot recover after a job fails.
    • A database field is added, but historical data has no compatibility strategy.
    • The rendering stage supports new assets, but the export stage still uses old logic.

    When evaluating a tool, therefore, look beyond how many files it changed. Check whether it identified the full dependency chain and whether it proactively handled compatibility.

    3. Continuous progress does not mean continuously adding code

    Effective task progress forms a loop:

    Understand the constraints → plan → implement a local change → run verification → analyze failures → revise the approach.

    If each failure leads only to another patch, the code may eventually run, but it tends to accumulate duplicate logic and hidden branches. A more reliable pattern is that the tool explains why a failure occurred. It should determine whether the cause is an implementation error, a contract conflict, or an ambiguous requirement, and then choose the smallest consistent fix.

    3. Building a More Representative Evaluation with Two Task Types

    1. Modifying an existing system: testing engineering understanding and security boundaries

    Existing projects are well suited to testing whether an AI coding tool respects historical constraints. One representative task is to add user image import to an existing content generation system, and allow animation scenes to reference these images.

    The task should not stop at “support image upload.” It should explicitly state the following conditions:

    • Users can access only their own assets;
    • Untrusted files must not enter the rendering pipeline directly;
    • Upload, validation, storage, and referencing each have clear states;
    • Failed operations can be retried without creating duplicate or dangling records;
    • Existing features remain compatible;
    • Preview and final output apply the same authorization rules.

    This type of task exposes problems that simple coding exercises miss. It shows whether the model truly understands the system’s structure, whether it can trace identity information along the call chain, and whether it bypasses existing constraints to finish faster.

    2. Building a learning app from scratch: testing requirement translation and product completeness

    Another task type provides learning materials and a requirements document, then asks the tool to build a learning app that users can complete from start to finish.

    Here, “complete” does not just mean having a home page, questions, and a results page. Evaluators should also check:

    • Whether learning goals map to specific levels;
    • Whether questions match the content of the source materials;
    • Whether the grading criteria are clear;
    • Whether error feedback helps users learn, rather than only showing that they failed;
    • Whether saved progress can be restored;
    • Whether every level has a reachable completion path;
    • Whether repeated submissions, page refreshes, and mid-session exits cause inconsistent state.

    This task type tests the full chain, from understanding source material to interaction design, state management, and final acceptance. It complements the existing-system task. The first tests the ability to organize a project from nothing. The second tests the ability to make correct changes within constraints.

    These task designs illustrate an evaluation method. They do not represent measured results for any specific product.

    4. Image Asset Import: Building an End-to-End Security Chain

    1. File names and declared types cannot be trusted

    A user’s file extension, file name, and declared content type are all external input. The server should validate the actual content, decoding results, file size, and image dimensions.

    A small compressed file does not mean small memory use after decoding. Besides limiting upload size, the system should also limit image dimensions and resource consumption during processing. For images that do not need to keep their original structure, a controlled decode and re-encode step can be applied before passing them downstream.

    Display names should also be kept separate from actual storage locations. Never concatenate user input directly into a storage path.

    2. A resource ID does not replace authorization

    A random, hard-to-guess resource ID reduces the risk of enumeration. However, it does not prove that the requester is allowed to access the resource.

    A secure read must confirm both that the resource exists and that it belongs to the requester. Here is an illustrative query:

    1. ReadAsset(
    2. asset_id = request.asset_id,
    3. owner_id = current_authenticated_user,
    4. status = usable
    5. )

    The current_authenticated_user value must come from a trusted server-side authentication context, not from a user field submitted by the client.

    Authorization checks must also appear at the binding step. Even if a user can edit a scene, that does not mean they can bind another user’s asset to it.

    3. Asynchronous jobs must carry explicit permission context

    Background jobs usually do not carry a page session. This makes them a common weak point for access control.

    When a job is created, its ownership, business object, and resource references should be written to a trusted record. When the job runs, the system should verify the relationship among the job, the scene, and the asset, rather than reading the asset directly from its ID alone.

    If the system supports team collaboration, the authorization model must also cover organizations, projects, and roles. Comparing user IDs alone may not express real permissions in this case. Use a centrally maintained authorization policy so that each module does not interpret permissions on its own.

    4. Rendering should limit side effects

    When a page or animation renderer processes user assets, the system should define its file access, network access, execution time, and resource limits.

    Be especially careful with external resource URLs, script content, and local paths, which can grant extra capabilities. If the business does not need arbitrary network access, the renderer should not be allowed to reach arbitrary addresses by default.

    A safer approach limits rendering tasks to a set of validated, explicitly authorized, and narrowly scoped resources. Temporary files should also have a cleanup mechanism.

    5. Why Passing Tests Can Still Miss Serious Problems

    Tests do not prove system correctness without limit. They verify only the scenarios that have been defined.

    Suppose the tests cover only “a user uploads their own image and generates a preview successfully.” Even if the implementation allows users to reference other users’ images, the tests could still all pass. The problem is not necessarily the test framework. It is that the permission rules were never written as executable verification conditions.

    1. Move from functional paths to security invariants

    For asset isolation, define the following invariant:

    An unauthorized principal cannot read, bind, render, or export the asset.

    Then write negative test cases around this invariant:

    • User A reads User B’s asset and is rejected;
    • User A binds User B’s asset to A’s own scene and is rejected;
    • After an asset becomes invalid, rerunning the related job follows the defined policy;
    • Preview and export endpoints return the same permission result;
    • A retry path cannot bypass the checks performed on the first execution.

    These tests are more valuable than adding more normal-flow samples.

    2. Use a state matrix to cover combined risks

    Defects in complex systems often appear in combinations of states. Cross-check the following dimensions:

    • Principal: owner, unauthorized user, user with collaboration permission;
    • Asset: pending validation, usable, invalid, deleted;
    • Job: waiting, running, failed, retrying;
    • Operation: read, bind, preview, export.

    You do not need to test every combination. However, cover the high-risk intersections, and document which combinations are forbidden, which require re-authorization, and which allow reuse of previously generated results.

    3. Keep implementation and review perspectives separate

    Having the same AI coding process both implement features and write tests can improve efficiency. However, the two outputs may share the same wrong assumptions.

    For this reason, security acceptance should add an independent perspective. This can include manual review of critical authorization paths, separately designed adversarial tests, or an independent review process that checks data flows and permission conditions. The goal is not to reread all the code. The goal is to verify the boundaries where a failure would cause the most serious harm.

    6. How to Verify That a Learning App Is Completable

    The completeness of a learning app can be constrained with an explicit state model, for example:

    Not started → Learning → Challenge in progress → Passed.

    Each state transition should have preconditions, and progress should have a single authoritative source. If the client can submit a completion state freely, users can skip the learning and challenge steps.

    Content accuracy matters just as much. Each question should trace back to a knowledge point in the source material. Answers and explanations must agree, so the app does not present plausible-looking questions that lack support in the materials.

    Final acceptance should cover at least two complete paths:

    1. Normal completion path: From first entry to finishing all levels, with progress and feedback staying consistent.
    2. Interruption and recovery path: Exiting, refreshing, or logging in again at different stages, then restoring a reasonable state.

    Also check whether repeated submissions cause duplicate scoring, whether level unlocking follows the rules, and whether a clear way to continue learning exists after a failure. Only after these conditions are verified can a page that can be browsed be considered a closed, working product loop.

    7. Building an Evaluation Record for Delivery

    When evaluating AI coding ability, record results, process, and cost together. Recording only task completion time is not enough.

    Dimension Key Observations
    Requirement understanding Whether implicit constraints are identified and ambiguities are clarified proactively
    Engineering consistency Whether cross-module changes and historical compatibility are fully handled
    Long-horizon stability Whether the tool still follows the original goal after multiple repair rounds
    Verification quality Whether error, permission, and state boundaries are covered
    Security Whether there are authorization bypasses, untrusted input issues, or execution isolation problems
    Maintainability Whether duplicate logic, unjustified refactoring, or hidden dependencies appear
    Delivery cost How much effort goes into manual review, rework, and additional tests

    Time tracking should separate initial implementation, verification and repair, and manual acceptance. Otherwise, a process that generates a large amount of code quickly but requires long rework may be mistaken for high efficiency.

    Similarly, a single success does not show stable capability. A more reliable approach runs multiple evaluations on tasks of similar complexity, with clear completion criteria and a consistent environment, and then checks whether the failure types cluster or can be predicted.

    8. Bringing AI Coding into a Controlled Delivery Process

    A practical process has five steps:

    Step 1: Define acceptance boundaries.
    Before coding, state the functional goals, security invariants, compatibility requirements, and prohibited actions. Do not leave critical conditions until the end.

    Step 2: Understand first, then modify.
    Require the tool to produce a map of module relationships, call chains, risk points, and a change plan. The plan is not a formality. It is evidence that the tool understands the system.

    Step 3: Implement in small closed loops.
    First complete one minimal end-to-end path that includes validation, authorization, persistence, and feedback. Then extend it to batch processing, complex interactions, and more exception scenarios.

    Step 4: Verify in layers.
    Verify local logic, module integration, complete business paths, and security boundaries in turn. Each repair should be followed by the necessary regression checks, so that fixing one problem does not break another path.

    Step 5: Keep a human delivery checkpoint.
    For authentication, permission isolation, sensitive data, external resource access, and high-impact operations, keep an independent review. Before release, make sure the necessary logging, monitoring, rollback, and incident response measures are in place.

    Conclusion

    The value of long-horizon AI coding lies in connecting requirement understanding, code changes, runtime verification, and problem fixing into one process. However, working longer or generating more code does not by itself prove that the delivered result is more reliable.

    A mature evaluation should answer three questions: Was the task completed? Did the key constraints hold throughout? How much extra effort did the team spend to confirm the result?

    For development teams, the goal is not to remove manual acceptance as quickly as possible. It is to use clear constraints, layered testing, and independent review to turn AI coding into a controllable and reusable engineering capability. Only when the gap between “it runs” and “it can be trusted” keeps narrowing does AI coding reach reliable delivery.