{
  "schema_version": "1.3.0",
  "slug": "under-what-conditions-must-an-instance-treat-opentelemetry-genai-span-token-counts-as-non-additive-across-agent-handoffs-and-how-does-the-gen-ai-usage",
  "title": "Under what conditions must an instance treat OpenTelemetry GenAI span token counts as non-additive across agent handoffs, and how does the `gen_ai.usage.*` accounting invariant break when tool-call spans re-parent mid-trace?",
  "date_of_record": "2026 November 28",
  "scope": "Applies to any agent runtime emitting OpenTelemetry GenAI semantic-convention spans (`gen_ai.operation.name`, `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, `gen_ai.tool.name`, `gen_ai.tool.call.id`) where a parent agent span spawns tool-call child spans that may be re-parented or retried by an orchestrator. Does not apply to single-shot inference spans with no tool-call children or to runtimes that emit only aggregate metrics counters without per-span attributes.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-treat-opentelemetry-genai-span-token-counts-as-non-additive-across-agent-handoffs-and-how-does-the-gen-ai-usage.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-treat-opentelemetry-genai-span-token-counts-as-non-additive-across-agent-handoffs-and-how-does-the-gen-ai-usage.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-treat-opentelemetry-genai-span-token-counts-as-non-additive-across-agent-handoffs-and-how-does-the-gen-ai-usage.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1405,
    "python_slice_tokens": 284,
    "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 *per-inference-call* attributes: they describe the tokens consumed by the model invocation that produced the span. They are **not** a rollup contract. The convention is silent on whether a parent agent span's usage attributes should equal the sum of its chil...",
    "what_was_observed": "A three-hop agent run: `planner` (agent span) → `search` tool call → `summarizer` (agent span) → `emit` tool call. The orchestrator's retry policy re-parented the `search` tool span under `summarizer` after `planner` returned a soft timeout, and the span exporter copied the full attribute map from the original `planner` span onto the re-parented `search` span to preserve \"context.\" Trace as exported (abridged): Summi...",
    "condition_of_validity": "The additivity invariant—`root.usage == Σ(leaf.usage)`—holds **only** when all three conditions are simultaneously true: 1. Every span carrying `gen_ai.usage.*` has `gen_ai.operation.name ∈ {invoke_agent, chat, text_completion}` (i.e., is a genuine model invocation, not `execute_tool`). 2. No span's `parent_span_id` was rewritten after the span was first clo...",
    "decision_boundary": "An instance must **stop treating per-span usage as summable** and switch to a deduplicating projection when it detects any of: - A span with `gen_ai.operation.name = \"execute_tool\"` that also carries `gen_ai.usage.input_tokens > 0` → the attribute is inherited; exclude from token rollup and flag for attribute-provenance audit. - Two spans in the same trace s...",
    "operational_effect": "The practical consequence is that cost dashboards and budget-enforcement loops built on `Σ gen_ai.usage.*` will over-count after any retry or handoff that re-parents a span, and the error compounds with retry depth. A token-budget guard that halts an agent at a summed threshold will trip early—killing runs that are under budget—precisely on the runs that ret..."
  },
  "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": "aa66692a7f519e9d3e865120bd1a46707c01000c3e8511bc14efb6f3dfcbb0aa",
    "verified_classes": [
      "TokenAccountingInvariantError",
      "GenAISpan"
    ],
    "verified_functions": [
      "safe_token_rollup",
      "assert_root_anchored"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "TokenAccountingInvariantError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
