{
  "schema_version": "1.3.0",
  "slug": "under-what-conditions-must-an-instance-reconcile-opentelemetry-genai-token-accounting-spans-against-tool-call-child-spans-before-emitting-a-completed",
  "title": "Under what conditions must an instance reconcile OpenTelemetry GenAI token-accounting spans against tool-call child spans before emitting a completed agent trace",
  "date_of_record": "2026 November 26",
  "scope": "Applies to agent runtimes that emit OpenTelemetry spans under the GenAI semantic conventions (`gen_ai.*`) where an agent span parents tool-call child spans and both contribute to token/cost accounting. Does not apply to single-shot inference calls with no tool fan-out, nor to runtimes that emit usage only at the root span.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-reconcile-opentelemetry-genai-token-accounting-spans-against-tool-call-child-spans-before-emitting-a-completed.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-reconcile-opentelemetry-genai-token-accounting-spans-against-tool-call-child-spans-before-emitting-a-completed.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-reconcile-opentelemetry-genai-token-accounting-spans-against-tool-call-child-spans-before-emitting-a-completed.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2357,
    "python_slice_tokens": 419,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat usage accounting (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`) and tool invocation (`gen_ai.tool.name`, `gen_ai.tool.call.id`) as attributes on spans, but they do not mandate *where* in the span tree usage is recorded, nor do they enforce that the sum of child-span usage equals the parent agent span's usage....",
    "what_was_observed": "A ReAct-style agent loop emitting spans as follows: one `invoke_agent` root span per task, one `execute_tool` child span per tool call, and one `chat` (LLM) child span per model invocation. In a 4-turn task that made 3 tool calls, the trace contained 4 `chat` spans and 3 `execute_tool` spans under a single agent span. The runtime set `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` on the **agent span** a...",
    "condition_of_validity": "The reconciliation invariant holds only when, for every logical turn *t* that produced a tool call: 1. The `chat` span and the `execute_tool` span for *t* share a stable turn identity — not just `gen_ai.tool.call.id` on the tool span, but a turn-scoped key (e.g., a `gen_ai.conversation.id` + turn index, or a shared `trace`/`span` lineage where the tool span'...",
    "decision_boundary": "The emitter must choose between two topologies and cannot mix them: - **Nested topology:** `execute_tool` spans are children of the `chat` span that requested them. Then turn identity is structural, retry dedup is per-`chat`-subtree, and the agent aggregate is a sum over `chat` subtrees. Reconciliation is a subtree sum, and a retried turn is one subtree. Thi...",
    "operational_effect": "When the invariant is violated, three concrete effects follow, in order of detection latency: 1. **Silent cost inflation with a passing sum check.** Because the parent aggregate and the leaf sum are computed from the same un-deduplicated set, they agree with each other and disagree with reality. No internal consistency check fires. Detection requires an exte..."
  },
  "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": "0918454e4e9839ff5c7cc88c6243cc40916a626d1c44f7decc02988623753fc7",
    "verified_classes": [
      "TokenReconciliationError",
      "Span"
    ],
    "verified_functions": [
      "reconcile_agent_span",
      "finalize_agent_span"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 5,
    "raised_exceptions": [
      "TokenReconciliationError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
