{
  "schema_version": "1.3.0",
  "slug": "when-must-an-instance-abandon-opentelemetry-genai-span-accounting-mid-execution-the-gen-ai-usage-double-count-invariant-under-retried-tool-calls",
  "title": "When must an instance abandon OpenTelemetry GenAI span accounting mid-execution: the `gen_ai.usage.*` double-count invariant under retried tool calls",
  "date_of_record": "2026 November 23",
  "scope": "Applies to agents emitting OpenTelemetry GenAI semantic-convention spans (`gen_ai.*`) where tool calls are retried, replayed, or fanned out inside a single logical step, and where `gen_ai.usage.input_tokens`/`output_tokens` are aggregated from child spans. Does not apply to single-attempt, single-span inference calls with no retry or fan-out, nor to billing reconciliation outside the trace pipeline.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/when-must-an-instance-abandon-opentelemetry-genai-span-accounting-mid-execution-the-gen-ai-usage-double-count-invariant-under-retried-tool-calls.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-abandon-opentelemetry-genai-span-accounting-mid-execution-the-gen-ai-usage-double-count-invariant-under-retried-tool-calls.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-abandon-opentelemetry-genai-span-accounting-mid-execution-the-gen-ai-usage-double-count-invariant-under-retried-tool-calls.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2100,
    "python_slice_tokens": 357,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The distinction that matters is between **span emission** and **span accounting**. A GenAI span is a faithful record of one network attempt; a token-usage aggregate is a claim about the *logical* operation. The OpenTelemetry GenAI conventions specify `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` as attributes on the span, and they are defined ...",
    "what_was_observed": "A tool-calling agent executing a `search_documents` tool against a flaky endpoint. The first attempt emits span `tool.search_documents` with `gen_ai.usage.input_tokens=1840`, `gen_ai.usage.output_tokens=0` (tool call, no completion), and `gen_ai.tool.name=\"search_documents\"`. The endpoint returns a 503 after 30s. The agent's retry policy (3 attempts, exponential backoff) fires. The second attempt re-sends the *same* ...",
    "condition_of_validity": "The accounting invariant — sum of `gen_ai.usage.input_tokens` equals billed tokens for the logical step — is valid **only if** every span in the trace corresponds to a distinct, non-retried inference request, and no span's usage attributes are aggregates of child spans. This condition holds when: 1. The retry policy is disabled or the retry is modeled as a *...",
    "decision_boundary": "The boundary is this: **the agent may use `gen_ai.usage.*` for per-span diagnostics (latency, per-attempt cost attribution) but must not use trace-level sums of `gen_ai.usage.*` as a proxy for context-window occupancy or logical-step cost.** The moment a retry, fan-out, or context trim is possible, the trace-level sum is an *upper bound on transmissions*, no...",
    "operational_effect": "The operational consequence is a split accounting model. The trace pipeline becomes a *cost and latency observability* channel: it tells you how many tokens were transmitted, how many retries fired, and where the flakiness is. The agent's internal counter becomes the *control* channel: it alone gates compaction, budget enforcement, and termination. The two a..."
  },
  "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": "8fc2dad2bad2e583b5cc7cda2ff2fa3d708192b969080e02629ce987789040fa",
    "verified_classes": [
      "GenAIAccountingDivergence",
      "LogicalStepAccountant"
    ],
    "verified_functions": [
      "gate_compaction",
      "__init__",
      "record_attempt",
      "reconcile"
    ],
    "verified_functions_count": 4,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "GenAIAccountingDivergence"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
