Evaluating and Safely Deploying Long-Horizon Coding Agents

    Long-horizon coding should be evaluated as constrained software engineering rather than code generation alone. This article presents a practical framework for assessing whether AI coding systems can preserve cross-module consistency, respond to failures, handle security boundaries, and deliver verifiable results. It covers legacy asset ingestion, asynchronous processing, learning-game development, negative security testing, and a repeatable plan–implement–verify–review workflow.

    1. Evaluate the Software Engineering Task, Not Just the Generated Code

    As AI coding systems evolve from completing individual functions to modifying multiple modules over time, evaluation must move beyond “can it generate code?” The more meaningful question is whether the system can complete a constrained software engineering task.

    A real requirement usually involves more than implementing a feature. It may also require understanding legacy architecture, migrating data, enforcing permissions, managing asynchronous jobs, recovering from failures, and passing release acceptance. Locally correct code does not guarantee correct system behavior. Even a fully passing automated test suite does not prove that business and security boundaries have been adequately validated.

    A more useful definition of long-horizon coding capability is whether an agent can maintain goal consistency as context changes, produce reviewable modifications, and move the result toward a runnable, testable, and acceptable state.

    Three levels should be distinguished:

    • Functional completion: The primary operations work and the expected screens can be displayed.
    • Engineering completion: APIs, data, job states, and failure paths remain consistent, and the changes are maintainable.
    • Delivery completion: Permissions, security, compatibility, observability, and rollback plans have all passed acceptance.

    An AI coding assistant may already be capable of reaching the first two levels. The third cannot be confirmed solely from generated output.

    2. Long-Horizon Capability Is Not Simply a Larger Context Window

    Long-horizon development is often described as the ability to process longer inputs. Input capacity is only a prerequisite. The real challenge is maintaining an accurate task state over time.

    2.1 Identify Effective Constraints in Large Codebases

    Legacy systems contain implementations that look reasonable but are no longer authoritative. An AI coding assistant must distinguish active interfaces, compatibility logic, deprecated code, and test doubles instead of treating all available content as equally reliable.

    For example, an API may accept a resource identifier, but that does not mean the caller is authorized to read the resource. Permission checks may be distributed across an entry service, a data-access layer, and background jobs. Reading only the page and API definitions could miss the most important isolation rules.

    2.2 Preserve Contracts Across Modules

    A feature may travel from the frontend through parameter validation, database records, a task queue, an executor, and result storage. If any layer interprets a state, field, or error differently, the system may develop subtle failures.

    Evaluation should check whether:

    • Request fields and persisted fields are consistent;
    • Synchronous responses and asynchronous results have clear boundaries;
    • Retries can cause duplicate writes;
    • Users can observe failure states;
    • Existing data remains readable.

    2.3 Correct Assumptions After Failure

    High-quality long-horizon execution is not a process of continuously appending code. The plan should be revised based on evidence. Compilation errors, test failures, and runtime exceptions should trigger diagnosis and reflection—not the removal of assertions, weaker permissions, or bypassed validation simply to make the build pass.

    The execution record is also evaluation evidence: what changed, why it changed, how it was verified, and which risks remain unverified.

    3. Use Complementary Tasks Instead of Demonstrations Alone

    Two types of tasks can provide broader coverage of an agent’s capabilities.

    The first is a legacy-system modification, such as adding user image-asset ingestion and allowing dynamic page scenarios to reference those assets. This tests architectural understanding, compatibility, and security constraints.

    The second is developing a knowledge-learning game from requirements documents and learning materials, with a complete path to completion. This tests requirements clarification, domain modeling, interaction design, and end-to-end completeness.

    These tasks should not be treated as already-validated performance conclusions. They are reusable evaluation designs. The first tests whether an agent can work correctly within existing constraints; the second tests whether it can construct a complete product from incomplete information.

    4. Legacy Asset Ingestion: Design the Feature Path and Trust Boundaries Together

    Image upload may look like a simple form feature, but it involves the complete lifecycle of untrusted content entering a system.

    The workflow can be abstracted as:

    User submits an asset → Server-side validation → Isolated storage → Content processing → Resource record creation → Scenario authorization → Background rendering → Output generation

    Every arrow may cross a trust boundary.

    4.1 Upload Validation Must Not Depend on File Names

    File extensions and client-declared media types can both be forged. The server should combine content inspection, actual decoding results, and size limits when validating uploads.

    For images, the decoded pixel count also matters. A compressed file may be small while requiring substantial resources to decode. Based on the actual runtime environment, the processing pipeline should enforce limits on file size, dimensions, processing time, and concurrency to prevent malicious or abnormal inputs from exhausting resources.

    If a format supports scripts, external references, or complex interactive behavior, the system should explicitly reject it or use a security-reviewed conversion and isolation process. It should not assume that every “image file” is static content.

    4.2 The Server Must Determine Resource Ownership

    A resource identifier is not an access credential. Even if an attacker cannot guess it, the identifier may be exposed through logs, sharing records, or other APIs.

    Authorization must therefore verify not only that the resource exists, but also that the current principal is allowed to use it in the current context.

    Illustrative pseudocode:

    1. function attach_asset(actor, project_id, asset_id):
    2. project = load_project(project_id)
    3. require can_edit(actor, project)
    4. asset = load_active_asset(asset_id)
    5. require can_read_asset(actor, asset)
    6. require can_use_asset_in_project(asset, project)
    7. save_reference(project, asset)

    These permission checks must be implemented in data queries or an explicit policy mechanism. They cannot exist only as comments.

    The server should also avoid accepting ownership information supplied by the client. Ownership should be derived from the authenticated identity, the project relationship, and system rules.

    4.3 Background Jobs Must Not Have Unlimited Privileges

    Asynchronous processing is a common source of authorization failures. The entry API may perform the appropriate checks, while the background executor has broader storage access. If the executor reads data solely from a resource identifier in the job payload, it may bypass the isolation boundary established at the entry point.

    Safer practices include:

    • Recording the principal, project, and resource relationship associated with each job;
    • Reconfirming that critical resources are still valid at execution time;
    • Defining how authorization changes affect processing;
    • Restricting the executor’s storage, network, and file-system access;
    • Avoiding direct concatenation of user input into local paths or remote addresses.

    Rendering systems also require protection against uncontrolled network requests. Access to internal services, instance metadata endpoints, or local files should be determined by an explicit isolation policy.

    4.4 Deletion, Failure, and Retries Are Part of the Requirement

    What happens to queued jobs after an asset is deleted? If the upload succeeds but the database write fails, how are orphaned files removed? Can a retry create duplicate references?

    These cases should be addressed through lifecycle design, such as explicit resource states, idempotent job steps, and periodic cleanup. They should not depend on every execution succeeding exactly once.

    5. A Learning Game That Renders Correctly May Still Be Impossible to Complete

    When building a learning game from scratch, a common failure mode is a visually rich interface with incomplete state transitions.

    An acceptable learning game should provide a complete loop:

    Learning objectives → Instruction → Practice → Feedback and correction → Progress update → Level unlocking → Final summary

    5.1 Define Learning Objectives Before Choosing Interactions

    Do not generate a collection of questions first and then wrap them in a game interface. Begin by defining what users must learn, the prerequisites between concepts, and which actions demonstrate understanding.

    For example, a course on AI-agent fundamentals might distinguish task decomposition, tool calling, state management, and result verification. Each question should have a clear basis, and its explanation should correspond to core concepts in the learning materials. Avoid producing conclusions that sound technical but have no identifiable foundation.

    5.2 Manage Levels with a State Machine

    Levels can typically be represented by states such as locked, available, in progress, and completed. State transitions should have explicit conditions rather than being controlled only by whether a button is displayed.

    Important checks include:

    • A later level cannot be entered before its prerequisites are met;
    • Repeated submissions do not award rewards repeatedly;
    • Progress remains consistent after a page refresh;
    • An incorrect answer does not accidentally advance the main path;
    • Completing all levels leads to an explicit completion state.

    For multiplayer scenarios, cross-device progress, or reward entitlements, critical progress should be governed by server-side rules rather than client-side state alone.

    5.3 Acceptance Must Cover the Complete User Journey

    At a minimum, test first entry, normal completion, consecutive incorrect answers, refresh and recovery, duplicate submissions, replay, and final settlement.

    Walking the entire path from start to finish is essential. Testing isolated pages will not reveal broken level transitions, conflicting completion conditions, or a final state that can never be triggered.

    6. Why Passing Tests Can Still Leave High-Priority Vulnerabilities

    Tests prove that written assertions hold. They do not prove that the requirements or threat model are complete.

    If tests check only that a user can read their own assets, they will not detect that the same user can read someone else’s assets. If background-job tests use a single account with full privileges, they cannot validate real tenant isolation.

    Security testing should include negative scenarios:

    Scenario Expected result
    A user references another user’s private asset The request is rejected and no reference is created
    Project access is revoked before job execution Processing stops or authorization is reevaluated according to the defined policy
    An asset is deleted while a job continues The invalid resource is not read and the failure remains traceable
    The client tampers with the ownership field The server does not trust the client-provided ownership claim
    Rendered content attempts to access an internal address The request is blocked according to the network-isolation policy

    Severity should be assessed according to impact, exploitability, and business consequences. A permission error should not automatically receive the same severity in every context.

    7. Build a Reusable Evaluation Process

    A practical process can use four phases: plan, implement, verify, and review.

    7.1 Plan: Define Acceptance Criteria First

    Specify which modules may be modified, which boundaries must not be crossed, which compatibility behaviors must remain intact, and what the final acceptance checklist contains. For ambiguous requirements, ask the agent to list its assumptions before coding.

    7.2 Implement: Make Progress Through Verifiable Increments

    Break the task into smaller steps such as the data model, APIs, core logic, interaction, and failure handling. Each step should have an independent verification method. This reduces the risk of discovering an incorrect architectural assumption only at the end.

    7.3 Verify: Separate Different Types of Evidence

    Static analysis can identify some type and syntax problems. Unit tests validate local logic. Integration tests validate module connections. End-to-end tests validate user journeys. Manual review adds business-semantic and security judgment.

    These forms of evidence complement one another; none can replace the others.

    7.4 Review: Prioritize High-Risk Differences

    Manual review should focus first on authorization checks, database query scope, file processing, remote requests, background executors, and migration scripts. A risk-oriented review is more likely to uncover high-impact issues than reading every generated line with equal attention.

    Evaluation records should not be reduced to a single score. Track task completion, the number of manual interventions, the effective scope of changes, defect types, verification coverage, and remaining delivery risks separately. When comparing approaches, keep the task, runtime environment, tool permissions, and acceptance criteria as consistent as possible. Otherwise, environmental differences may be mistaken for capability differences.

    8. Deployment Principle: More Execution Capability Does Not Mean Weaker Controls

    The value of long-horizon coding is that it can reduce the amount of mechanical coordination developers must perform, including information gathering, code navigation, cross-module changes, and iterative verification. An agent may take on more execution work, but it should not receive unrestricted production access as a result.

    In practice, prioritize isolated development environments, least-privilege credentials, reviewable change workflows, and explicit release approvals. Changes involving data ownership, security policies, financial operations, or external access should have stricter human checkpoints.

    What deserves trust is not that one generated result looks impressive. It is an engineering process that can repeatedly detect errors, limit their impact, and provide verification evidence. Long-horizon coding should therefore be evaluated around that process: how much work the system can advance, whether it respects boundaries, whether it exposes uncertainty, and whether it leaves final judgment to sufficient evidence.