{
  "schema_version": "1.3.0",
  "slug": "what-structural-signals-indicate-token-accounting-drift-when-opentelemetry-genai-span-attributes-are-split-across-a-retry-boundary",
  "title": "What structural signals indicate token-accounting drift when OpenTelemetry GenAI span attributes are split across a retry boundary",
  "date_of_record": "2026 November 24",
  "scope": "Applies to agent runtimes that emit OpenTelemetry spans conforming to the GenAI semantic conventions (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, `gen_ai.operation.name`, `gen_ai.tool.name`, etc.) and that perform internal retries or tool-call re-issuance beneath a single logical agent step. Does not apply to systems where each retry is surfaced as a fully distinct top-level trace with no parent `invoke_agent` span, nor to purely streaming tokenizers that never reconcile usage post-hoc.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-token-accounting-drift-when-opentelemetry-genai-span-attributes-are-split-across-a-retry-boundary.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-token-accounting-drift-when-opentelemetry-genai-span-attributes-are-split-across-a-retry-boundary.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-token-accounting-drift-when-opentelemetry-genai-span-attributes-are-split-across-a-retry-boundary.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2091,
    "python_slice_tokens": 445,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions describe *what* to record on a span — `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, `gen_ai.operation.name`, `gen_ai.tool.name`, `gen_ai.tool.call.id` — but they do not specify the *cardinality contract* between a logical agent step and the physical spans that realize it. When an agent retries a model call or re-is...",
    "what_was_observed": "An agent executing a multi-step tool-use loop emitted, for a single logical \"resolve customer record\" step, the following span structure: Three structural signals appeared, none of which are schema violations: 1. **Duplicate `gen_ai.tool.name` with divergent `gen_ai.tool.call.id` under one parent.** The retry re-issued the tool call with a new call ID (`call_a1` → `call_a2`). Any downstream consumer that deduplicates...",
    "condition_of_validity": "The additive-correctness invariant holds only under this condition: > For a logical agent step `S` with span subtree `T(S)`, the authoritative token cost is `sum(usage over all spans in T(S) that actually invoked a model or tool, including ERROR-status spans)`, and this sum equals the provider's billed cost for `S` **if and only if** every retry is represent...",
    "decision_boundary": "The runtime must choose, at the moment a retry is triggered, between two representations, and the choice is irreversible for accounting purposes once the span is exported: - **Materialize the retry** (new child span, fresh `gen_ai.tool.call.id`, usage on the child, no usage on the parent): accounting is additive-correct; cost is recoverable by subtree sum; f...",
    "operational_effect": "The observable consequence is a divergence between telemetry-derived cost and provider-invoiced cost that is *proportional to retry rate* and *invisible in any single span*. At a 12% tool-timeout retry rate with ~200 output tokens per aborted attempt, a workload billing 10M output tokens/month shows ~2.4M tokens of aborted-attempt usage that appears in neith..."
  },
  "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": "386c1edf69af84f56ab5cb0c4a74ba327eff4b33fd3eafcc23ac5aa3380ac9c9",
    "verified_classes": [
      "TokenAccountingDriftError",
      "Span"
    ],
    "verified_functions": [
      "reconcile_step_cost",
      "walk",
      "check_partial_failures"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "TokenAccountingDriftError"
    ],
    "sample_fail_closed_invariants": [
      "usage recorded on both invoke_agent parent and its children; subtree sum would double-count"
    ],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
