{
  "schema_version": "1.3.0",
  "slug": "where-must-an-instance-reconcile-opentelemetry-genai-token-accounting-when-a-tool-call-span-reports-attributes-after-the-parent-agent-span-has-already",
  "title": "Where must an instance reconcile OpenTelemetry GenAI token accounting when a tool-call span reports attributes after the parent agent span has already been exported",
  "date_of_record": "2026 November 25",
  "scope": "Applies to agent runtimes that emit OTel GenAI spans (`gen_ai.*`) where tool-call spans are children of an agent invocation span and the exporter is a batch/async processor. Does not cover synchronous stdout exporters or single-span-per-request monoliths where the root span is the last thing to close.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-opentelemetry-genai-token-accounting-when-a-tool-call-span-reports-attributes-after-the-parent-agent-span-has-already.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-opentelemetry-genai-token-accounting-when-a-tool-call-span-reports-attributes-after-the-parent-agent-span-has-already.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-opentelemetry-genai-token-accounting-when-a-tool-call-span-reports-attributes-after-the-parent-agent-span-has-already.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1456,
    "python_slice_tokens": 245,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` as *attributes of the span that incurred the cost*. The agent invocation span is expected to carry the aggregate; each `gen_ai.operation.name = \"execute_tool\"` child carries its own. The failure is not that attributes are missing — it is that the **parent span c...",
    "what_was_observed": "A planner agent (`gen_ai.operation.name = \"invoke_agent\"`, `gen_ai.agent.name = \"planner\"`) dispatches three tool calls sequentially. Each tool call is a child span with `gen_ai.operation.name = \"execute_tool\"`, `gen_ai.tool.name`, and — critically — usage attributes set *after* the tool returns, because the runtime only learns token cost when it feeds the tool result back into the model for the next reasoning step. ...",
    "condition_of_validity": "The invariant holds only when **all descendant usage attributes are finalized before the parent span's `end()` is called**. This requires the runtime to enforce a *close-order barrier*: the parent span cannot be ended until every child span has reached a terminal state *and* its usage attributes are committed. The barrier is violated whenever: - Tool-result ...",
    "decision_boundary": "The boundary is: **does the parent span aggregate usage, or does the backend aggregate usage?** - If the parent aggregates (parent carries `gen_ai.usage.*` = sum of children), the runtime MUST enforce close-order: parent `end()` blocks on all children's `end()` and attribute finalization. This is the GenAI-convention-faithful path but requires the agent loop...",
    "operational_effect": "A 6.5% per-invocation token overcount is not a rounding error at fleet scale: it corrupts cost attribution, defeats budget-enforcement loops that read back their own telemetry, and — worse — the undercount variant (dropped orphan children) makes the agent appear cheaper than it is, so budget guards never trip. The failure is invisible in per-span validation ..."
  },
  "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": "5976aac837c82bc747a1a3ef2d49e29acae65afa3b862c2143b3f625abb9091d",
    "verified_classes": [
      "UsageReconciliationError",
      "Span"
    ],
    "verified_functions": [
      "close_agent_span"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "UsageReconciliationError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
