Large Language Model (LLM) agents interact with their environments through tools, reading repositories, running builds, and pushing code. When a tool fails with an ordinary error, such as a rate limit or a timeout, the agent can fall back to a substitute tool and still complete the task. However, the same fallback that completes a task in one environment can cross an action boundary in another. For example, after a push is rejected, a forced push in one repository replaces only the agent's own commits, while in a different repository it also removes another author's commits. We call such a fallback a risky fallback. To understand this phenomenon, we conduct an empirical study on 304 scenarios that span eight domains and cover 55 real CVEs. All four mainstream models we evaluate exhibit risky fallback, with action-boundary violations in up to 96.8% of risky scenarios. We further evaluate three mainstream mitigations and find that none of them is effective against risky fallback. We then present nrepair. At each call to the substitute tool, nrepair scores the agent's context with a monitor whose threshold is calibrated on normal runs alone; when the monitor triggers, it withholds the call once and returns the decision to the agent. nrepair reduces action-boundary violations on all four models, by up to 76.0% (from 67.5% to 16.2%), at a negligible runtime cost. On most models, the normal success rate drops by less than 7%. We also evaluate nrepair on two production agents, Claude Code and Codex, and find that it is equally effective on both.
Figures & tables
Figure 1. The same fallback in a normal and a risky scenario. Red marks the two commits by another author that the push removes.
Normal
Risky
Model
SR
SR
MMR
OMR
ABV
DeepSeek
83.3
76.5
6.5
17.0
23.5
Luna
92.0
32.5
21.4
46.1
67.5
Qwen
98.0
3.2
26.6
70.1
96.8
Gemma
93.3
11.7
24.7
63.6
88.3
Table 1. Prevalence of risky fallback across the four models. MMR: missing-modification rate; OMR: over-modification rate.
Risky
Normal
Crossed but
Model
identified
flagged
identified
DeepSeek
96.8
24.7
86.1
Luna
90.9
25.3
89.4
Qwen
73.4
12.7
73.8
Gemma
70.1
19.3
69.1
Table 2. Boundary identification of the four models outside the agent loop.
Normal
Risky
Mitigation
SR
Blocked
ABV
Cost
None
98.0
0.0
96.8
–
Deliberative alignment ( Guan et al., 2025 )
92.7
0.0
88.3
0.62
AgentSpec ( Wang et al., 2026 )
0.0
98.7
0.0
0.99
GuardAgent ( Xiang et al., 2025 )
52.7
60.0
29.2
0.65
Table 3. Comparison of mainstream mitigations on Qwen. Blocked: share of normal runs blocked; Cost: normal successes lost per prevented violation.
Figure 2. Overview of nrepair . Offline: decision points are collected from recorded runs, the monitor is fitted on them, and its threshold is calibrated on normal runs; online: a call to S that scores at or above θ is withheld once with the repair prompt.
Normal
Risky
Monitor
Model
Configuration
SR
ABV
Recall
Precision
Cost
Qwen
No repair
98.0
96.8
–
–
–
nrepair
97.3
77.3
80.8
80.8
0.03
Gemma
No repair
93.3
88.3
–
–
–
nrepair
91.3
55.8
83.0
80.6
0.06
Luna
No repair
92.0
67.5
–
–
–
Table 4. Effectiveness of nrepair across the four models.
Generalization
Model
Threshold from
Decision points
AUROC
Recall
Unseen tasks
Qwen
Qwen
296
0.904
81.9
Unseen models
Gemma
Gemma
276
0.887
80.1
Gemma
Qwen
276
0.887
75.7
Luna
Luna
242
0.897
84.6
DeepSeek
DeepSeek
161
0.843
75.0
White-box monitor
Table 5. Generalization of the monitor to unseen tasks and models at β=20% .
Stage
Component
Frequency
Latency
Added tokens
Offline
Fitting the monitor
Once per agent model
7.5 s
0
Online
Embedding the context
1.1–1.4 per run
66 ms
0
Linear classifier
1.1–1.4 per run
2.8 μ s
0
Repair prompt
Once per trigger
One step
103
Table 6. Overhead of nrepair on Qwen and Gemma.
Normal
Risky
Monitor
Agent response
Model
Configuration
SR
ABV
Precision
σ
ρ
Cost
Qwen
No repair
98.0
96.8
–
–
–
–
nrepair
97.3
77.3
80.8
23.1
7.4
0.03
Without monitor
90.0
70.8
50.7
26.4
6.2
0.30
With refusal
80.7
18.8
80.8
100.0
100.0
0.22
Gemma
No repair
93.3
88.3
–
–
–
–
Table 7. Ablation of the monitor and the intervention of nrepair . σ : stop rate of triggered risky runs; ρ : abandon rate of triggered normal runs.
Model
Prompt
σ
ρ
SR
ABV
Cost
p
Qwen
Prompt defense
25.9
3.8
97.3
74.7
0.03
0.75
Generic
27.2
3.7
98.0
72.7
0.00
Gemma
Prompt defense
42.5
12.0
91.3
55.8
0.06
<10−4
Generic
19.4
8.7
90.7
72.7
0.17
Luna
Prompt defense
87.8
42.9
80.0
16.9
0.23
<0.001
Generic
62.5
17.1
86.0
28.6
0.15
Table 8. Impact of the prompt defense on replayed triggers. p : McNemar test on triggered risky scenarios.
Normal
Risky
Monitor
Model
Configuration
SR
ABV
Recall
Precision
Cost
Luna
No repair
92.0
67.5
–
–
–
β=20%
79.3
16.2
84.8
70.1
0.24
β=10%
84.7
24.0
71.0
80.0
0.16
DeepSeek
No repair
83.3
23.5
–
–
–
β=20%
77.9
11.8
65.7
44.2
0.44
Table 9. Impact of the budget ( β ) on Luna and DeepSeek.
SR (normal)
ABV (risky)
Agent
No repair
nrepair
No repair
nrepair
Claude Code
100.0
93.8
68.8
6.3
Codex
100.0
100.0
100.0
25.0
Table 10. Effectiveness of nrepair on two production agents over 16 runs per cell.
LLM agents often fail mid-task due to invalid tool calls, repeated actions, or poorly grounded reasoning, and learning from these failures is a path to reliability. We find that how failure knowledge reaches the agent matters as much as what it contains. Failure lessons are conditional: kept in the agent's context, they misfire when their failure is absent, and removing them from an evolving playbook improves performance. Runtime interventions, in contrast, act only when a failure occurs but do not learn from their repairs. We argue that failure knowledge is conditional knowledge and should be conditionally exposed, and instantiate this principle in Sentry, a failure-management layer that runs alongside the agent. When Sentry detects a failure, it retrieves matching lessons from an external playbook to guide recovery, verifies without access to task rewards whether the agent recovered, and stores a new lesson only if it did; the full playbook never enters the agent's context. Across multiple agentic benchmarks, Sentry outperforms the strongest runtime-intervention baseline on every benchmark, by 37% on average, and the strongest context-evolution baseline by 39% on the two benchmarks where both are evaluated; combining Sentry with context evolution yields further gains. Learned lessons transfer to held-out tasks, and controlled experiments show that exposing the full playbook to the agent lowers performance even when relevant lessons remain available on demand.
Changxiu Ji, Amy Lu, Qizheng Zhang +1
Department of Computer Science, Stanford University
LLM agents fail mid-episode -- they loop, cascade tool errors, drift off goal, fabricate results, or silently absorb corrupted content -- and the standard remedy, judging every step with a second LLM, costs more than the agent itself. We ask how much detection is achievable from observable step telemetry alone, using monitors costing microseconds per step and trained only on healthy runs. On 2,823 committed agent episodes across three frameworks, three local models (qwen2.5 7b/3b, llama3.1 8b) and a commercial API (gemini-2.5-flash), a one-class echo-state-network ensemble with CUSUM alarms detects 0.71 of failures at a 5% false-alarm budget (AUROC 0.872). Its advantage over a memoryless baseline is a monotone function of post-onset horizon (+0.09 at <=3 steps, +0.40 at >=9), predicting its own failure region out of sample on AFTraj-2K. Ranking transfers with no retraining to two corpora from other groups (AFTraj-2K 0.745, ATBench 0.779). Monitors carry two burdens: a per-deployment healthy null (they do not transfer -- AUROC 0.527 cold against 0.885 recalibrated) and a residual false-alarm rate. We add a layer carrying neither: deterministic verification, which recomputes a run's stated total from the tool results it actually received and confirms every required call was made. Head-to-head it catches 60% of failures (96% with the coverage check) at 0 of 63 false positives against the monitor's 54% at 17%, transfers unchanged to llama3.1:8b (110 of 110 at 0 of 10), and trips on 0 of 1825 healthy episodes. Detection is then closed into repair: each flagged run is rolled back and re-run live, recovering 45% of failures against a 16% resampling control (p=0.0005) and lifting task success from 52% to 73% for about one extra model call per run. The system runs at ~200 microseconds per step, three orders of magnitude below a judge call. Code, traces and results are released.
Existing benchmarks evaluate Tool-Integrated Reasoning (TIR) in LLMs on idealized ''happy paths'', largely overlooking real-world tool failures. We introduce ToolMaze, a benchmark for dynamic path discovery and error recovery in TIR agents. To separate systematic replanning from blind trial-and-error, ToolMaze adopts a two-dimensional design: DAG-based topological complexity and a 2×2 taxonomy of tool perturbations (explicit/implicit, transient/permanent). Evaluations show that perturbations degrade performance across nearly all models, with the sharpest drops under implicit semantic failures. Driven by systemic over-trust in corrupted outputs, Perturbation Recovery Rate (PRR) plummets by around 37% in these scenarios, while complex topologies trap agents in futile trial-and-error loops. Crucially, agentic fault-tolerance improves with model scale 3.66× slower than basic task execution, highlighting dynamic replanning as a distinct bottleneck unaddressed by model scaling or prompting. Data and code are available at https://github.com/Zhudongsheng75/ToolMaze.
Dongsheng Zhu, Xuchen Ma, Yucheng Shen +5
Shanghai AI Laboratory · East China Normal University · Soochow University +2