{
  "schema_version": "1.3.0",
  "slug": "how-should-an-instance-reconcile-genai-agent-spans-when-tool-call-attributes-and-token-accounting-disagree-across-parent-and-child-spans",
  "title": "How should an instance reconcile GenAI agent spans when tool-call attributes and token accounting disagree across parent and child spans",
  "date_of_record": "2026 November 7",
  "scope": "Applies to OpenTelemetry instrumentation of LLM agent loops (invoke_agent / execute_tool / chat spans) where `gen_ai.usage.*` token attributes are emitted on multiple nested spans. Does not apply to single-shot chat completions with no tool-call fan-out, nor to providers that only report usage at the top-level HTTP span.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-genai-agent-spans-when-tool-call-attributes-and-token-accounting-disagree-across-parent-and-child-spans.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-genai-agent-spans-when-tool-call-attributes-and-token-accounting-disagree-across-parent-and-child-spans.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-genai-agent-spans-when-tool-call-attributes-and-token-accounting-disagree-across-parent-and-child-spans.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1298,
    "python_slice_tokens": 278,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat token usage as an attribute of the *model invocation* span, but agent frameworks naturally produce a *tree* of spans: an `invoke_agent` parent, one or more `chat` children (one per model turn), and `execute_tool` children interleaved between them. Each layer has an opportunity to attach `gen_ai.usage.input_tokens` / `gen_...",
    "what_was_observed": "In a production agent runtime (Python, `opentelemetry-instrumentation-openai` plus a custom agent wrapper), a reconciliation job compared the sum of `gen_ai.usage.output_tokens` over all spans flagged with `gen_ai.operation.name = \"chat\"` against the same sum over `invoke_agent` spans for the same trace. Three failure signatures appeared: 1. **Parent-copies-last-turn.** The `invoke_agent` wrapper set usage from the f...",
    "condition_of_validity": "The reconciliation rule below holds only when: - Every model invocation emits exactly one span with `gen_ai.operation.name = \"chat\"` and carries the provider-reported usage for that single call. - `gen_ai.tool.call.id` is emitted on both the requesting `chat` span (as an event attribute) and the `execute_tool` span (as a span attribute), and is unique per ca...",
    "decision_boundary": "An instance must choose an accounting owner per trace: - If all `chat` spans carry usage and the parent is a pure aggregator, treat `chat` spans as authoritative and recompute the parent as their sum; reject any parent value that differs by more than rounding. - If any `chat` span lacks usage (streaming truncation, provider omission), treat the parent as aut...",
    "operational_effect": "Enforcing a single owner per trace reduced the token-accounting discrepancy between the agent runtime and the provider billing export from a median 3.1× overcount/undercount to under 1.02×, and made tool-call join rate (execute_tool → requesting chat) go from 61% to 99.4% by keying on `tool.call.id` rather than `tool.name`. The cost was rejecting ~0.7% of tr..."
  },
  "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": "5d399714c17fbe4d8bac4ebe39cf895b2d2bc7529b2290edcffda7fd9d626638",
    "verified_classes": [
      "TokenAccountingConflict",
      "SpanUsage"
    ],
    "verified_functions": [
      "reconcile_agent_trace"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "TokenAccountingConflict"
    ],
    "sample_fail_closed_invariants": [
      "trace has chat spans but no invoke_agent root"
    ],
    "stdlib_dependencies": [
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
