{
  "schema_version": "1.3.0",
  "slug": "how-should-an-instance-reconcile-opentelemetry-genai-span-token-accounting-when-a-streaming-tool-call-span-is-retried-after-partial-emission",
  "title": "How should an instance reconcile OpenTelemetry GenAI span token accounting when a streaming tool-call span is retried after partial emission",
  "date_of_record": "2026 November 26",
  "scope": "Applies to agent runtimes that emit OpenTelemetry GenAI semantic-convention spans (`gen_ai.*`) for LLM invocations and tool calls, where the LLM call streams tokens and the tool-call span can be retried mid-stream. Does not cover non-streaming batch inference, or telemetry emitted only at the process boundary (e.g., a single span per agent task).",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-span-token-accounting-when-a-streaming-tool-call-span-is-retried-after-partial-emission.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-span-token-accounting-when-a-streaming-tool-call-span-is-retried-after-partial-emission.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-span-token-accounting-when-a-streaming-tool-call-span-is-retried-after-partial-emission.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1935,
    "python_slice_tokens": 336,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The distinction that matters is between **span identity** and **attempt identity**. The OpenTelemetry GenAI conventions define attributes such as `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` on the span that represents a model invocation, and `gen_ai.tool.name` / `gen_ai.tool.call.id` on tool-call spans. The conventions implicitly assume a on...",
    "what_was_observed": "A tool-calling agent loop was instrumented to emit one `gen_ai.chat` span per model call and one `gen_ai.tool` span per tool invocation. The model call used streaming; the runtime created the `gen_ai.chat` span at call start, set `gen_ai.request.model` and `gen_ai.request.max_tokens` before dispatch, and wrote `gen_ai.usage.input_tokens` / `gen_ai.usage.output_tokens` from the provider's terminal usage frame in a `fi...",
    "condition_of_validity": "The invariant that must hold for the span tree to be interpretable is: > For every `gen_ai.chat` span S, `S.gen_ai.usage.input_tokens` equals the number of input tokens billed for the *single provider invocation* that S represents, and the set of spans with the same `gen_ai.conversation.id` (or equivalent logical-operation key) that share a retry group must ...",
    "decision_boundary": "The decision boundary is whether the token counters on a span are **descriptive of one invocation** or **aggregative over many**. The GenAI conventions do not distinguish these, so the runtime must choose and must make the choice legible. The rule that survived operational contact: - A span that carries `gen_ai.usage.input_tokens` / `gen_ai.usage.output_toke...",
    "operational_effect": "Enforcing the boundary changes three things. First, cost dashboards must sum leaf spans, not parent spans; the parent's `gen_ai.retry.aggregate.*` is for latency and retry-rate analysis, not billing. Second, context-budget alarms must read `gen_ai.usage.input_tokens` only from leaf spans, since only a leaf's value is a prompt size. Third, and most important,..."
  },
  "matched_failure_symptoms": [
    "OOM_KILL_OR_MEMORY_EXHAUSTION"
  ],
  "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": "1155992efcc26d3354689fabf1e67a8ddafb9af84519dd599857608f0d86cd01",
    "verified_classes": [
      "GenAiSpanAccountingError"
    ],
    "verified_functions": [
      "reconcile_retry_group"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 7,
    "raised_exceptions": [
      "GenAiSpanAccountingError"
    ],
    "sample_fail_closed_invariants": [
      "retry group has no leaf spans; cannot reconcile",
      "parent span carries gen_ai.usage.*; parent must use gen_ai.retry.aggregate.* to stay distinguishable from a leaf"
    ],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
