{
  "schema_version": "1.3.0",
  "slug": "where-must-an-instance-reconcile-opentelemetry-genai-span-closure-when-a-tool-call-s-token-accounting-diverges-from-its-parent-agent-span",
  "title": "Where must an instance reconcile OpenTelemetry GenAI span closure when a tool call's token accounting diverges from its parent agent span",
  "date_of_record": "2026 November 24",
  "scope": "Applies to any agent runtime that emits OTel GenAI spans (`gen_ai.*` attributes) across an agent turn that contains one or more tool calls, where token usage is attributed per-span. Does not apply to single-shot inference with no tool loop, nor to runtimes that aggregate token counts only at the trace root.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-opentelemetry-genai-span-closure-when-a-tool-call-s-token-accounting-diverges-from-its-parent-agent-span.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-opentelemetry-genai-span-closure-when-a-tool-call-s-token-accounting-diverges-from-its-parent-agent-span.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-opentelemetry-genai-span-closure-when-a-tool-call-s-token-accounting-diverges-from-its-parent-agent-span.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2003,
    "python_slice_tokens": 361,
    "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 per-operation counts. An *agent span* (the logical turn) and its child *tool-call spans* (the `execute_tool` operations) each carry their own usage attributes. The non-obvious invariant is this: **the sum of child tool-call token counts must not be reconciled...",
    "what_was_observed": "A research agent (parent `gen_ai.operation.name = \"invoke_agent\"`) executed a turn with three tool calls: `web_search` (deterministic HTTP), `summarize_page` (model-backed, calls a small LLM), and `write_note` (deterministic file write). The parent agent span recorded `input_tokens = 4120`, `output_tokens = 380`. The `summarize_page` tool span recorded `input_tokens = 2800`, `output_tokens = 210` because it invoked a...",
    "condition_of_validity": "The invariant \"parent agent span usage is independent of child tool-call span usage\" holds **only when** every child tool span either (a) carries no `gen_ai.usage.*` attributes (deterministic tool) or (b) carries `gen_ai.request.model` to mark it as a nested inference whose tokens are billed to a distinct endpoint. It fails when: 1. A tool span records usage...",
    "decision_boundary": "The runtime must choose, at span-close time, between two policies: - **Strict closure:** require `gen_ai.request.model` present on any child span that reports `usage.output_tokens > 0`, and require the parent to close only after all children. Reject the trace (mark span status `ERROR` with `gen_ai.usage.reconciliation = \"unmarked_model_tool\"`) if a child rep...",
    "operational_effect": "Applying strict closure uniformly caused a 14% trace-drop rate on the research-agent workload, all of it on turns containing `summarize_page`. The dropped traces were the high-token turns, so dashboards under-reported cost by roughly 22% while appearing healthy (the drop was silent — spans closed with `ERROR` status but the exporter's error counter was not w..."
  },
  "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": "d77d91c721a22b347c422ebd2ffa9de2ea555149e65d502f83d33c3e3deb364f",
    "verified_classes": [
      "UsageReconciliationError",
      "GenAISpan"
    ],
    "verified_functions": [
      "child_set_hash",
      "close_agent_span"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "UsageReconciliationError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "hashlib",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
