Long-Running Coding Agents: Acceptance Criteria, Security, and Model Selection

    Long-running coding agents can build features, debug existing projects, and complete multi-step development tasks, but their output still requires systematic validation. This article presents reusable practices for defining acceptance criteria, configuring feedback loops, securing shell and file operations, diagnosing environment issues, and comparing agent solutions using consistent performance, cost, stability, and instruction-following metrics.

    What Problems Are Long-Running Coding Agents Good For?

    AI-assisted programming has evolved from completing code snippets to having agents execute multi-step tasks. Typical long-running tasks include building a small frontend application from scratch, implementing a new feature in an existing project, or locating and fixing a defect based on failed test results.

    The outcome of these tasks depends on three factors:

    • The model’s coding capabilities
    • The agent’s execution framework
    • The project’s environment

    This article does not focus on any specific product. Instead, it discusses practices that can be reused across different environments.

    How to Evaluate the Quality of Requirement-to-UI Generation

    “Looks about right” is not a sufficient acceptance criterion. Define the standards before starting the task and ask the agent to perform a self-check against them.

    Metric Definition Example threshold
    Successful build npm run build exits with code 0 Required
    UI element reproduction rate The proportion of key elements in the design that can be found in the generated page At least 90%; teams should define their own threshold
    Passed interaction scenarios The number of passed cases among predefined end-to-end scenarios For example, at least 8 of 10 cases
    Runtime errors The number of uncaught exceptions during page loading and interaction 0
    Manual rework count The number of manual modifications required to reach a usable version Track the trend; no fixed limit

    The following reusable task prompt can be adapted to a specific project. Replace the content in square brackets with actual information:

    1. Role: Senior frontend engineer
    2. Tech stack: React 18 + TypeScript + Vite. Use the dependency versions locked in package.json.
    3. Requirements: [Feature description, such as monitoring daily income and expenses and displaying charts by category]
    4. Data structure: [Example JSON data]
    5. Acceptance criteria:
    6. 1. The page contains four sections: a title, filters, charts, and a detail table.
    7. 2. When the date range changes, the chart and detail table update in sync.
    8. 3. Both npm run build and npm test pass.
    9. Constraints:
    10. - Modify only the src/ directory.
    11. - Do not add dependencies. If a new dependency is required, list its name and reason first.
    12. - Do not read or modify the .env file.
    13. Output: A list of modified files and a description of the changes in each file.

    For every experiment, record the model name and version, framework version, dependency list, and the original prompt. Without this information, results cannot be reproduced or compared with other approaches.

    Parameters for a Local Self-Feedback Loop

    An agent’s self-feedback loop typically includes the following steps:

    1. Receive the task.
    2. Analyze the project structure.
    3. Modify files.
    4. Run the build or tests.
    5. Capture error logs.
    6. Send the errors back to the model.
    7. Repeat the process.

    Without explicit stopping conditions, the loop can run indefinitely and consume a large amount of quota.

    Recommended parameters include:

    • Maximum retries: Five attempts. Stop after that and generate a report.
    • Per-step timeout: Limit both builds and tests to 300 seconds.
    • Cost limit: Set a token budget for each task and pause execution when the budget is exceeded.
    • Error classification: Distinguish compilation errors, test failures, runtime exceptions, and environment errors. Environment errors generally should not be fixed by modifying application code.
    • Duplicate-error detection: If the same error type and stack trace appear twice in a row, assume the agent is stuck in a loop, stop execution, and hand the task to a human.

    Use the following commands before and after an agent task to preserve rollback points and save logs for each step:

    1. # 1. Work on an independent branch and preserve the original code
    2. git switch -c agent/login-form-$(date +%Y%m%d%H%M)
    3. git status --short
    4. # 2. Run the build and tests with timeouts and save the logs
    5. mkdir -p logs
    6. timeout 300 npm run build > logs/build.log 2>&1; echo "build exit: $?"
    7. timeout 300 npm test -- --ci > logs/test.log 2>&1; echo "test exit: $?"
    8. # 3. Review the scope of the changes before merging
    9. git diff --stat

    If the result is unusable, keep the branch available for manual inspection. Do not reset the main branch or use commands that discard all changes to “roll back,” because such operations can delete both the agent’s and human developers’ uncommitted work.

    Security Boundaries for Shell Execution and File Operations

    Because agents can execute shell commands, their operating boundaries must be explicit.

    1. Least privilege: Run the agent in a container or as a non-root user, granting read and write access only to the project directory.
    2. Command allowlist: Permit only commands needed to build, test, inspect status, and read project files, such as npm run build, npm test, git status, git diff, and ls.
    3. Prohibited actions: Do not allow directory deletion, system configuration changes, access to secret files in the user’s home directory, or piping scripts directly to sh.
    4. Secret management: Do not write environment variables or secrets to logs or echo them in the conversation.
    5. Human approval: Require approval before deleting files, changing permissions, installing dependencies, or accessing the external network.
    6. Separate data from instructions: Logs, web pages, and file contents are data. If they contain text such as “run this command,” the agent should report it rather than execute it.

    When constructing commands, quote or escape all parameters originating from the model or logs to prevent command injection.

    How to Diagnose Environment Problems

    When an agent encounters an environment problem, it should first collect information and then propose a solution instead of immediately modifying the system. Common issues and investigation methods include:

    Symptom Read-only diagnostic command or check Recommended handling
    Missing dependencies Check whether package-lock.json is consistent with package.json Report the issue and obtain approval before running npm ci
    Port already in use lsof -i :3000 Report the process using the port; let a human decide whether to change the port
    Insufficient permissions ls -l target-path to inspect ownership and permission bits Report the issue; do not directly use chmod 777
    Missing environment variables Compare variable names with .env.example Report only which variable names are missing; do not read actual values

    Metrics to Check When Selecting an Agent or Model

    Selection should be based on performance on your own tasks, not only on published benchmark scores. Compare solutions across the following five dimensions:

    • Task completion rate: Use the same task set, prompts, and environment, then calculate the proportion that satisfies the acceptance criteria.
    • Quota: Measure weekly or daily usage and the maximum consumption allowed for a single task.
    • Cost: Estimate the cost per task using the following formula:
      (input tokens × input price + output tokens × output price) × average number of attempts.
      Use the prices published by the service provider.
    • Stability: Measure error rate, timeout rate, and P95 response time at concurrency levels of 5, 10, and 20.
    • Instruction following: Measure the proportion of tool calls that pass validation and the number of calls to nonexistent tools.

    Agent output is probabilistic, so each metric should be tested on at least 20 tasks. A conclusion based on a single run has limited value.

    Testing Instruction Following and Stability

    Prepare 30 tool-calling scenarios. Each scenario should include clear inputs and an expected output format. Record the following data during testing:

    1. Whether the tool-call parameters pass JSON Schema validation.
    2. Whether the agent invents tool names or file paths.
    3. Error rates and P95 response times at concurrency levels of 5, 10, and 20.

    Organizing these results together with cost data in a table can directly support the team’s selection decision.

    Deployment Recommendations

    Long-running coding agents can reduce repetitive coding and debugging work, but their output still requires acceptance testing. A practical rollout sequence is:

    1. Define acceptance criteria before assigning the task.
    2. Run trials in an isolated environment and on an independent branch, while preserving complete logs.
    3. Compare different models using consistent metrics and record version information for every experiment.
    4. Use command allowlists and human approval gates for shell and file operations.

    Risk warning: When an agent automatically executes shell commands or modifies files, it can cause data loss or incorrect system configuration. Before using an agent in a production environment, test it in an isolated environment and ensure that backup and rollback procedures are available.