AI Agent Governance: Preventing Runaway Automation and Budget Spikes

    This article examines a representative failure in automated software development: two AI coding assistants were allowed to refactor a project in turns for about three weeks before the code was inspected closely, revealing a clear mismatch between the implementation and the intended architecture. Tests also called a production inference endpoint, creating unexpected costs. The article explains why such failures are usually not a single code-generation error but the result of broken control chains across requirements, testing isolation, and human review. It then presents engineering practices for agent runtimes, skill validation, layered testing, budget enforcement, executable acceptance criteria, independent review, and small-batch delivery. Readers will learn how to replace vague automation claims with verifiable evidence and how to build governance into the execution path rather than relying on post hoc alerts and reports.

    1. Code Keeps Being Produced, So Why Does the System Become Less Controlled?

    A representative automation failure involved a developer who handed a personal project to two AI coding assistants and let them refactor it in turns. After about three weeks, a deeper inspection revealed that the implementation had drifted significantly from the expected architecture. Tests were also calling a production inference endpoint, causing unexpected costs.

    One number needs clarification first: the source material mentions figures such as about $100 per day, a normal weekly budget, and “five times,” but it does not provide a clear, consistent baseline for comparison. It is therefore not possible to calculate an exact cost-growth multiple from those figures. The more important question is the engineering issue that has already been exposed: why could a test run continue to generate real inference charges without explicit authorization and effective blocking?

    Likewise, “the skills are fake” is not a sufficiently accurate technical diagnosis. The real questions are whether the so-called skills consist only of description files, whether they are loaded by the runtime, whether they can participate in task execution, and whether their execution results are validated.

    Failures of this kind usually do not come from one bad code generation. They occur when three control chains break at the same time:

    • Requirements are not translated into verifiable architecture constraints.
    • Automated tests do not establish reliable resource boundaries.
    • Human review cannot keep pace with the speed of code changes.

    The focus should therefore not be on finding a “more obedient” coding assistant. It should be on redesigning the delivery mechanism for automated development.

    2. Project Complexity Increased, but the Development Model Did Not

    The system in the case initially needed only to download audio, transcribe content, and generate summaries. That kind of requirement can be handled with a relatively direct pipeline:

    Input task → fetch content → convert to text → generate summary → save result

    When external content collection, scheduled execution, email triggers, long-running operation, research tasks, and experience accumulation were added, the nature of the project changed.

    It was no longer just a processing script. It became an application system with external dependencies, persistent state, and autonomous decision-making. Engineering requirements therefore had to be upgraded as well.

    First, task state must be explicit. A task may be waiting to run, currently running, waiting for an external result, or terminated after failure. The system should not require operators to infer state only from logs.

    Second, duplicate execution must be handled. Scheduled tasks, email redelivery, and failure retries can all cause the same content to be processed multiple times. The system needs deduplication and idempotency mechanisms.

    Third, resource boundaries must be managed. How many model calls a research task may make, which data it may access, and when it must stop all need to be explicitly defined.

    Fourth, a traceable execution record must be established. Otherwise, even if the final summary looks normal, it is impossible to determine whether duplicate calls, unauthorized access, or ineffective loops occurred in the middle.

    A growing number of features does not automatically produce a sound architecture. If the main acceptance criterion remains “build the next feature,” the system can easily accumulate a large amount of code that looks usable on the surface but is heavily coupled internally.

    3. How to Determine Whether the Implementation Is Actually an Agent Runtime

    There is no single fixed implementation form for agents, and not every task requires autonomous decision-making. However, if a requirement explicitly calls for an “agent runtime,” it should explain how that runtime differs from an ordinary pipeline.

    A fixed pipeline usually executes predefined steps. An agent system usually needs to choose the next action based on the goal, context, and execution results, and then advance in a loop within constraints.

    For a system that is required to support multiple agents, different execution backends, and task governance, architecture acceptance can be broken down into several areas.

    3.1 Does Registration Information Actually Enter the Execution Chain?

    A registry should not only store names, descriptions, and configuration. Execution records should also prove that the scheduler selected an execution subject based on registration information and invoked the corresponding implementation.

    A useful acceptance question is:

    “After changing a registration item, does the behavior of an actual task change in an explainable and testable way?”

    If configuration changes never affect runtime behavior, the registry is likely only a presentation layer.

    3.2 Is Execution State Explicitly Present?

    The runtime should retain enough information to support fault diagnosis and necessary recovery, such as:

    • The current task and execution step;
    • Intermediate results that have been produced;
    • The number of calls and budget already used;
    • The termination reason or failure type;
    • Human approval and authorization records.

    Not every system needs a complex persistence mechanism, but critical state must not be hidden only in process memory or natural-language output.

    3.3 Do External Calls Pass Through a Unified Boundary?

    If model calls, data reads, and tool execution are scattered across modules, it is difficult to enforce permissions, timeouts, retries, and cost accounting consistently.

    A more robust approach is to establish a unified invocation layer. Business modules express intent, while the invocation layer enforces resource controls and records results. This way, when the execution backend changes later, governance logic does not need to be rewritten in every business function.

    4. “A Skill File Exists” Does Not Mean the Skill Is Active

    A skill can take the form of operating instructions, prompt templates, structured configuration, or an associated executable component. It is not accurate to assume that only code counts as a real skill. Regardless of form, however, a skill needs clear usage semantics.

    To determine whether a skill is effective, at least six questions must be answered:

    1. When is it selected? Which tasks are applicable, and which tasks should be explicitly excluded?
    2. How is it loaded? Who reads it, and can loading failures be detected?
    3. What are its inputs? Are there required fields and context requirements?
    4. What is it allowed to do? Which tools, data, and external resources can it access?
    5. What counts as success? Does the output meet structural, quality, or business constraints?
    6. How can its use be proven? Can execution records be linked to the skill version and result?

    For example, if the system generates a “long-form summary skill,” but summary tasks always use a fixed prompt and never read that file, then the file is only an asset waiting to be integrated. It is not a completed runtime capability.

    It is also necessary to distinguish between “experience candidates” and “formal skills.” Automated reflection can propose optimization suggestions, but it should not directly modify production behavior. A more reliable process is:

    Execution records → extract candidate experience → offline evaluation → human or rule-based approval → versioned release → continuous observation

    This prevents a one-time success from being incorrectly fixed as a general rule.

    5. Unit Tests Hitting Production Reveal a Missing Isolation Layer

    The main goal of unit tests is to verify local logic under controlled dependencies. They should not depend on real model services by default, and they certainly should not depend on production credentials.

    Tests that involve real inference endpoints are not forbidden, but they should belong to separate integration tests or end-to-end tests and use explicitly authorized test resources.

    Establish a Layered Testing System

    Unit tests use test doubles to verify state transitions, exception branches, budget decisions, and output parsing without generating external inference charges.

    Integration tests verify connections, authentication, and protocol compatibility between real services, using isolated accounts and small samples.

    End-to-end tests verify the complete business path while controlling execution frequency, data scope, and resource limits.

    Quality evaluation focuses on probabilistic results such as summary accuracy and task completion rate. It should not be confused with deterministic checks that run on every code commit.

    Default Deny Is More Reliable Than Default Allow

    Simply requiring in documentation that “do not connect to production” is far from enough. More effective controls include:

    • Unit test processes are not injected with production credentials.
    • The test environment denies access to external inference services by default.
    • Tests against real services must be explicitly enabled through a separate entry point.
    • Test accounts use separate quotas and permissions.
    • Execution terminates when environment identifiers are missing or conflict.
    • Production resources have separate access policies and auditing.

    These measures should be used together. Checking a single environment variable does not create a reliable security boundary.

    Pay particular attention to the fact that automatic repair after a test failure can amplify costs. A failure triggers a retry, the retry calls the model again, the coding assistant then modifies code and reruns the entire test suite, and a costly loop can form.

    6. Cost Control Must Be Part of the Task Execution Path

    Cost alerts are necessary, but they usually notify owners only after charges have already been incurred. For autonomous execution systems, budget should also be part of scheduling decisions.

    6.1 Set Multiple Limits Together

    A single token quota cannot cover every risk. Depending on business needs, the system can combine limits such as:

    • Maximum model calls per task;
    • Maximum input and output size;
    • Maximum execution duration;
    • Maximum number of concurrent tasks;
    • Maximum retry count;
    • Allowed tools and data scope;
    • Per-task and global budgets.

    These limits should be configurable, but the model should not be allowed to relax them on its own.

    6.2 Reserve Budget Before Concurrent Execution

    If multiple tasks all check the remaining balance first and then initiate calls, they may simultaneously conclude that “budget is sufficient” and ultimately overspend.

    Concurrent environments therefore usually need atomic budget reservation: request quota first, execute the call, settle based on actual consumption, and release the unused portion.

    Failure, timeout, and delayed usage reporting should also be considered. A request that does not return a useful result may still have incurred cost. Failed requests cannot simply be treated as zero consumption.

    6.3 Treat Retries as a Constrained Decision

    Authentication failures, malformed input, and exhausted budgets are usually not suitable for identical retries. Temporary network anomalies may be retried a limited number of times, but they require backoff strategies, retry caps, and total duration limits.

    Retry is not a free reliability mechanism. It is an execution strategy that consumes resources.

    7. Turn Specifications into Executable Acceptance Criteria

    “Support skills,” “implement a registry,” and “provide autonomous reflection” are all too abstract. They easily allow code generation to stop at structural imitation.

    A better approach is to establish an evidence chain for each requirement:

    Requirement description → behavioral constraint → implementation location → automated test → runtime record

    For example:

    Requirement Verifiable Constraint Acceptance Evidence
    Support skill loading After a skill version is changed, new tasks use the corresponding version Loading test and execution records
    Support budget control No new paid call may start when quota is insufficient Boundary test and rejection records
    Support failure recovery Completed steps can be identified after interruption Recovery test and state records
    Prevent tests from accessing production The default test path cannot obtain production access Configuration check and access policy validation

    This approach does not require every behavior to be written as an automated test, but key architecture goals must have inspectable results. They cannot rely only on a textual summary from the generation tool.

    8. Multiple Assistants Are Not the Same as Independent Audits

    Letting multiple AI coding assistants work in turns can increase the number of ideas, but it does not inherently provide quality assurance. If they read the same vague requirements and inherit the same flawed abstractions, they may reinforce the problem together.

    A more effective division of labor is to give each review role a different objective:

    • The implementation role focuses on whether functionality is complete.
    • The architecture review focuses on module boundaries and dependency direction.
    • The test review focuses on assertion quality and dependency isolation.
    • The cost review focuses on paid calls, retries, and concurrency.
    • Human review focuses on whether requirements have been correctly understood.

    Testing, in particular, needs independence. Tests generated by the same implementation process may only verify that “the code runs as currently written,” not that “the current implementation satisfies the real requirement.”

    9. Deliver in Small Batches Instead of a Three-Week Review

    AI coding reduces the cost of generating code, but it does not reduce the cost of understanding code. The more changes accumulate, the harder it is for humans to distinguish necessary refactoring from unrelated expansion.

    A more reliable delivery sequence is:

    First, establish the smallest execution loop for a single task, with explicit inputs, state, and termination conditions.

    Second, integrate test doubles to verify normal and failure paths without calling real inference services.

    Third, add a unified invocation layer, budget reservation, and execution logs.

    Fourth, run a small number of real integration tests in an isolated environment.

    Fifth, gradually add scheduling, concurrency, recovery, and skill management capabilities.

    Each round should preserve a stable, rollback-capable point. Review should focus on permissions, external calls, data migration, and scheduling logic. Reading a change summary is not enough; critical execution paths must be inspected directly in the code.

    10. Conclusion: Stronger Automation Requires Stronger Engineering Evidence

    The most important lesson from this kind of case is not that AI coding tools cannot handle complex tasks. It is that continuously produced code, passing tests, and fluent completion reports cannot be equated directly with a reliable system.

    A truly deliverable agent system needs to satisfy three conditions at the same time:

    Implementation is explainable: It is possible to identify how tasks are scheduled, how skills take effect, and how state advances.

    Behavior is constrained: Permissions, network access, budget, and retries all have boundaries that cannot be bypassed at will.

    Results are verifiable: Key requirements have tests and runtime evidence, and important changes are reviewed in a timely manner.

    The goal of automated development should not be to avoid looking at code for as long as possible. It should be to use less human effort to obtain clearer implementation evidence, shorter feedback cycles, and more controllable operational risk.