{
  "schema_version": "1.3.0",
  "slug": "how-does-an-instance-detect-double-counted-token-usage-when-opentelemetry-genai-spans-are-retried-across-an-agent-handoff",
  "title": "How does an instance detect double-counted token usage when OpenTelemetry GenAI spans are retried across an agent handoff",
  "date_of_record": "2026 November 11",
  "scope": "Applies to instrumentation that emits `gen_ai.*` spans (per the OpenTelemetry GenAI semantic conventions) for tool calls, model invocations, and agent-to-agent handoffs, where a parent agent span may be retried or re-emitted by an upstream orchestrator. Does not apply to single-shot leaf model calls with no retry wrapper, nor to pure trace-only deployments where token sums are never aggregated by a downstream consumer.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-double-counted-token-usage-when-opentelemetry-genai-spans-are-retried-across-an-agent-handoff.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-double-counted-token-usage-when-opentelemetry-genai-spans-are-retried-across-an-agent-handoff.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-double-counted-token-usage-when-opentelemetry-genai-spans-are-retried-across-an-agent-handoff.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1682,
    "python_slice_tokens": 371,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` as attributes of a *model invocation span*. They are additive facts about a single call to a model endpoint. They are **not** facts about a logical agent turn. The conventions deliberately leave retry, hedging, and handoff semantics unspecified, which means the...",
    "what_was_observed": "In a two-agent pipeline (planner → executor) with a retry wrapper around the executor's model call, a dashboard reading `sum(gen_ai.usage.input_tokens)` over the trace reported 3.1× the tokens actually billed by the provider. Decomposition: - Planner span: 1 invocation, 1,840 input / 210 output tokens. Correct. - Executor span: 1 logical invocation, but 2 physical attempts (first attempt returned a 429; retry succeed...",
    "condition_of_validity": "The aggregation is valid (i.e., summing `gen_ai.usage.*` over spans yields the billed total) **only if all of the following hold**: 1. **No retried spans carry usage attributes.** If a retry wrapper emits usage on failed attempts, the sum is invalid. Either suppress usage attributes on failed attempts or mark them with a non-standard `gen_ai.retry.failed = t...",
    "decision_boundary": "An instance should treat a token sum as **authoritative** when the trace contains only leaf model-invocation spans with no retry siblings and no handoff inheritance. It should treat the sum as **advisory** (and emit a warning span attribute) when any of the following are detected: - Two spans with the same `gen_ai.request.model`, overlapping time ranges, and...",
    "operational_effect": "Downstream consumers that do not enforce the partition will over-attribute cost to agents, mis-rank agents by token efficiency, and — in the worst case — trigger rate-limit backoff logic based on a token rate that is 2–3× the provider's actual rate, causing self-inflicted throttling. The corrective action is not to change the conventions but to add a *partit..."
  },
  "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": "95e6c3a0f6f77cca2269e4515fe559c4cd25abc57f12c5ce275f3766ac2f4cf7",
    "verified_classes": [
      "TokenPartitionError",
      "GenAISpan"
    ],
    "verified_functions": [
      "_overlaps",
      "assert_token_partition"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "TokenPartitionError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
