Goal-Driven Coding: Implementing Autonomous Loops and the Acceptance Problem

    This article explains how goal-driven autonomous loops shift prompting from task-based instructions to state-based contracts, and why the credibility of the termination condition determines whether such loops succeed. It covers the three common failure modes of model self-certification, the difference between model-attested and externally verified termination, how to design machine-checkable acceptance criteria, the guardrails needed for safe autonomy (path allowlists, budgets, diff gates, and rollback), common anti-patterns, and a practical rollout checklist. The core takeaway: make "done" provable through deterministic checks rather than the model's own claims.

    1. From “Execute One Step” to “Converge on a State”: A Paradigm Shift

    A two-hour discussion that consumed roughly 900 million tokens brought an otherwise unremarkable command into the mainstream: the goal-driven autonomous loop. Its value lies not in “being able to loop,” but in fundamentally rewriting the semantics of the prompt.

    Past prompts were task-based: please do a certain thing. The model executed one round, stopped, a human confirmed, and then it continued. Current prompts are state-based: push the system to a verifiable state, and stop once that state holds. The prompt has changed from an “instruction” into a “contract”—containing the goal state, acceptance criteria, inviolable constraints, and resource boundaries.

    A schematic call shape looks like this (neutral pseudocode, not the interface of any specific product):

    1. /goal make all tests under src/auth/ pass, with no static-check warnings
    2. Constraints: do not modify public interface signatures; do not add third-party dependencies
    3. Budget: at most 40 rounds / 30 minutes / no more than 400 lines changed incrementally

    Once this contract is entered, no human needs to repeatedly type “continue” in the middle. The model runs a round on its own, judges whether the target is met on its own, and runs another round if it is not. On the surface this is an efficiency tool; in essence, it partially hands the “acceptance authority” from the human to the model—and this is precisely the source of all the risk.

    2. The Core Problem: Who Is Qualified to Declare “Done”

    The success or failure of an autonomous loop depends on only one thing: the credibility of the termination condition.

    An early, naive approach popular in the community (often called the “feed-the-loop-tasks” pattern) is logically minimal: use a hook to intercept the model’s stop action and feed the original task back in once more; when the model outputs an agreed signal (for example, DONE), the loop exits. It genuinely works in engineering terms, but the judgment authority rests 100% with the model itself—equivalent to letting a candidate grade their own exam. It has three typical failure modes:

    • Premature convergence: the model mistakes “I’ve changed part of it” for “everything passes” and outputs the signal to exit.
    • Never converging: the acceptance condition is written vaguely, and the model finds a new “it could still be better” every round, polishing endlessly.
    • Goal drift: to make a check turn green, the model chooses to loosen assertions, skip cases, or comment out validations—metrics look good while the system degrades.

    Therefore, the key to long-running autonomous coding is not the loop itself, but turning “done” from a subjective statement into an objective fact.

    3. The Essential Difference Between Two Implementation Paths

    Once you abstract away the branding of the implementations on the market, only two philosophies remain.

    The first: model self-attestation. The termination signal is produced by the model, and the outside is only responsible for relaying “continue/exit.” The advantage is extremely low integration cost—a few dozen lines of script are enough to get it running; the drawback is that acceptance is untrustworthy and unauditable, and long-running execution is highly prone to the three failures above. It suits exploratory, one-off, low-risk scripting tasks.

    The second: external verification. The termination signal is produced by deterministic checks, and the model is only responsible for “changing things until the checks pass.” The checks can be unit tests, type checks, static analysis, build artifacts, contract tests, end-to-end cases, or even a read-only acceptance script. The model has no authority to modify the verifier or the test cases themselves; any change that tries to loosen assertions is blocked by the diff policy. Its integration cost is somewhat higher, but it buys a reproducible, auditable, and regression-safe convergence process.

    The difference in one sentence: the former exits when “the model says it’s done,” the latter exits when “the world says it’s done.” In engineering, you should default to the latter and use the former only as a fallback timeout strategy.

    4. Writing “Done” So a Machine Can Decide: Acceptance Criteria Design

    Acceptance criteria are the most important clause in the contract. An actionable approach follows four principles:

    1. Executable: each criterion corresponds to a check that can be triggered from the command line, not an adjective.
    2. Binary: the result is 0/1, not “basically passing” or “roughly correct.”
    3. Isolated: the acceptance environment is decoupled from the development environment, preventing the model from “cheating” by altering the environment.
    4. Minimally sufficient: cover only the conditions that truly represent the requirement; too many conditions will drain the budget on irrelevant details.

    Example (pseudo-config):

    1. verify:
    2. - unit: run_tests(area="src/auth") # must all pass
    3. - types: typecheck(project) # zero errors
    4. - lint: static_check(severity>=warning) # zero warnings
    5. - build: build(target="service") # artifact can be generated
    6. forbid:
    7. - modify(path="verify/**") # verifier is read-only
    8. - weaken_assertions() # loosening assertions is forbidden
    9. - add_dependency(without_approval=true) # adding dependencies on your own is forbidden

    5. Guardrails: Constraints, Budgets, and Rollback

    Autonomy does not mean letting things run wild. At least four layers of guardrails are needed:

    • Path allowlist: only changes to specified directories are allowed; acceptance scripts, build configs, and dependency manifests are set to read-only.
    • Resource budget: set upper limits on rounds, duration, tokens, and lines changed simultaneously; if any one is hit, stop and hand back control.
    • Diff gate: generate a diff each round; if there is any deletion or weakening of tests, assertions, or log checks, the round is judged invalid outright.
    • Rollback: execute each round on an independent branch or workspace snapshot; discard on failure and merge only on success, ensuring the main branch is always usable.

    Supporting observability is equally indispensable: write each round’s acceptance output, failure reason, and change summary into a logging service, and use monitoring alerts to set thresholds for “abnormally growing round counts” and “the same error across consecutive rounds,” avoiding silently burning budget while unattended.

    6. Common Anti-Patterns and Tuning Techniques

    • Writing a condition as “high code quality”: undecidable, and drift is inevitable. Replace it with concrete check items.
    • One giant condition: failure messages are noisy and the model struggles to locate the issue. Split it into multiple atomic conditions, and light them up one by one from fail to pass.
    • Ignoring the initial baseline: run acceptance once first to get a baseline; if the baseline itself is not green, fix the baseline before talking about autonomy.
    • No timeout: network, dependency, and external-service jitter will make the loop spin idle. Timeout and max rounds must appear as a pair.
    • Granting too much authority at once: start with a small-scale pilot (single directory, single module), verify convergence quality, then expand the scope.

    7. Rollout Checklist

    1. Pick a module with clear boundaries and automatable acceptance as a pilot.
    2. Write a read-only acceptance script and confirm it reproduces stably in a clean environment.
    3. Configure the path allowlist, budget limits, diff gate, and snapshot rollback.
    4. Integrate logging and alerting, and observe the round distribution over 3–5 complete convergence runs.
    5. Consolidate the stabilized acceptance script into a team asset for reuse in later tasks.

    The real threshold for goal-driven autonomous loops has never been “getting the model to run,” but “making done provable.” Only by handing acceptance authority to deterministic checks rather than the model’s self-statement does autonomous coding move from a demo to a trustworthy daily engineering practice; running such workflows on top of general-purpose capabilities of cloud platforms such as Baidu AI Cloud (for example, container platforms, logging services, and monitoring alerts) can also keep the resources and risks of long-running tasks within a manageable and controllable range.