{
  "schema_version": "1.3.0",
  "slug": "what-structural-signals-indicate-a-token-accounting-divergence-between-opentelemetry-genai-agent-spans-and-their-child-tool-call-spans",
  "title": "What structural signals indicate a token-accounting divergence between OpenTelemetry GenAI agent spans and their child tool-call spans",
  "date_of_record": "2026 November 17",
  "scope": "Applies to agentic workloads instrumented with OpenTelemetry GenAI semantic conventions (span kinds `chat`, `execute_tool`, and agent orchestration spans) where token usage is aggregated from child spans and compared against parent span attributes. Does not apply to single-turn LLM calls without tool invocation, nor to providers that emit usage only at stream finalization without per-span attribution.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-a-token-accounting-divergence-between-opentelemetry-genai-agent-spans-and-their-child-tool-call-spans.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-a-token-accounting-divergence-between-opentelemetry-genai-agent-spans-and-their-child-tool-call-spans.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-a-token-accounting-divergence-between-opentelemetry-genai-agent-spans-and-their-child-tool-call-spans.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1495,
    "python_slice_tokens": 340,
    "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 a model-invocation span. They do **not** define an aggregation contract across an agent tree. The non-obvious invariant is this: **a parent agent span's token attributes are not the sum of its children's token attributes when the agent performs...",
    "what_was_observed": "In a replayed agent trace (12 tool calls, one model per step), the exported shape was: - Parent span `invoke_agent`: `gen_ai.usage.input_tokens = 184,320`, `output_tokens = 4,110`. - 12 child spans `execute_tool`: each with `gen_ai.tool.name`, `gen_ai.tool.call.id`, and **no** usage attributes. - Zero intermediate `chat` spans — the instrumentation collapsed the per-step model calls into the parent. A cost pipeline t...",
    "condition_of_validity": "Aggregation of child token attributes to a parent is valid **only** when every model invocation is represented by exactly one span and that span is a descendant of the agent span, with no invocation represented at two levels of the tree. This requires: 1. One `chat` (or `gen_ai.operation.name = chat`) span per model call, including calls that precede and fol...",
    "decision_boundary": "The operational rule: **before summing token attributes across a trace, assert that the count of model-invocation spans equals the count of tool-call spans plus one (the terminal response).** If `chat_span_count < tool_call_count`, the trace has hoisted accounting and must be read from the agent span only, never from a child sum. If `chat_span_count == tool_...",
    "operational_effect": "The practical consequence is that cost attribution and per-agent budget enforcement cannot share one aggregation path. Budget enforcement must read the agent span (the billed total). Per-tool cost attribution must read `chat` spans and will fail closed when the instrumentation hoists. The correct posture is to detect the hoisted shape at ingest and route the..."
  },
  "matched_failure_symptoms": [
    "SUBPROCESS_PIPE_HANG_OR_FD_LEAK"
  ],
  "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": "07aa3d4fe1d0f26e4ed26b7e70dc3a6b074ac2ad873ec9c51a65fd1dbf32bd4a",
    "verified_classes": [
      "TokenAggregationInvariantError"
    ],
    "verified_functions": [
      "reconcile_token_usage"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "TokenAggregationInvariantError"
    ],
    "sample_fail_closed_invariants": [
      "no invoke_agent span: cannot establish billed total"
    ],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
