{
  "schema_version": "1.3.0",
  "slug": "what-happens-when-an-instance-emits-otel-genai-agent-spans-whose-tool-call-attributes-desynchronize-from-token-accounting-at-the-span-close-boundary",
  "title": "What happens when an instance emits OTel GenAI agent spans whose tool-call attributes desynchronize from token accounting at the span-close boundary",
  "date_of_record": "2026 November 28",
  "scope": "Applies to LLM agent runtimes instrumented with OpenTelemetry GenAI semantic conventions (`gen_ai.*`) where a single agent invocation emits a parent `invoke_agent` span enclosing child `execute_tool` spans and per-turn `chat` spans, and where token usage is reported on the chat spans and aggregated upward. Does not apply to stateless single-call inference with no tool loop, nor to systems that emit only metrics with no span tree.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-emits-otel-genai-agent-spans-whose-tool-call-attributes-desynchronize-from-token-accounting-at-the-span-close-boundary.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-emits-otel-genai-agent-spans-whose-tool-call-attributes-desynchronize-from-token-accounting-at-the-span-close-boundary.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-emits-otel-genai-agent-spans-whose-tool-call-attributes-desynchronize-from-token-accounting-at-the-span-close-boundary.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2384,
    "python_slice_tokens": 390,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure is not \"missing telemetry\" or \"wrong attribute names.\" It is a **desynchronization between two independently-clocked accounting channels** that are reconciled only at span close: the *tool-call lifecycle channel* (child `execute_tool` spans, which open at tool dispatch and close at tool return) and the *token-usage channel* (attributes `gen_ai.us...",
    "what_was_observed": "A representative trace from a 4-tool ReAct loop, where the agent runtime uses an async span processor and a tool executor with a 30s per-call timeout: - `invoke_agent` span opens at t=0, `gen_ai.operation.name=invoke_agent`, `gen_ai.agent.name=researcher`. - Turn 1 `chat` span opens t=0.02, closes t=1.9 with `gen_ai.usage.input_tokens=1840`, `output_tokens=96`, and a `gen_ai.response.finish_reasons=[\"tool_calls\"]`. -...",
    "condition_of_validity": "The desync manifests only when **all** of the following hold. Remove any one and the trace reconciles: - The parent agent span and at least one child tool span are closed by **different control paths** (supervisor budget vs. tool executor timeout). If a single coordinator closes both, ordering is preserved. - The span processor is **asynchronous with a bound...",
    "decision_boundary": "The architectural choice is where to place the **reconciliation point** — the single place where tool-lifecycle and token-accounting are forced to agree before export. Three viable boundaries, each with a cost: - **Close-order enforcement (span-level).** The supervisor, on budget expiry, must not end the parent until all descendant spans are ended or explici...",
    "operational_effect": "The practical consequence is a **systematic, cancellation-correlated undercount of tokens attributed to tool-using agents**, plus a population of orphan spans that poison parent-join queries. The undercount is not random: it is concentrated exactly on the runs that hit budget or timeout — i.e., the expensive, long-tail, failure-adjacent runs that cost the mo..."
  },
  "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": "f38fc1d2d5c6f6b930bcfed552e3bf02c4254cfa9830306aec03ac306187acaf",
    "verified_classes": [
      "SpanReconciliationError",
      "ChatTurn",
      "ToolCall",
      "AgentSpan"
    ],
    "verified_functions": [
      "close_agent_span",
      "total_usage",
      "finalize"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "SpanReconciliationError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
