{
  "schema_version": "1.3.0",
  "slug": "what-happens-when-an-instance-emits-opentelemetry-genai-spans-for-an-agent-turn-but-the-tool-call-events-are-recorded-on-a-child-span-that-outlives-th",
  "title": "What happens when an instance emits OpenTelemetry GenAI spans for an agent turn but the tool-call events are recorded on a child span that outlives the parent's token-accounting boundary",
  "date_of_record": "2026 November 25",
  "scope": "Applies to agents instrumented with OpenTelemetry GenAI semantic conventions (`gen_ai.*`) where a single logical agent turn is modeled as a parent span with token-usage attributes and tool invocations are modeled as child spans/events. Does not apply to flat single-span-per-LLM-call instrumentation or to systems where tool execution is fully synchronous and in-process within the parent span's lifetime.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-emits-opentelemetry-genai-spans-for-an-agent-turn-but-the-tool-call-events-are-recorded-on-a-child-span-that-outlives-th.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-emits-opentelemetry-genai-spans-for-an-agent-turn-but-the-tool-call-events-are-recorded-on-a-child-span-that-outlives-th.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-emits-opentelemetry-genai-spans-for-an-agent-turn-but-the-tool-call-events-are-recorded-on-a-child-span-that-outlives-th.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2052,
    "python_slice_tokens": 333,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions attach cost and token attribution to the *span that called the model*: `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, and (in newer drafts) `gen_ai.usage.cost.*` live on the inference span. Tool-call telemetry — `gen_ai.tool.name`, `gen_ai.tool.call.id`, request/response payloads — is conventionally emitted as a chi...",
    "what_was_observed": "A multi-step agent (planner → tool-executor → critic) instrumented with a parent `invoke_agent` span and child `execute_tool` spans. On a run where the planner issued a `search` tool call and the tool-executor, upon receiving a low-quality result, internally issued a *second* model call to reformulate the query, the following trace shape was produced: - Parent span `invoke_agent` closed at T+1.2s with `gen_ai.usage.i...",
    "condition_of_validity": "The accounting closure invariant holds if and only if all three of the following are true at parent-span close: 1. **Drain condition:** every descendant span carrying any `gen_ai.usage.*` attribute has already ended (its end timestamp ≤ parent end timestamp), or the parent's usage attributes are computed by an aggregator that reads the completed subtree rath...",
    "decision_boundary": "The operational decision is where to place the parent span's end edge. Three placements are possible, and each has a distinct failure signature: - **Close on model-return (control-flow edge).** Cheapest, matches most framework auto-instrumentation. Fails the drain condition whenever any tool descendant emits usage. Symptom: under-attribution proportional to ...",
    "operational_effect": "The practical consequence is a *silent, workload-dependent cost-attribution error* that is correlated with agent behavior rather than with infrastructure health. Traces look healthy; span counts are normal; latency percentiles are fine. The only signal is a slow divergence between `sum(gen_ai.usage.*)` over the trace and the ground-truth token meter of the m..."
  },
  "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": "3c7c3c1bac239243a8412e464270e3384cd1fdbd1d4da1be8c59bcb61eead3e4",
    "verified_classes": [
      "AccountingClosureViolation",
      "SpanRecord"
    ],
    "verified_functions": [
      "assert_accounting_closure"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "AccountingClosureViolation"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
