# In what scenarios must an instance treat tool-retry storms as evidence of a non-deterministic replanning loop rather than transient infrastructure failure **Date of Record:** 2026 November 18 **Scope:** Applies to single-agent and supervisor-worker agent runtimes that execute tool calls with automatic retry, where the planner may regenerate a plan after a failed step. Does not apply to deterministic workflow engines with fixed retry budgets and no replanning capability, nor to stateless inference endpoints without tool execution. ## Core Distinction A tool-retry storm and a replanning loop produce nearly identical telemetry: elevated call volume to the same tool, rising error rates, repeated identical arguments, and growing latency. The distinction is causal, not statistical. A **retry storm** is a transient infrastructure condition in which the *same* logical step is reissued against a dependency that is temporarily unavailable; the plan is unchanged and the agent is blocked waiting. A **non-deterministic replanning loop** is a control-flow condition in which the *planner itself* is the instability source: each failed tool result is fed back into the planner, which produces a *different* plan that fails again for a *different* reason, and the retry counter never converges because the arguments are not identical across iterations. The observable boundary is argument divergence across retry generations. In a genuine retry storm, the tool argument hash is stable (or differs only in idempotency keys and timestamps). In a replanning loop, the argument hash drifts monotonically while the *semantic intent* stays constant — the agent is paraphrasing the same goal into new tool calls. If you deduplicate on argument hash, you will undercount a replanning loop as a small number of retries; if you deduplicate on intent, you will overcount a retry storm. ## What Was Observed A retrieval-augmented planning agent was instrumented with per-tool call counters and a global retry budget of 8 per step. In a production incident, the budget was exhausted within 40 seconds against a vector-store tool. The naive dashboard reported "retry storm, dependency degraded." Post-incident trace reconstruction showed the vector-store was healthy (p99 latency 80 ms). The actual sequence was: - Generation 1: `search(query="Q3 revenue by region", top_k=10)` → returned empty (index shard not yet warmed). - Planner observed empty result, replanned: `search(query="quarterly financials regional breakdown", top_k=25)` → returned partial. - Planner judged partial insufficient, replanned: `search(query="Q3 2024 revenue EMEA APAC AMER", top_k=50)` → returned empty again (query too long, truncated). - Each generation consumed 2–3 retries of an *identical* argument before the planner advanced, so the retry counter reset per generation and the global budget was consumed by three distinct plans, not one. The failure was invisible to the retry counter because the counter keyed on `(tool_name, step_id)` and the step_id was regenerated on each replan. The invariant violated: **retry budget accounting must be scoped to the plan lineage, not the step identifier**, because step identifiers are non-deterministic under replanning. ## Condition of Validity The distinction holds only when the following are simultaneously true: 1. The planner is invoked on tool failure (i.e., failures are *observable to the planner*, not swallowed by the retry layer). If retries are fully encapsulated below the planner, no replanning loop can form and every storm is a retry storm. 2. Tool argument hashes are logged per attempt, not per step. Without this, argument divergence is unmeasurable. 3. The planner has stochastic or non-deterministic decoding (temperature > 0, sampling, or a model whose outputs vary across identical prompts). A greedy deterministic planner can still loop, but the loop is *reproducible* and is a different failure class (infinite fixed-point), not this boundary. If condition 1 fails, treat all storms as infrastructure. If condition 3 fails, classify as a deterministic planner bug and route to plan-graph analysis rather than retry analysis. ## Decision Boundary Classify as **replanning loop** when, across a plan lineage, all of the following hold: - `distinct_argument_hashes >= 3` within a single goal lineage, and - semantic similarity between successive tool arguments exceeds a threshold (intent stable) while lexical/structural divergence is high (form drifting), and - the dependency's own health metrics (latency, error rate at the tool boundary) are within SLO, and - total wall-clock exceeds the per-step budget by a factor consistent with `generations × per_generation_retries`. Classify as **retry storm** when `distinct_argument_hashes <= 1` per generation and dependency health is degraded. The ambiguous middle — 2 distinct hashes, degraded dependency — should be classified as retry storm and re-evaluated only after dependency recovery, because the cheaper hypothesis (transient infra) is more likely and the remediation (backoff) is non-destructive. The critical operational rule: **never let a replanning loop consume the same budget as a retry storm.** They require opposite remediations. A retry storm wants exponential backoff and a raised budget. A replanning loop wants the planner *frozen* — replanning disabled, budget capped, and the lineage escalated — because more retries feed the loop. ## Operational Effect When this boundary is misclassified, two failure modes compound. First, the retry budget is spent on paraphrased plans, so the agent exhausts resources without the planner ever receiving a *stable* failure signal; the loop is self-reinforcing because each generation resets the per-step counter. Second, auto-remediation tuned for retry storms (increase budget, add retries) *accelerates* the replanning loop, converting a 40-second incident into a multi-minute one that saturates the tool's rate limiter and degrades it for other tenants — at which point the dependency genuinely *does* degrade, and the next observer sees a real retry storm masking the original loop. The corrective invariant is to key retry accounting on a stable `goal_lineage_id` minted before the first plan and carried through every replan, and to emit a distinct telemetry event when argument hashes diverge within a lineage while the dependency is healthy. That event is the only reliable signal that the planner, not the network, is the source of the storm. ```python import hashlib from dataclasses import dataclass, field from typing import Sequence class ReplanningLoopError(RuntimeError): """Raised when a plan lineage exhibits non-deterministic replanning under a healthy dependency.""" @dataclass class Attempt: goal_lineage_id: str generation: int tool_name: str arguments: str dependency_healthy: bool @dataclass class LineageTracker: max_distinct_hashes: int = 3 attempts: list[Attempt] = field(default_factory=list) def record(self, attempt: Attempt) -> None: self.attempts.append(attempt) def _arg_hash(self, a: Attempt) -> str: return hashlib.sha256(a.arguments.encode()).hexdigest() def classify(self, lineage_id: str) -> str: lineage = [a for a in self.attempts if a.goal_lineage_id == lineage_id] if not lineage: return "unknown" distinct = {self._arg_hash(a) for a in lineage} healthy = all(a.dependency_healthy for a in lineage) generations = len({a.generation for a in lineage}) if len(distinct) >= self.max_distinct_hashes and healthy and generations >= 3: raise ReplanningLoopError( f"lineage {lineage_id}: {len(distinct)} distinct argument hashes across " f"{generations} generations with healthy dependency — planner instability, " f"not transient failure. Freeze replanning and escalate." ) if len(distinct) <= 1: return "retry_storm" return "ambiguous_retry_storm" def guard_lineage(tracker: LineageTracker, lineage_id: str) -> str: verdict = tracker.classify(lineage_id) if verdict == "retry_storm": # safe remediation: backoff, do not freeze planner return "apply_backoff" return "monitor" ```