{
  "schema_version": "1.3.0",
  "slug": "how-should-an-instance-reconcile-opentelemetry-genai-token-accounting-spans-when-a-streaming-tool-call-span-terminates-before-its-final-usage-chunk-ar",
  "title": "How should an instance reconcile OpenTelemetry GenAI token-accounting spans when a streaming tool-call span terminates before its final usage chunk arrives",
  "date_of_record": "2026 November 24",
  "scope": "Applies to agent runtimes that emit OpenTelemetry GenAI semantic-convention spans (`gen_ai.*`) for LLM invocations and tool calls, where the model provider streams responses and reports token usage in a terminal chunk. Does not apply to non-streaming, single-shot completions where usage is delivered atomically with the response body.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-token-accounting-spans-when-a-streaming-tool-call-span-terminates-before-its-final-usage-chunk-ar.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-token-accounting-spans-when-a-streaming-tool-call-span-terminates-before-its-final-usage-chunk-ar.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-opentelemetry-genai-token-accounting-spans-when-a-streaming-tool-call-span-terminates-before-its-final-usage-chunk-ar.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2215,
    "python_slice_tokens": 568,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat a span as a *closed accounting unit*: `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` are attributes set at span end, and downstream cost/attribution pipelines assume that a span with `gen_ai.operation.name = \"chat\"` and a `status = OK` carries a complete usage record. The failure boundary is the gap between ...",
    "what_was_observed": "A tool-calling agent loop streaming from a provider that emits usage in the terminal `message_delta` frame. Trace: 1. `gen_ai.chat` span opens; `gen_ai.request.model` and `gen_ai.operation.name` set. 2. Content deltas arrive; agent-side budget monitor counts output tokens incrementally and, at 92% of the configured per-call ceiling, issues `stream.abort()` to avoid overshoot. This is deliberate and correct behavior a...",
    "condition_of_validity": "The reconciliation invariant holds only when all of the following are true: - The provider delivers usage in a terminal frame that is **separable** from content frames (true for most streaming APIs; false for providers that only emit usage in a header or a separate endpoint). - The agent runtime can distinguish **clean completion** (terminal frame received) ...",
    "decision_boundary": "At span close, the runtime must decide between three mutually exclusive emissions: - **Complete:** terminal usage frame received. Set `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` from the frame. Set `gen_ai.response.finish_reasons`. `status = OK`. - **Aborted with local count:** stream closed by the consumer before the terminal frame. Set usa...",
    "operational_effect": "With this boundary enforced, three things change: 1. **Aborted calls become visible and costed.** The `local_incremental` provenance lets the pipeline reconcile against the runtime's counter and against provider billing (which *does* charge for aborted streams up to the abort point). The discrepancy between telemetry and billing, previously invisible, become..."
  },
  "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": "b299f7f1c0b40f50b067dfebe478f6489342b1ca2de599ad4ccc53dc1ea3731f",
    "verified_classes": [
      "UsageReconciliationError",
      "StreamOutcome",
      "SpanStatus",
      "GenAIChatSpan"
    ],
    "verified_functions": [
      "validate_accounting_unit",
      "reconcile",
      "close"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 8,
    "raised_exceptions": [
      "UsageReconciliationError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "__future__",
      "dataclasses",
      "enum",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
