Correctness Governance for Long-Running Agents: From Naive Loops to a Handover-Ready Architecture

    Keeping an agent running for hours is now easy—keeping it correct is not. This article dissects the three hidden drift problems of naive loop architectures—goal drift, context drift, and quality drift—and presents a handover-ready architecture built on upfront specifications and external state files (GOAL.md, PLAN.md, STANDARDS.md, PROGRESS.md), making long-horizon agent tasks verifiable, resumable, and auditable.

    Correctness Governance for Long-Running Agents: From Naive Loops to a Handover-Ready Architecture

    1. Why “It Keeps Running” Doesn’t Mean “It’s Running Right”

    Advances in intelligent coding tools have made continuous execution trivial. Give a model a goal, a loop, and a set of tool-call interfaces, and it can work for hours—writing code, running tests, fixing errors. Many teams have celebrated: long-task automation has finally arrived.

    But anyone who has actually run long-horizon tasks in production knows this only solves half the problem. “Can it keep running?” is a stamina question; “is it running correctly?” is a direction question. Stamina problems can be brute-forced with loops, retries, and checkpoint restarts. Direction problems, however, get quietly amplified inside the loop. The scariest failure mode of a long-running agent is not that it stops after ten iterations—it’s that after a hundred iterations it delivers something that looks diligent but has drifted miles away from the original goal. Every individual step was “reasonable,” yet the accumulated output is no longer what was asked for.

    This article systematically breaks down the three types of drift in long-running agents and presents a handover-ready architecture centered on upfront specifications plus external state files, making the correctness of long tasks verifiable, transferable, and auditable.

    2. Three Hidden Drifts in the Naive Loop Architecture

    The most intuitive implementation of a long-running agent is the “naive loop”: put the goal into the prompt and let the model repeat “observe—think—act” until it declares itself done. The problem with this architecture is not the number of iterations—it’s that every iteration quietly accumulates three kinds of drift.

    2.1 Goal Drift: The Task Gets Rewritten Through Retelling

    The model re-interprets “what am I doing” in every round. When the goal lives only in the conversation history, it gets paraphrased again and again as the context is compressed, truncated, and summarized. Like a game of telephone, by round ten the goal in the model’s “mind” may differ—subtly but fatally—from round one: “optimize API performance” slowly becomes “refactor the API code,” and “fix occasional timeouts” quietly becomes “rewrite the retry logic.”

    The hallmark of goal drift is that every step is reasonable, but the whole is wrong. Because each round’s deviation is tiny, no single point can trigger an alarm.

    2.2 Context Drift: Critical Constraints Get Pushed Out of Sight

    The context window is a scarce resource. During long tasks, massive volumes of tool outputs, logs, and intermediate code keep flooding in, pushing the original constraints—coding standards, prohibitions, compatibility requirements—out of the effective attention span. The model hasn’t “forgotten” the constraints; the information has simply been marginalized in the competition for attention.

    Typical symptoms: the directory-structure convention strictly followed in the first three rounds gets casually broken by round twenty; an external dependency explicitly forbidden at the start quietly slips in during some late-night iteration.

    2.3 Quality Drift: Acceptance Standards Loosen Under Fatigue

    Long tasks have another insidious slope: round-by-round erosion of quality standards. In early iterations, the model diligently writes tests and runs validations. As the task progresses, “get the feature working first” starts replacing “do it right”—test coverage drops, edge cases get skipped, and “leave it for now, fix it later” compromises pile up. The final deliverable works functionally but is a pile of technical debt engineering-wise.

    3. Upfront Spec: Pruning Wrong Branches Before Errors Happen

    The first line of defense against drift is investing sufficient “specification cost” before the loop starts.

    A common misconception is that specs are bureaucracy—the model will figure things out during execution. But the decision space of a long-horizon task is exponential: every round offers multiple reasonable branches, and if the wrong technical route is chosen at round 5, the tokens of the next 95 rounds run ever further down the wrong path. The cost of course correction grows exponentially with time.

    The value of an upfront Spec is pruning wrong branches at the root of the decision tree. A qualified Spec should answer at least four questions:

    1. Boundaries: what to do—and equally important—what not to do. Explicit exclusions are the most effective anchor against goal drift.
    2. Acceptance criteria: what “done” means. These must be mechanically verifiable conditions (tests pass, metrics met, files exist), not subjective descriptions like “feels good.”
    3. Technical constraints: permitted dependencies, directory conventions, compatibility baselines, forbidden operations.
    4. Phase breakdown: split the long task into independently verifiable milestones; each milestone is an opportunity to “check against the map.”

    A useful rule of thumb: in long-horizon tasks, every extra ten minutes spent on upfront specification saves hours of rework on average. The Spec is not a ceremonial document written for the model—it is the supreme constitution of the entire execution.

    4. External State Files: Handover Evidence for the “Next Operator”

    The second line of defense is acknowledging a fact: chat history is not reliable state storage. Conversation history gets truncated, compressed, and selectively forgotten by the model—and more importantly, it cannot be efficiently audited by humans or other agent instances.

    The core idea of a handover-ready architecture is to externalize all critical task state into a set of explicit, versioned text files. These files serve both as the current executor’s basis for action and as handover evidence for the “next operator”—whether a human engineer or a new agent session. A battle-tested file set typically includes:

    • GOAL.md: the task’s ultimate objective and acceptance criteria. During execution it may only be explicitly revised, never implicitly forgotten. Every round of action should be checked against it—this is the anchor against goal drift.
    • PLAN.md: the phased execution plan, recording each milestone’s status (not started / in progress / completed) along with summaries of what completed phases actually produced. The plan may be adjusted, but adjustments must leave a trace—write down why it changed.
    • STANDARDS.md: non-negotiable engineering constraints—code style, testing requirements, prohibitions. This is the guardrail against quality drift; every round’s output must be checkable against it.
    • PROGRESS.md: an append-only execution log recording what each round did, what was encountered, and what the next action is. It is the antidote to context drift—even if the session restarts, a new executor can read it and take over seamlessly.

    The deeper value of this design is liberating “continuity of memory” from the model’s context window and moving it onto the file system. A long-running agent’s session can crash, restart, switch models, or switch operators at any time—as long as this file set exists, the task is never lost. This is the true meaning of a “handover-ready harness”: not some clever prompt trick, but an architectural discipline that treats long tasks as transferable engineering assets.

    5. Implementation: A Minimal Viable Execution Loop

    Combining the analysis above, a minimal viable long-horizon execution loop can be described as:

    1. loop:
    2. 1. Read GOAL.md / STANDARDS.md — align with goal and constraints
    3. 2. Read PLAN.md — determine the current milestone and next action
    4. 3. Execute one atomic action (write code / run tests / change config)
    5. 4. Validate this round's output against acceptance criteria; roll back if it fails
    6. 5. Update PROGRESS.md (record facts) and PLAN.md (update status)
    7. 6. Check whether all acceptance conditions in GOAL.md are satisfied

    The key engineering disciplines are threefold: take only one small step per round, so errors are rollback-able; persist state to disk at the end of every round, so progress is recoverable; and periodically do a full check against GOAL.md rather than only inspecting the previous round’s output, so drift can be detected.

    In team practice, this file set can also plug into standard engineering infrastructure: use version control to record state evolution, object storage to share state across multiple executors, monitoring and alerting to track milestone timeouts and abnormal exits, and log services to aggregate execution traces for post-hoc audits. A long-running agent is not a model problem—it is a systems engineering problem.

    6. Conclusion

    In the competition over long-running agents, the first half was about “who can run longer”; the second half will inevitably be about “who can run more accurately.” Naive loops solve stamina, but correctness must be guarded by three things: an upfront Spec that prunes wrong branches before they happen, external state files that free memory from the fragile context window, and a handover-ready architecture that lets the task be reviewed, corrected, and transferred at any moment. When your agent can hand a clear GOAL, PLAN, STANDARDS, and PROGRESS to the “next operator” at any time, it truly evolves from a tireless executor into a trustworthy engineering partner.