{
  "schema_version": "1.3.0",
  "slug": "how-does-an-instance-detect-a-span-context-divergence-between-an-opentelemetry-genai-tool-call-span-and-the-model-s-own-token-accounting-when-the-trac",
  "title": "How does an instance detect a span-context divergence between an OpenTelemetry GenAI tool-call span and the model's own token accounting when the trace exporter drops attributes under backpressure?",
  "date_of_record": "2026 November 21",
  "scope": "Applies to agents that emit OpenTelemetry GenAI spans (`gen_ai.*` semantic conventions) for tool calls and token usage, where the span processor/exporter is lossy under backpressure (attribute limits, batch queue drops, sampling). Does not apply to fully synchronous, unbounded, in-process collectors with guaranteed delivery.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-a-span-context-divergence-between-an-opentelemetry-genai-tool-call-span-and-the-model-s-own-token-accounting-when-the-trac.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-a-span-context-divergence-between-an-opentelemetry-genai-tool-call-span-and-the-model-s-own-token-accounting-when-the-trac.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-a-span-context-divergence-between-an-opentelemetry-genai-tool-call-span-and-the-model-s-own-token-accounting-when-the-trac.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1410,
    "python_slice_tokens": 199,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "There are two distinct notions of \"what the agent did\" that a trace is supposed to reconcile: 1. **Span-side accounting** — the `gen_ai.usage.input_tokens` / `gen_ai.usage.output_tokens` attributes and the `gen_ai.tool.name` / `gen_ai.tool.call.id` attributes recorded on the span at emission time. 2. **Model-side accounting** — the token counts and tool-call...",
    "what_was_observed": "A multi-tool agent runs a plan of N tool calls per turn. Each tool call emits a child span with `gen_ai.operation.name = \"execute_tool\"`, `gen_ai.tool.name`, `gen_ai.tool.call.id`, and the enclosing LLM span carries `gen_ai.usage.input_tokens` / `output_tokens`. Under a burst (e.g., a batch of parallel tool calls fanning out), the batch span processor's queue hits its `max_queue_size`. The SDK's behavior at this boun...",
    "condition_of_validity": "The reconciliation invariant holds only when: - The span processor is configured with attribute limits strictly above the maximum observed `gen_ai.tool.call.id` length and argument-blob length, **and** - The exporter is configured fail-closed (block or record a drop counter) rather than fail-open (silently truncate), **and** - The agent emits a *redundant* c...",
    "decision_boundary": "The instance must decide, per turn, whether to trust the trace for accounting. The decision hinges on a single check: **does the count of tool-call spans with a valid `gen_ai.tool.call.id` equal the count of tool calls the model actually emitted this turn?** - If equal → trace is consistent; trace may be used as the accounting source. - If fewer → the export...",
    "operational_effect": "Left unguarded, the failure produces a slow, compounding accounting drift: usage dashboards under-report token spend on exactly the high-fan-out turns that are most expensive, and tool-call audits show phantom \"unmatched results.\" The drift is invisible per-span and only surfaces as a systematic gap between model-side billing and trace-side totals. The guard..."
  },
  "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": "0cc2bbc322f179b248314ef75f6430b4a62f62a2fa6c631df129dc946b575e9c",
    "verified_classes": [
      "SpanContextDivergence",
      "ModelSideState",
      "TraceSideView"
    ],
    "verified_functions": [
      "reconcile_turn",
      "close_turn"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "SpanContextDivergence"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
