{
  "schema_version": "1.3.0",
  "slug": "what-structural-signals-indicate-token-accounting-drift-in-opentelemetry-genai-agent-spans-when-tool-call-attributes-and-usage-semantics-diverge-mid-t",
  "title": "What structural signals indicate token-accounting drift in OpenTelemetry GenAI agent spans when tool-call attributes and usage semantics diverge mid-trace",
  "date_of_record": "2026 November 22",
  "scope": "Applies to agent runtimes emitting OpenTelemetry spans under the GenAI semantic conventions (`gen_ai.*`) where a single logical agent invocation is decomposed into nested spans (agent → LLM call → tool call) and token usage is aggregated across that tree. Does not cover single-shot completion logging, non-OTel telemetry pipelines, or cost attribution across billing tenants.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-token-accounting-drift-in-opentelemetry-genai-agent-spans-when-tool-call-attributes-and-usage-semantics-diverge-mid-t.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-token-accounting-drift-in-opentelemetry-genai-agent-spans-when-tool-call-attributes-and-usage-semantics-diverge-mid-t.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-token-accounting-drift-in-opentelemetry-genai-agent-spans-when-tool-call-attributes-and-usage-semantics-diverge-mid-t.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2219,
    "python_slice_tokens": 394,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` as **per-span measurements of a single model invocation**, and treat tool calls as **sibling spans** under the LLM span that requested them, carrying `gen_ai.tool.name` and `gen_ai.tool.call.id` rather than token attributes. The subtle invariant this rests on is...",
    "what_was_observed": "A tool-using agent (planner → executor → verifier loop) was instrumented with `gen_ai` spans. During normal operation the trace tree looked correct: one `invoke_agent` root, one `chat` span per LLM turn carrying `gen_ai.usage.*`, and `execute_tool` child spans carrying `gen_ai.tool.name` and `gen_ai.tool.call.id`. Aggregate input tokens matched the provider dashboard within 0.3%. Under load, three structural anomalie...",
    "condition_of_validity": "The leaf-summation invariant holds **only if** all of the following are enforced at emit time: - **Exactly one leaf `chat` span per real model invocation**, with retries recorded as span *events* (`gen_ai.retry` event with attempt number) on the same span, not as new sibling spans. If the SDK creates a new span per attempt, the invariant is void unless a ded...",
    "decision_boundary": "The operational decision is **when to trust a summed token count from a trace versus when to quarantine the trace and fall back to provider-side billing records**. The boundary is crossed when the structural preconditions above fail in a way that cannot be resolved by a deterministic rule applied to span attributes alone. Concretely: - **Trust the sum** if e...",
    "operational_effect": "Emitting a trace that violates the leaf-summation invariant does not just produce a wrong dashboard number — it **poisons downstream verification**. An auditor agent that recomputes cost-per-tool from spans will, in the retry case, attribute the retried turn's tokens to the tool that triggered it, inflating that tool's apparent cost and potentially causing t..."
  },
  "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": "7177b1b2f46cd96f353e1540baacca6b2890d993e70150e44bc42bced8613fac",
    "verified_classes": [
      "TokenAccountingDriftError",
      "GenAISpan"
    ],
    "verified_functions": [
      "validate_leaf_summation",
      "reconcile_or_quarantine",
      "has_usage",
      "tool_call_ids",
      "is_leaf"
    ],
    "verified_functions_count": 5,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "TokenAccountingDriftError"
    ],
    "sample_fail_closed_invariants": [
      "no leaf chat spans with usage found; trace cannot be reconciled"
    ],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
