{
  "schema_version": "1.3.0",
  "slug": "how-does-an-instance-detect-the-otel-genai-span-accounting-divergence-that-occurs-when-a-tool-call-span-reopens-after-a-speculative-retry",
  "title": "How does an instance detect the OTel GenAI span-accounting divergence that occurs when a tool-call span reopens after a speculative retry",
  "date_of_record": "2026 November 28",
  "scope": "Applies to agent runtimes that emit OpenTelemetry GenAI semantic-convention spans (`gen_ai.*`) for LLM invocations and tool calls, where a single logical tool call may be retried or speculatively re-executed within the same trace. Does not cover spans emitted by the model provider itself, nor plain HTTP instrumentation without GenAI attributes.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-the-otel-genai-span-accounting-divergence-that-occurs-when-a-tool-call-span-reopens-after-a-speculative-retry.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-the-otel-genai-span-accounting-divergence-that-occurs-when-a-tool-call-span-reopens-after-a-speculative-retry.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-the-otel-genai-span-accounting-divergence-that-occurs-when-a-tool-call-span-reopens-after-a-speculative-retry.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1516,
    "python_slice_tokens": 317,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat a tool call as a *child span* of an agent invocation span, with token usage (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`) recorded on the LLM invocation span that produced the tool-call request, and tool latency/outcome recorded on the tool span. The convention assumes a **one-to-one mapping between a logica...",
    "what_was_observed": "A coding agent with a `run_shell` tool was observed emitting, for a single `git status` invocation: - `span_id=A` — LLM invocation, `gen_ai.usage.input_tokens=842`, `output_tokens=61`, produced tool-call intent. - `span_id=B` — tool span, `gen_ai.tool.name=run_shell`, `gen_ai.tool.call.arguments_hash=...`, status `ERROR` after 30s (SIGTERM timeout). - `span_id=C` — LLM invocation, `gen_ai.usage.input_tokens=903`, `ou...",
    "condition_of_validity": "The invariant \"trace token sum equals billed tokens\" holds only when: 1. Every LLM invocation span is emitted exactly once per model call, and 2. Every tool span is a leaf with no sibling sharing the same logical identity, and 3. The aggregator's join path is `span_id`-keyed, not `parent_span_id`-keyed. The invariant **fails** when any of: speculative retry,...",
    "decision_boundary": "An instance must treat a tool span as **superseded** (not merely failed) when a subsequent tool span with identical `gen_ai.tool.name` and `arguments_hash` appears under the same logical parent within the same trace. The decision boundary is: - If the retry decision LLM span (`span_id=C`) exists, the original tool span (`B`) must be annotated `gen_ai.tool.ca...",
    "operational_effect": "Without the guardrail, per-tool token dashboards over-report by the input tokens of every retry-decision prompt — in the observed case, a 107% inflation (1,745 vs 842) for a single tool. Cost attribution per tool becomes unusable for budget enforcement, and a token-budget governor that reads the inflated per-tool figure will throttle the agent prematurely. T..."
  },
  "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": "66d7f222307c447a4db270eff7a5a1650a0af5f84c13d8ed8be187491c1f255f",
    "verified_classes": [
      "SpanAccountingDivergence",
      "ToolSpan",
      "TraceLedger"
    ],
    "verified_functions": [
      "record_retry",
      "emit",
      "per_tool_token_attribution"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "SpanAccountingDivergence"
    ],
    "sample_fail_closed_invariants": [
      "retry does not match original logical call; not a speculative retry"
    ],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
