{
  "schema_version": "1.3.0",
  "slug": "in-what-scenarios-must-an-instance-refuse-to-close-an-opentelemetry-agent-span-when-genai-token-attributes-are-non-additive-across-tool-call-retries",
  "title": "In what scenarios must an instance refuse to close an OpenTelemetry agent span when GenAI token attributes are non-additive across tool-call retries",
  "date_of_record": "2026 November 27",
  "scope": "Applies to any agent runtime that emits OpenTelemetry spans conforming to the GenAI semantic conventions (`gen_ai.*`) for an agent turn containing one or more tool calls, where the runtime performs internal retries, fan-out, or model re-invocation beneath a single logical agent span. Does not apply to single-shot, single-tool-call spans with no retry or fan-out semantics, nor to spans where token accounting is delegated entirely to a downstream billing pipeline that tolerates overcounting.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-refuse-to-close-an-opentelemetry-agent-span-when-genai-token-attributes-are-non-additive-across-tool-call-retries.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-refuse-to-close-an-opentelemetry-agent-span-when-genai-token-attributes-are-non-additive-across-tool-call-retries.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-refuse-to-close-an-opentelemetry-agent-span-when-genai-token-attributes-are-non-additive-across-tool-call-retries.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2084,
    "python_slice_tokens": 418,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define token attributes (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, and the newer `gen_ai.usage.*` sub-namespace) as *per-invocation* counters describing a single model call. They are not defined as aggregable across a span tree in a way that guarantees additive conservation. The distinction that matters operati...",
    "what_was_observed": "A three-tool agent turn (search → fetch → summarize) with one retry on the fetch tool. The runtime emitted: - `agent.turn` (parent, `gen_ai.operation.name=invoke_agent`) - `llm.call.1` (`gen_ai.operation.name=chat`, input=1840, output=210) - `tool.fetch.attempt1` (errored, `error.type=TimeoutError`, no token attrs) - `tool.fetch.attempt2` (succeeded) - `llm.call.2` (input=3120, output=180) — this input includes the f...",
    "condition_of_validity": "The naive parent-sum is valid **only** under all of the following: 1. Every child model span is a *fresh* invocation with no prompt-cache hit, **or** the runtime carries `gen_ai.usage.cache_read.input_tokens` and the aggregator subtracts it from the billed total. 2. No child was retried after a partial-stream abort, **or** aborted-stream spans are tagged wit...",
    "decision_boundary": "The boundary is: **does the runtime have a ground-truth per-turn token ledger independent of the span tree?** - If **yes**, the span tree's parent token attributes should be reconciled against the ledger before export; mismatches are a signal of a retry/fan-out accounting bug, and the span should be closed with an explicit `gen_ai.usage.reconciliation_status...",
    "operational_effect": "The effect of getting this wrong is not a crash. It is a *silent divergence between the observability plane and the billing plane* that compounds. Cost dashboards built from span sums drift upward relative to invoices by the retry rate and the cache-hit rate — typically 15–40% in agents with tool loops. SLOs built from child `status` overcount failures by th..."
  },
  "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": "b4884e4c9f9ad5e652022162c7cea20d6e7f6938af757a78b9d3cc771d46f683",
    "verified_classes": [
      "SpanAccountingError",
      "FinishReason",
      "ChildSpan",
      "AgentSpan"
    ],
    "verified_functions": [
      "emit_agent_turn",
      "_naive_input_sum",
      "_billed_input_estimate",
      "close"
    ],
    "verified_functions_count": 4,
    "defensive_guards_count": 1,
    "raised_exceptions": [
      "SpanAccountingError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "__future__",
      "dataclasses",
      "enum",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
