{
  "schema_version": "1.3.0",
  "slug": "what-structural-signals-indicate-token-accounting-divergence-when-opentelemetry-genai-spans-conflate-retry-attempts-with-logical-tool-calls",
  "title": "What structural signals indicate token-accounting divergence when OpenTelemetry GenAI spans conflate retry attempts with logical tool calls",
  "date_of_record": "2026 November 24",
  "scope": "Applies to agent runtimes that emit OpenTelemetry spans conforming to the GenAI semantic conventions (`gen_ai.*` attributes) where a single logical tool invocation may be retried, streamed, or split across child spans. Does not apply to single-shot, non-retried inference calls with a one-to-one span-to-request mapping.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-token-accounting-divergence-when-opentelemetry-genai-spans-conflate-retry-attempts-with-logical-tool-calls.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-token-accounting-divergence-when-opentelemetry-genai-spans-conflate-retry-attempts-with-logical-tool-calls.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-token-accounting-divergence-when-opentelemetry-genai-spans-conflate-retry-attempts-with-logical-tool-calls.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1857,
    "python_slice_tokens": 445,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure mode is not \"wrong token counts.\" It is the collapse of the distinction between a **logical operation** (one intent to call a tool or one model turn) and a **transport attempt** (one HTTP round-trip, one streamed response, one retry). The GenAI semantic conventions describe attributes (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, `g...",
    "what_was_observed": "A tool-calling agent issued an `execute_tool` intent for a retrieval function. The transport layer attempted the call three times: attempt 1 timed out at 30s after the model had already produced the tool arguments (input tokens billed), attempt 2 returned a 503 mid-stream (input tokens billed again, partial output tokens billed), attempt 3 succeeded. The emitted trace contained: - One parent span `agent.invoke` with ...",
    "condition_of_validity": "The invariant \"sum of child `gen_ai.usage.*_tokens` equals the logical operation's billable token count\" holds **only if** every span maps one-to-one to a distinct provider request whose input tokens are not re-counted. It fails under any of: - **Retry with full-context re-serialization.** Input tokens are counted per attempt, not per logical turn. - **Strea...",
    "decision_boundary": "The boundary is whether the telemetry consumer treats **span usage attributes as additive** or as **per-attempt facts requiring reconciliation against a logical-operation key**. If additive: the consumer must guarantee one-span-per-logical-operation. That requires the runtime to *suppress* usage attributes on failed attempts, or to emit a single aggregated s...",
    "operational_effect": "Without the discriminator, three downstream systems silently corrupt: - **Cost dashboards** over-report by the retry multiplier, which correlates with provider instability—so cost spikes masquerade as traffic spikes during incidents, misdirecting on-call. - **Budget enforcement** trips early, causing the agent to abort mid-task at a token budget that was nev..."
  },
  "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": "ef19ea0ea77eea6bcd9f9f34e251a55e3979525cd645fd767ca072db931d527e",
    "verified_classes": [
      "TelemetryAccountingDivergence",
      "GenAISpan"
    ],
    "verified_functions": [
      "reconcile_logical_operation"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 5,
    "raised_exceptions": [
      "TelemetryAccountingDivergence"
    ],
    "sample_fail_closed_invariants": [
      "empty span set: no logical operation to reconcile",
      "zero input tokens across all attempts: span set is malformed",
      "retry-as-sibling detected (identical tool_name, shared parent, multiple spans) but no gen_ai.attempt.index discriminator",
      "attempt discriminator present but terminality flag absent; cannot separate semantic output accounting from billing accou"
    ],
    "stdlib_dependencies": [
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
