arXiv:2610.25776cs.AIOct 2026

Manuscript Offprint

arXiv:2610.25776

From Trace to Fix: Residual Task State in Long-Horizon Agents

Zile Huang, Ser-nam Lim

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

ABSTRACT

Recovering from failures in long-horizon, stateful language agents is challenging because the action introducing a defect, the symptom exposing it, and the persistent state requiring repair frequently diverge. Existing methods largely focus on retrospective failure attribution, leaving sequential diagnosis and state repair poorly integrated under constrained budgets. We introduce TRACE-FIX, a unified recovery framework centered on versioned residual task state. TRACE transforms execution logs into a structured dependency-linked ledger, prioritizing unresolved task requirements rather than salient surface errors. FIX formulates recovery as budgeted planning over admissible actions, incorporating outcome forecasting and explicit repair-reserve constraints to prevent premature budget exhaustion. To rigorously decouple localization accuracy from downstream repair capability, we present LongH-Debug, evaluating root-cause attribution, verified-fault recovery, and end-to-end closed-loop execution independently. Our empirical analysis demonstrates that structured residual tracking substantially improves causal localization over raw-trace baselines, while budget-aware sequential planning converts verified fault signals into more reliable task recovery without destructive trial-and-error. Code is available at https://github.com/toffeecat/tracedp.

1 INTRODUCTION

Language-model agents increasingly complete tasks by changing persistent state: they write files, update databases, invoke tools, create intermediate artifacts, and make decisions that later steps depend on (Dong et al., 2026; Zhou et al., 2024; Xie et al., 2024; Jimenez et al., 2024). In such tasks, the action that introduces a problem need not coincide with the step where the problem becomes visible. The environment can also change again before debugging begins. As a result, the historical cause, the observed symptom, and the state that currently needs intervention can be different.

A retained database-recovery run illustrates the distinction. A successful SQLite operation silently removes the write-ahead log that contains records needed later in the task. Subsequent commands continue normally, the actor eventually recognizes the mechanism, and the final failure occurs long after the destructive state transition. At recovery time, replaying the final error or blaming the latest suspicious command does not identify what information was lost; restarting from scratch would also discard work that remains valid. The useful recovery question is instead: which task requirement is still unsupported, which historical state change is relevant to it, and what affordable action can improve the task from here?

Prior work has made substantial progress on failure attribution, critical-step localization, counterfactual replay, and intervention-based verification (Zhang et al., 2025b; Chen et al., 2026; Ma et al., 2025; Liu et al., 2026; Zhang et al., 2025a; Qiao et al., 2026). These methods primarily organize evidence about what went wrong. Recovery adds a sequential decision problem: additional diagnosis consumes time and intervention budget, repair can invalidate earlier evidence, and the best next action depends on what will remain possible after its outcome. A more complete diagnosis is therefore not automatically a better recovery decision.

We address this problem with two components over a shared runtime state. TRACE represents current task requirements together with versioned execution evidence and ranks historical events that can explain requirements that remain unresolved. FIX plans over the legal checks, recovery actions, actor

A Delayed state mutation

db-wal-recovery

live run, 97 tool calls

0 · ls -la /app: base 8192B + log 16512B 2 × sqlite3 main.db ... PRAGMA wal.checkpoint: log deleted 9 · cp main.db-wal /tmp/...bak (already too late) 38 × the same read deletes the rebuilt log again 95 · the actor states the mechanism itself end × timeout, reward 0.0 A successful read removes the only carrier of the six missing records. Nothing errors, so the run repeatedly rebuilds and destroys the log.

C Blame is not a current fault

bn-fit-modify

live run, 8 checks

0 ✓ learned_dag.csv exists in to, from format 1 ✓ intervened DAG exists in to, from format 2 ✓ intervened sample keeps the column names 3 ✓ the DAG has six total edges 4 ✓ intervened edges are a subset of the learned DAG 5–7 ✓ repeated checks of the same conditions end ✓ 8/8 supported, reward 1.0, 0 repairs The history contains a failure, but the live state already satisfies every check. Historical blame is therefore not a current repair target.

B Residual obligation

openssl-selfsigned-cert

live run, 7 checks

1 × script-runs: /app/check_cert.py exits 1 2 ✓ verification-file: subject and fingerprint 3 ✓ key-attributes: 2048-bit RSA, mode 600 4 ✓ script-runs re-run: the same predicate passes 5 ✓ combined-pem parses as a certificate 6 ✓ ssl-directory-layout holds the deliverables 7 ✓ certificate-attributes: subject, 365-day validity end ✓ reward 1.0

The actor rewrites the script after the first failure; the same predicate then passes and the task reaches reward 1.0.

D Budgeted recovery

cancel-async-tasks

live run, 8 checks, 2 repairs

1–2 ✓ import-form and signature supported 3 × concurrent-execution refuted 4–6 ✓ max-concurrency, cancel-below, cancel-at supported 7 × cancel-above-limit refuted 8 ✓ import-form re-run: supported end × 2 repairs tried, reward 0.0

Eight checks and two repairs exhaust the twelve-unit budget before either repaired predicate is re-verified.

Figure 1: Four long-horizon failure modes from retained Terminal-Bench trajectories. (A) A successful operation silently destroys state whose loss appears only later. (B) A failed predicate is subsequently repaired, leaving only its residual consequences relevant. (C) A historical failure remains in the trajectory although the current state is already healthy. (D) Checks and repairs share a finite budget, which can be exhausted before repair verification. Rows quote retained commands or registered checks; ✓ and × denote supported and refuted outcomes.

continuation, and submission choices available at the current boundary. Its short-horizon outcome estimates are supplied from public runtime state, but action identity, costs, state transitions, and the dynamic-programming backup are enforced by runtime code. Every executed action produces a receipt; resource changes invalidate version-bound evidence, the residual state is recompiled, and the next decision is made from the new state.

We also introduce LongH-Debug, which separates retrospective localization from executable recovery. Localization is evaluated under matched public inputs; recovery methods are compared under the same independently verified fault packet; and a final factorial crossing tests whether the localization and recovery components compose end to end. This separation avoids crediting a fixer for hidden re-diagnosis or penalizing it for an upstream localization error.

Contributions. First, we define a versioned residual task representation that distinguishes current unsupported requirements from historical events that no longer require intervention. Second, we connect this representation to a practical recovery controller that combines public-state outcome forecasting with runtime-checked bounded planning and replanning after real execution. Third, LongH-Debug provides matched localization, verified-fault recovery, and closed-loop evaluation.

Figure

Figure 2: Runtime path from public history to recovery. The task contract, public execution record, resource versions, and registered checks are compiled into a residual state. TRACE uses the resulting dependency-linked ledger to rank historical events relevant to unresolved requirements. FIX receives the live action slate and a bounded public-state forecast, while runtime code checks action identity, cost, reachability, and time before computing the depth-two decision. The selected action is then executed; its receipt updates resource versions and evidence, the residual state is recompiled, and planning repeats before the same actor continues. Hypothetical planning outcomes are kept separate from observed execution receipts throughout.

protocols so that attribution quality and recovery quality can be measured separately before they are composed.