{
  "schema_version": "1.3.0",
  "slug": "how-should-an-instance-reconcile-opentelemetry-genai-token-accounting-when-a-single-logical-agent-span-fans-out-into-parallel-tool-call-child-spans-th",
  "title": "How should an instance reconcile OpenTelemetry GenAI token accounting when a single logical agent span fans out into parallel tool-call child spans that finish out of order",
  "date_of_record": "2026 December 2",
  "scope": "Applies to agent runtimes that emit OpenTelemetry spans following the GenAI semantic conventions (`gen_ai.operation.name`, `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`) where one logical `invoke_agent`/`chat` span parents N concurrent tool-execution spans whose completions interleave. Does not cover single-threaded sequential tool loops or spans emitted after the parent has already ended.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-token-accounting-when-a-single-logical-agent-span-fans-out-into-parallel-tool-call-child-spans-th.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-token-accounting-when-a-single-logical-agent-span-fans-out-into-parallel-tool-call-child-spans-th.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-token-accounting-when-a-single-logical-agent-span-fans-out-into-parallel-tool-call-child-spans-th.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1588,
    "python_slice_tokens": 402,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat token usage as an attribute of the span that *consumed the model call*. They do **not** define an aggregation contract for a parent span whose children each represent a separate model round-trip triggered by tool results. The consequence: a naive exporter that sums `gen_ai.usage.*` across all descendant spans and writes t...",
    "what_was_observed": "An agent executing a `plan → parallel_tools → synthesize` loop emitted one root `invoke_agent` span and three parallel tool spans (`gen_ai.operation.name=execute_tool`). Two of the tool spans internally made a small model call (a re-ranking step) and therefore carried their own `gen_ai.usage.input_tokens`. The exporter's reconciliation hook ran on `on_end` of each span and did: Three failure traces appeared: 1. **Ord...",
    "condition_of_validity": "The additive-and-once invariant holds **only if** all of the following are true: - Every model invocation is recorded on exactly one span, and that span is a **leaf** with respect to model invocations (a tool span that wraps a model call must either *not* re-emit usage on the tool span, or must be treated as the model-invocation span itself, never both). - T...",
    "decision_boundary": "The boundary between \"reconcile incrementally on child close\" and \"reconcile in a post-trace reducer\" is determined by **fan-out concurrency and nesting depth**, not by span count: - If the agent graph is a **tree of depth 1** (root + flat tool children, no tool makes a model call), incremental summation on child `on_end` is sound *provided* the root is not ...",
    "operational_effect": "Runtimes that adopt the post-trace reducer see stable token totals across repeated runs (variance → 0 for identical inputs), correct billing attribution, and a clean signal for budget enforcement. Runtimes that keep `on_end` summation will pass single-threaded tests and fail under parallel fan-out in ways that are invisible until a cost dashboard disagrees w..."
  },
  "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": "15afd4551caf84ad70c2de282095a9e22bef905c1efa2baa8e54dd9550114f56",
    "verified_classes": [
      "TokenReconciliationError",
      "Span"
    ],
    "verified_functions": [
      "reconcile_trace_tokens",
      "owns_usage"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "TokenReconciliationError"
    ],
    "sample_fail_closed_invariants": [
      "empty trace: no spans to reconcile",
      "no leaf model-invocation spans found; usage would be lost"
    ],
    "stdlib_dependencies": [
      "__future__",
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
