{
  "schema_version": "1.3.0",
  "slug": "when-must-an-instance-refuse-to-emit-an-opentelemetry-genai-span-the-token-accounting-reconciliation-invariant-across-parent-child-tool-call-spans",
  "title": "When must an instance refuse to emit an OpenTelemetry GenAI span: the token-accounting reconciliation invariant across parent/child tool-call spans",
  "date_of_record": "2026 November 26",
  "scope": "Applies to any agent runtime that emits OTel GenAI semantic-convention spans (`gen_ai.*` attributes, `gen_ai.client.token.usage` metrics) for a multi-step agent loop where tool calls are modeled as child spans of a model-invocation span. Does not apply to single-shot inference calls with no tool fan-out, nor to runtimes that export only aggregate metrics without per-span hierarchy.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/when-must-an-instance-refuse-to-emit-an-opentelemetry-genai-span-the-token-accounting-reconciliation-invariant-across-parent-child-tool-call-spans.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-refuse-to-emit-an-opentelemetry-genai-span-the-token-accounting-reconciliation-invariant-across-parent-child-tool-call-spans.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-refuse-to-emit-an-opentelemetry-genai-span-the-token-accounting-reconciliation-invariant-across-parent-child-tool-call-spans.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2151,
    "python_slice_tokens": 379,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat *model invocation* and *tool execution* as distinct span kinds with distinct attribute namespaces. A model-invocation span carries `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, `gen_ai.request.model`, and `gen_ai.response.finish_reasons`. A tool-execution span carries `gen_ai.tool.name`, `gen_ai.tool.call.id`...",
    "what_was_observed": "A three-step ReAct loop (invoke → tool → invoke → tool → invoke) was instrumented with an auto-instrumentation shim that wrapped the agent’s `run()` method. The shim opened one span per LLM call and one span per tool call, parenting tool spans to the enclosing invocation via `context.attach`. The token meter was a single `TokenAccumulator` object living on the agent instance, incremented by the HTTP client hook on ev...",
    "condition_of_validity": "The per-span-delta invariant is only well-defined when three conditions hold, and instrumentation authors routinely violate the third without noticing: 1. **The meter is scoped to the invocation, not the loop.** The accumulator must be constructed per model-invocation span and closed (frozen) at `span.end()`. A loop-scoped accumulator makes the invariant uns...",
    "decision_boundary": "The runtime must decide, at `span.end()`, between three states, and the decision is not a formatting choice — it changes what downstream consumers can compute: - **Emit delta + terminal finish reason:** the span is fully reconcilable. Cost rollups sum it; trace replay can reconstruct the loop. - **Emit delta + non-terminal finish reason (`length`, `content_f...",
    "operational_effect": "The operational consequence is that **cost dashboards built on `sum(gen_ai.usage.input_tokens)` are only trustworthy if the instrumentation enforces the per-invocation-delta invariant at emit time, and there is no way to detect the violation after the fact from the exported data alone.** The overcount is not a data-quality flag; it is a structurally valid tr..."
  },
  "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": "08f55afa85618bfd52e2b317069dd90a59a0e85d959b5e548d60b0ac8998254f",
    "verified_classes": [
      "UnreconciledUsageError",
      "TokenAccumulator",
      "InvocationSpan"
    ],
    "verified_functions": [
      "open_invocation",
      "close_invocation",
      "reconcile_trace",
      "add"
    ],
    "verified_functions_count": 4,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "UnreconciledUsageError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
