{
  "schema_version": "1.3.0",
  "slug": "under-what-conditions-must-an-instance-refuse-to-close-an-opentelemetry-genai-agent-span-when-child-tool-call-spans-report-token-usage-that-exceeds-th",
  "title": "Under what conditions must an instance refuse to close an OpenTelemetry GenAI agent span when child tool-call spans report token usage that exceeds the parent's recorded `gen_ai.usage.*` totals",
  "date_of_record": "2026 November 24",
  "scope": "Applies to any agent runtime that emits OTel GenAI semantic-convention spans (`gen_ai.operation.name`, `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, `gen_ai.request.model`, `gen_ai.tool.name`) for a parent agent-invocation span with one or more child tool-call spans, where token accounting is aggregated at close time. Does not apply to single-span, single-call instrumentation with no nested tool spans, nor to runtimes that delegate accounting entirely to a downstream billing pipeline that tolerates negative residuals.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-refuse-to-close-an-opentelemetry-genai-agent-span-when-child-tool-call-spans-report-token-usage-that-exceeds-th.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-refuse-to-close-an-opentelemetry-genai-agent-span-when-child-tool-call-spans-report-token-usage-that-exceeds-th.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-refuse-to-close-an-opentelemetry-genai-agent-span-when-child-tool-call-spans-report-token-usage-that-exceeds-th.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1842,
    "python_slice_tokens": 264,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` as *attributes of the span that performed the model call*. They do **not** define a parent-child aggregation rule. The conventions are, by design, per-span. What most agent runtimes actually implement, however, is a *rollup*: the parent agent span carries a tot...",
    "what_was_observed": "An agent invocation span `invoke_agent` was opened with `gen_ai.operation.name=invoke_agent`, `gen_ai.request.model=gpt-4o`. During execution it issued three tool calls: - `get_weather` — succeeded, `gen_ai.usage.input_tokens=812`, `gen_ai.usage.output_tokens=44`. - `search_docs` — first attempt timed out at the HTTP layer *after* the model had already generated a 1,200-token tool-call argument blob; the runtime retr...",
    "condition_of_validity": "The rollup invariant `parent_total ≥ Σ child_usage` holds **only** when all of the following are true simultaneously: 1. Every child span corresponds to exactly one logical model call — no retries emit duplicate usage, or retries are explicitly tagged (`gen_ai.request.retry_count` or a custom `tool.attempt`) and deduplicated before summation. 2. A child span...",
    "decision_boundary": "At parent-span close, compute `residual = parent_total - Σ child_usage` separately for input and output. - If `residual ≥ 0` for both: emit the residual as `agent.reasoning_overhead` (or omit it), close the span. This is the expected path. - If `residual < 0` for either: **do not close the span with the computed totals.** The parent's recorded `gen_ai.usage....",
    "operational_effect": "Clamping the residual to zero without the event hides a real accounting error: the retry double-count means a tenant is being charged twice for one logical tool call, and the failed-child flush means a tenant is charged for a call that produced no usable output. Surfacing `UsageRollupDiscrepancy` with the residual magnitude lets the billing reconciliation jo..."
  },
  "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": "e851575f601cac6258319c36c596d6ab71d2f7d7c1fcc274dd4bccf75fefb7d5",
    "verified_classes": [
      "UsageRollupDiscrepancy",
      "SpanUsage",
      "ParentSpan"
    ],
    "verified_functions": [
      "close_agent_span",
      "__init__"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 1,
    "raised_exceptions": [
      "UsageRollupDiscrepancy"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
