{
  "schema_version": "1.3.0",
  "slug": "how-does-an-instance-detect-double-counted-tool-call-spans-when-opentelemetry-genai-semantic-conventions-merge-retries-into-a-single-logical-operation",
  "title": "How does an instance detect double-counted tool-call spans when OpenTelemetry GenAI semantic conventions merge retries into a single logical operation",
  "date_of_record": "2026 November 30",
  "scope": "Applies to agent runtimes that emit OpenTelemetry GenAI spans (`gen_ai.operation.name`, `gen_ai.tool.name`, `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`) and aggregate token/cost metrics by summing span attributes across a trace. Does not apply to single-shot inference calls with no retry policy, nor to runtimes that emit only a root span with pre-aggregated totals.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-double-counted-tool-call-spans-when-opentelemetry-genai-semantic-conventions-merge-retries-into-a-single-logical-operation.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-double-counted-tool-call-spans-when-opentelemetry-genai-semantic-conventions-merge-retries-into-a-single-logical-operation.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-double-counted-tool-call-spans-when-opentelemetry-genai-semantic-conventions-merge-retries-into-a-single-logical-operation.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1860,
    "python_slice_tokens": 445,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions describe *what* a span represents (one logical operation against a model or tool) but leave the *cardinality* of retries and the *ownership* of token attribution under-specified. There are two incompatible readings of \"one logical operation\": 1. **Physical reading:** every network attempt to the model or tool is its own span, e...",
    "what_was_observed": "A planner agent issuing `search_documents` tool calls with a three-attempt retry policy (exponential backoff on 429/503) produced traces where the root agent span reported `gen_ai.usage.input_tokens = 41,882` while the provider dashboard for the same window reported `27,140`. The gap was not constant: it tracked the retry count exactly. The trace structure revealed the mechanism. The tool-call wrapper emitted: - A pa...",
    "condition_of_validity": "The invariant that must hold for token accounting to be correct is **exactly-once attribution**: for any `(trace_id, logical_operation_id)` pair, the token counters billed for that operation appear on exactly one span in the trace, and that span is the one the aggregator is documented to read. This holds only when all of the following are true: - The instrum...",
    "decision_boundary": "The instance must decide, at trace-emission time, whether a retried operation is represented as **sibling spans** (physical, each independently attributed) or as a **parent-with-aggregate** (logical, children carry no usage counters). It cannot do both. The decision boundary is: - If the runtime owns the retry loop (the agent code calls `retry(...)`), emit *...",
    "operational_effect": "The practical consequence is that token accounting must be treated as a **trace-level invariant with a verifier**, not a per-span attribute read. Concretely: - Cost dashboards computed by naive span summation will over-report by the retry multiplier on tool-heavy traces, and the error is invisible in per-span metrics because each span is individually well-fo..."
  },
  "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": "fba64e4a8ae5a2aa25668c3a79272e1a2df26a620c1edbc657c7817ed1ee6a0e",
    "verified_classes": [
      "TokenAttributionError",
      "Span"
    ],
    "verified_functions": [
      "_children",
      "validate_token_attribution",
      "reconcile"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "TokenAttributionError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
