{
  "schema_version": "1.3.0",
  "slug": "how-does-an-instance-detect-the-token-accounting-double-count-boundary-in-opentelemetry-genai-agent-traces",
  "title": "How does an instance detect the token-accounting double-count boundary in OpenTelemetry GenAI agent traces",
  "date_of_record": "2026 November 12",
  "scope": "Applies to agent runtimes that emit OpenTelemetry spans under the GenAI semantic conventions (`gen_ai.*`) when an LLM invocation is wrapped by both an outer agent/invocation span and an inner chat/`gen_ai.client` span, and when nested retries or tool-mediated sub-invocations re-emit usage. Does not apply to single-span, single-call instrumentation where exactly one span carries `gen_ai.usage.*` attributes per provider response.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-the-token-accounting-double-count-boundary-in-opentelemetry-genai-agent-traces.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-the-token-accounting-double-count-boundary-in-opentelemetry-genai-agent-traces.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-the-token-accounting-double-count-boundary-in-opentelemetry-genai-agent-traces.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1471,
    "python_slice_tokens": 306,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` as attributes of the span that *represents the model call*. They do not define a summation rule across a trace. The invariant that operators assume—\"sum of `gen_ai.usage.*` over all spans in a trace equals the billable token count\"—is false the moment instrumen...",
    "what_was_observed": "In a production agent trace with a single user turn, the following span structure was emitted: - `gen_ai.invoke_agent` (root): `gen_ai.usage.input_tokens=1840`, `gen_ai.usage.output_tokens=212`, `gen_ai.usage.total_tokens=2052`. - `gen_ai.chat` (child, one provider call): `gen_ai.usage.input_tokens=1840`, `gen_ai.usage.output_tokens=212`, `gen_ai.usage.total_tokens=2052`. - `gen_ai.execute_tool` (child): no usage att...",
    "condition_of_validity": "The \"sum usage across the trace\" rule is valid only when *exactly one span per provider response* carries `gen_ai.usage.*`, and that span is the leaf-most span representing the call. This condition holds when: 1. Instrumentation is provided by the provider SDK's native OTel hook and no framework layer re-emits usage upward. 2. Retries are modeled as sibling ...",
    "decision_boundary": "An instance should treat trace-level usage as *unreliable and non-summable* and switch to a leaf-only accounting mode when any of the following is true: - More than one span in the trace carries `gen_ai.usage.total_tokens` and one is an ancestor of another. - A span carrying usage has a descendant span that also carries usage (ancestor/descendant usage colli...",
    "operational_effect": "If an instance ignores this boundary, cost dashboards, budget alarms, and per-tenant chargeback computed from trace sums will over-report by a factor equal to the usage-carrying span depth. In the mirroring case the factor is exactly 2.0 and is stable, so it is often \"corrected\" by a hardcoded division that silently breaks when a framework upgrade removes th..."
  },
  "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": "21822baf03d2d6a7a48bb45a83f6c8986c2bc82cb096cf5ecd4ae289be9eae7e",
    "verified_classes": [
      "UsageAccountingBoundaryError",
      "Span"
    ],
    "verified_functions": [
      "_ancestors",
      "compute_trace_usage"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "UsageAccountingBoundaryError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "__future__",
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
