AI Agent Reliability: The Overlooked Role of the Execution Harness
Why does an AI agent complete a task in one run but fail on the next? This article examines how the execution harness can cause inconsistent outcomes through output truncation, context growth, weak completion checks, and missing recovery mechanisms. It outlines a workflow for comparing successful and failed runs, improving harness behavior without changing model weights, and building a measurable reliability loop.
An AI assistant writes code and runs scripts flawlessly on its first attempt. The next day, given the same task, it stalls halfway through—or declares success even though the work is incomplete.
When the same agent, configuration, and task produce inconsistent outcomes, the task is often described as a flaky task. This behavior points to an overlooked issue: the industry has spent years making models smarter through reinforcement learning and trajectory synthesis, while paying less attention to the layer connecting models to the outside world.
The Overlooked Layer: The Execution Harness
For a large language model to complete tasks through a computer terminal, a runtime layer must receive its instructions, translate them into executable commands, run those commands, and return the results to the model.
This layer is commonly called an agent harness or execution harness. It handles command execution, observation feedback, context management, and completion checks. In effect, it acts as both interpreter and coordinator between the model and its environment.
The same model can perform very differently depending on the harness around it. Consider a skilled interpreter who repeatedly omits important details or fails to ask necessary follow-up questions. The resulting communication can still be unreliable—not because of poor language skills, but because of a flawed workflow.
Likewise, an agent’s bottleneck may lie not in the model’s reasoning ability, but in how the harness turns that ability into action.
Why Flaky Tasks Are Hard to Run Reliably
On a challenging terminal-task benchmark containing roughly 100 long, multistep tasks, researchers observed a characteristic pattern. A commonly used terminal harness paired with mainstream large language models achieved an average per-run pass rate of about 50% across repeated trials. The share of tasks that succeeded in every trial was substantially lower.
In other words, many tasks failed in at least some attempts, even though the agent could solve them in others.
The central problem is the gap between capability and reliable execution: the model can solve the task, but the system cannot consistently translate that capability into a successful outcome. Several harness-level weaknesses can contribute:
- Observation truncation: Long command outputs are cut off indiscriminately, removing critical errors and causing the model to draw incorrect conclusions.
- Context growth: Conversation history accumulates across turns, consuming the context window and burying important earlier information.
- Weak completion checks: A command’s zero exit code is treated as proof of success, without checking whether the intended effects actually occurred.
- Missing error recovery: Failures have no rollback or retry strategy, allowing one mistake to cascade into subsequent steps.
Improving the Harness Without Changing the Model
One engineering approach to flaky tasks is to iteratively improve the harness while leaving model weights unchanged. The process follows a four-step feedback loop:
- Sample and identify: Run the same task multiple times and select cases that sometimes succeed and sometimes fail.
- Compare trajectories: Use a successful run as a reference and compare it step by step with a failed run to locate where execution diverged.
- Map differences to mechanisms: Attribute the divergence to a specific harness mechanism, such as output truncation or completion logic, rather than automatically blaming the model.
- Adapt and patch: Draw on design ideas from other mature harnesses, fix the identified weakness, and run regression tests.
The following pseudocode illustrates the loop:
def evolve_framework(task, framework, model, rounds=4):runs = [run(task, framework, model) for _ in range(rounds)]if all_success(runs) or all_fail(runs):return framework # Not a flaky task; skip this workflowsuccess = pick_success(runs)failure = pick_failure(runs)diff = diff_trajectories(success, failure) # Compare trajectoriespatch = locate_mechanism(diff) # Map to a harness mechanismreturn apply_patch(framework, patch) # Patch, then regression-test
The goal is to turn inconsistent outcomes into actionable evidence about the execution system.
Practical Ways to Improve Agent Reliability
Developers can start by strengthening several general-purpose harness capabilities:
- Structured observations: Use layered summaries and key-field extraction for long outputs instead of indiscriminate truncation.
- Context management: Apply rolling compression while preserving essential information, keeping the limited context window focused on what matters most.
- Strict completion checks: Combine exit codes, artifact validation, and checks of intended side effects rather than relying on a single success signal.
- Rollback-capable execution: Provide snapshots and retries for high-risk operations so failed attempts can be repeated safely.
- Observability: Use logging and monitoring services to retain complete execution trajectories for each run, enabling comparisons between successful and failed attempts.
In cloud deployments, container platforms can host isolated execution environments, object storage can archive run trajectories, and logging and monitoring services can support failure attribution. Together, these components make reliable execution a measurable, iterative engineering process.
Conclusion
Flaky tasks often expose weaknesses in the execution harness rather than a lack of model capability. Treating the harness as a first-class engineering component—and continuously improving how it executes, observes, manages context, and verifies results—is key to moving AI agents from occasional impressive successes toward dependable performance.
