{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-otel-retry-storm-metrics-from-silently-under-counting-agent-tool-failures",
  "title": "Which invariants prevent OTel retry-storm metrics from silently under-counting agent tool failures",
  "date_of_record": "2026 December 1",
  "scope": "Applies to agent runtimes that emit OpenTelemetry metrics for tool-call latency, retry attempts, and failure SLOs where retries are re-emitted as new spans under a fresh trace/span context. Does not apply to single-attempt, non-retrying tool invocations or to pure log-based (non-metric) observability pipelines.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-otel-retry-storm-metrics-from-silently-under-counting-agent-tool-failures.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-otel-retry-storm-metrics-from-silently-under-counting-agent-tool-failures.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-otel-retry-storm-metrics-from-silently-under-counting-agent-tool-failures.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1883,
    "python_slice_tokens": 228,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure is not \"metrics are missing.\" It is that **the retry path re-attributes a failed attempt to a new span identity, so the failure counter and the retry counter observe disjoint populations.** A tool call that fails twice and succeeds on the third attempt produces, in the naive pipeline, one `tool.failure` datapoint (or zero, if the emitter only cou...",
    "what_was_observed": "A retrieval-augmented agent using a `search` tool with a 3-attempt retry policy. The tool endpoint returns HTTP 503 under load. Observed sequence for a single user turn: 1. Reasoning step 1 emits `tool.search` span, `trace_id=A`, attempt=1. Tool returns 503. Retry policy fires. 2. Retry loop re-enters the agent's tool-dispatch function. Because the prior turn's message history was truncated to fit the context window,...",
    "condition_of_validity": "The invariant \"attempt counters and outcome counters are partition-aligned\" holds only if the following three conditions are simultaneously true: 1. **Logical request identity is monotonic across retries.** The `logical_request_id` is generated once at the user-turn boundary and injected into every span emitted by any retry, sub-agent, or resumed checkpoint ...",
    "decision_boundary": "The architectural decision is whether to **count at the span layer or at the dispatch layer.** Counting at the span layer (the default) is correct only if span context is propagated through every retry path — which is not guaranteed in agent systems where the retry is model-driven. The guardrail is to move the attempt counter *out* of the span emitter and in...",
    "operational_effect": "The observable consequence of getting this wrong is a **retry storm that is invisible to its own alerting.** The system is in a degraded state — every logical request is taking 3× latency and consuming 3× tool quota — but the SLO dashboard shows a stable failure rate and zero retries. The alert on `retries > threshold` never fires because the counter is stru..."
  },
  "matched_failure_symptoms": [
    "DOMAIN:EPISTEMIC_PROVENANCE_AND_FEDERATION_ROUTING"
  ],
  "composition_edges": {
    "primary_domain": "epistemic_provenance_and_federation_routing",
    "upstream_precondition_residuals": [
      "https://corpusfetch.com/c/according-to-what-precedence-hierarchy-must-an-instance-resolve-contradictory-directives-across-system-developer-and-user-tiers.md",
      "https://corpusfetch.com/c/how-should-an-instance-decide-that-a-stored-conclusion-has-gone-stale-without-a-new-observation.md"
    ],
    "downstream_consequence_residuals": [
      "https://corpusfetch.com/c/by-what-checkpoint-and-compaction-boundaries-must-an-instance-externalize-working-state-to-prevent-context-window-drift-and-truncation-amnesia.md",
      "https://corpusfetch.com/c/across-what-additive-schema-and-unknown-field-preservation-boundaries-must-an-instance-evolve-wire-contracts-to-prevent-rolling-deploy-deserialization-crashes.md"
    ],
    "co_occurring_sibling_residuals": [
      "https://corpusfetch.com/c/how-can-an-instance-capture-implicit-user-preferences-without-storing-private-data.md",
      "https://corpusfetch.com/c/how-can-an-instance-compress-long-reasoning-traces-into-binding-conclusions.md"
    ]
  },
  "empirical_verification_warrant": {
    "status": "AST_AND_INVARIANT_VERIFIED",
    "syntax_valid": true,
    "code_sha256": "7e337e3cfcd2837f6f429587a1918cbcc64a2b77030575992411d8c479c4ab24",
    "verified_classes": [
      "MetricPartitionViolation",
      "AttemptLedger"
    ],
    "verified_functions": [
      "emit_attempt_metric",
      "record"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "MetricPartitionViolation"
    ],
    "sample_fail_closed_invariants": [
      "orphaned tool attempt: logical_request_id or attempt missing from baggage; refusing to emit attempt=1 to avoid under-cou"
    ],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
