Why AI Agents Succeed or Fail on the Same Task Across Ten Runs

    This article explains why an AI agent can pass a task on some runs and fail on others even with the same model and setup. It breaks down the main sources of uncertainty, shows how to diagnose failures by comparing successful and failed execution traces, and outlines practical fixes at the agent harness level, including environment isolation, faithful observation, explicit verification, and regression metrics for stability.

    1. The Core Problem: The Capability Is There, but Delivery Is Unstable

    Run the same agent, with the same model and the same task, ten times in a row. The results will sometimes succeed and sometimes fail. Many teams respond by assuming the model is not strong enough, so they switch to a larger model or tune more aggressive parameters. But a fact that is often overlooked is this: what really determines success or failure is usually not the model itself, but the middle layer between the model and the external world—the execution layer that translates model intent into real actions and translates real feedback back into a state the model can understand.

    The core contradiction is straightforward: the model has the capability to solve the problem, but the system cannot reliably deliver that capability. On a widely recognized, high-difficulty terminal task benchmark, a common execution framework paired with a strong model achieves a single-run pass rate of only about 50%, and the proportion of tasks that pass on every repeated attempt is under 40%. In other words, more than one-third of tasks fail on some attempts. This is not a capability problem; it is a stability problem.

    This article does not focus on any specific product or framework. It discusses a general technical issue: reliability engineering for the agent execution layer (harness).

    2. Why Results Vary: Breaking Down the Uncertainty

    Failures in long-chain tasks are usually not caused by a single point of error, but by a series of low-probability events. Suppose the success rate of a single operation is p, a task requires n steps, and the steps are approximately independent. The success rate of the entire chain is roughly p^n. When p=0.95 and n=20, the overall success rate drops to about 0.36. This explains why “every step seems fine” while the overall result is highly unstable.

    Uncertainty comes mainly from four sources:

    • Environment state drift: Temporary files, processes, caches, and port usage left behind by the previous run change the initial conditions of the next run.
    • Incomplete observation: The context passed back to the model by the execution layer is truncated, summarized, or filtered, so the model makes decisions based on partial information.
    • Action space ambiguity: The same intent can be implemented in multiple ways. Each sampling by the model may choose a different path, and some paths are unavailable in certain environments.
    • Missing termination and verification: There is no decidable acceptance criterion between “the task looks done” and “the task is actually correct,” leading to premature termination or incorrect convergence.

    Together, these four sources produce one result: the capability is present, but the initial conditions, observation quality, and action choices vary on every invocation, so the results fluctuate randomly.

    3. Diagnosis: Use Successful Traces as a Reference for Difference Attribution

    The approach in the paper is very practical and can be abstracted directly into an engineering method: find tasks that sometimes succeed and sometimes fail, use the successful run as a reference, compare the failed run frame by frame, and locate the difference to a specific mechanism in the execution layer.

    It breaks down into four steps:

    1. Layered metrics: Do not look only at the overall pass rate. Also record the single-run pass rate, the all-pass rate over k runs, and the failure distribution (whether failures are concentrated in a certain type of task or spread evenly).
    2. Trace retention: Fully save the action, parameters, environment feedback, elapsed time, and failure information for every step, forming a replayable trace.
    3. Difference comparison: Align the successful and failed traces of the same task and find the first action point where they diverge (divergence point).
    4. Mechanism attribution: Map the divergence point to an execution layer mechanism, such as the context trimming strategy, retry strategy, timeout settings, or environment initialization method.

    An illustrative record structure:

    1. {
    2. "task_id": "T-042",
    3. "run_id": "r7",
    4. "steps": [
    5. {"i": 1, "action": "read_file", "args": {"path": "a.txt"}, "ok": true, "ms": 12},
    6. {"i": 2, "action": "apply_patch", "args": {"hunk": 3}, "ok": false, "err": "context_mismatch"}
    7. ],
    8. "divergence_from_success": 2
    9. }

    As long as the divergence point can be reliably narrowed down to a few mechanisms, optimization turns from “mystical parameter tuning” into “targeted repair.”

    4. Fixes: Borrow Proven Designs and Shore Up the Execution Layer

    Once the mechanism is identified, fixes usually fall into the following directions, all of which are widely accepted practices in the industry:

    • Environment isolation and initialization: Use a clean, reproducible environment for each run and reclaim resources after the task ends to eliminate state drift.
    • Observation fidelity: Prioritize returning structured, complete key feedback and avoid summarizing too early; for long outputs, use “searchable truncation” rather than “direct discard.”
    • Reversible actions: Provide pre-checks and rollback paths for high-risk operations to reduce the chain effect of a single-step failure.
    • Explicit verification: Define “done” as a decidable check (tests passing, file checksums, API return codes) rather than the model’s own statement.
    • Failure classification and retry strategy: Distinguish retryable errors (transient conflicts) from non-retryable errors (logic errors) to avoid meaningless retries that amplify cost.

    A simplified execution loop:

    1. for step in range(max_steps):
    2. obs = env.observe() # faithful observation
    3. action = policy(obs) # model decision
    4. result = env.apply(action) # execute with pre-check
    5. if result.retryable and retries < limit:
    6. retries += 1
    7. continue
    8. if verifier.check(result): # explicit verification
    9. return SUCCESS
    10. return FAIL

    5. Verification and Regression: Turning Stability into a Sustainable Metric

    After fixes, you must verify quantitatively; otherwise it is easy to “fix one thing and break a dozen.” It is recommended to establish three regression metrics: single-run pass rate, all-pass rate over k runs, and average divergence point position. After each change to an execution layer mechanism, rerun on the same set of tasks and observe whether the all-pass rate over k runs improves and whether the divergence point moves later.

    Engineering practice can also introduce layered sampling: group tasks by chain length and prioritize long-chain tasks, because they are where stability problems are most concentrated. At the same time, keep a library of failed traces as regression cases for later changes.

    6. Conclusion

    When the same agent succeeds or fails across ten runs of the same task, in most cases it is not that the model is inadequate, but that the execution layer fails to reliably deliver the model’s capability. Make the metrics finer, keep the traces complete, align the divergence points, and fill in the mechanisms. Combined with decidable verification and regression testing, occasional success can gradually turn into stable delivery. This is also the key step for agent engineering to move from “it runs” to “it is deliverable.”