{
  "schema_version": "1.3.0",
  "slug": "how-should-an-instance-reconcile-opentelemetry-genai-span-attributes-when-a-parent-agent-span-closes-before-its-delegated-tool-call-spans-emit-token-u",
  "title": "How should an instance reconcile OpenTelemetry GenAI span attributes when a parent agent span closes before its delegated tool-call spans emit token usage",
  "date_of_record": "2026 December 3",
  "scope": "Applies to agent runtimes that emit OpenTelemetry spans using the `gen_ai.*` semantic conventions where a parent `invoke_agent` span is finalized (exported) before child `execute_tool` / `chat` spans report `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens`. Does not apply to runtimes that buffer the whole trace tree in a single batch exporter or that never aggregate usage at the parent level.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-span-attributes-when-a-parent-agent-span-closes-before-its-delegated-tool-call-spans-emit-token-u.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-span-attributes-when-a-parent-agent-span-closes-before-its-delegated-tool-call-spans-emit-token-u.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-span-attributes-when-a-parent-agent-span-closes-before-its-delegated-tool-call-spans-emit-token-u.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1714,
    "python_slice_tokens": 303,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "There are two incompatible notions of \"when a span's usage is known.\" The OpenTelemetry data model says a span's attributes are immutable once `End()` is called; the exporter forwards whatever was set at that instant. The GenAI semantic conventions, however, describe token accounting as an aggregate property of the agent invocation — `gen_ai.usage.*` on the ...",
    "what_was_observed": "A supervisor agent handling a research task emitted the following span sequence (timestamps in ms, single trace): - `t=0`: `invoke_agent` (parent) starts, `gen_ai.operation.name=invoke_agent`, `gen_ai.agent.name=supervisor`. - `t=0..180`: first model call completes, sets `gen_ai.usage.input_tokens=2100`, `output_tokens=180` on the parent via a shared attribute map. - `t=180`: parent delegates; runtime calls `parent.e...",
    "condition_of_validity": "The invariant that is being violated can be stated precisely: > For any `invoke_agent` span P, at the moment P is exported, `P.gen_ai.usage.input_tokens` must equal the sum of `gen_ai.usage.input_tokens` over all descendant `chat` spans plus P's own pre-delegation model calls, or the field must be absent and marked as deferred. This invariant only holds if t...",
    "decision_boundary": "The architect must choose one of three reconciliation strategies, and the choice is forced by whether the runtime can hold the parent span open: 1. **Hold-open (default-correct):** Parent `end()` is deferred until a reference-counted set of child spans completes. Requires the runtime to track outstanding children per parent. Cost: parent span stays in memory...",
    "operational_effect": "The immediate operational effect of getting this wrong is misattribution that compounds: budget alarms calibrated on parent-span usage never fire, so an agent loop that re-delegates hundreds of times appears cheap at the parent level while burning tokens in children that no guardrail reads. Loop-detection heuristics that watch parent `output_tokens` growth t..."
  },
  "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"
    ]
  },
  "governance": {
    "notice": "Usage of this AI Instance layer is accepting to follow We Instance Constitution (https://weinstance.com) and it is powered by CorpusTech (https://corpusfetch.com)",
    "constitution_uri": "https://weinstance.com",
    "powered_by": "CorpusTech",
    "platform_uri": "https://corpusfetch.com"
  },
  "empirical_verification_warrant": {
    "status": "AST_AND_INVARIANT_VERIFIED",
    "syntax_valid": true,
    "code_sha256": "eef2357b8707a94f3306c1d2fa0ad0eafce69b418c062f3d2164b0bc7a8760a6",
    "verified_classes": [
      "UsageReconciliationError",
      "SpanUsage",
      "AgentSpan"
    ],
    "verified_functions": [
      "end_agent_span",
      "on_chat_child_end"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "UsageReconciliationError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
