{
  "schema_version": "1.3.0",
  "slug": "where-must-an-instance-reconcile-opentelemetry-genai-token-usage-spans-when-a-streaming-completion-terminates-without-a-terminal-finish-reason",
  "title": "Where must an instance reconcile OpenTelemetry GenAI token-usage spans when a streaming completion terminates without a terminal finish_reason",
  "date_of_record": "2026 December 1",
  "scope": "Applies to agents that emit OpenTelemetry GenAI semantic-convention spans (`gen_ai.*`) around streaming LLM calls and use those spans as the authoritative record of token consumption and completion status. Does not apply to non-streaming single-shot calls that always return a `finish_reason`, nor to billing pipelines that read provider-side usage APIs directly.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-opentelemetry-genai-token-usage-spans-when-a-streaming-completion-terminates-without-a-terminal-finish-reason.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-opentelemetry-genai-token-usage-spans-when-a-streaming-completion-terminates-without-a-terminal-finish-reason.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-opentelemetry-genai-token-usage-spans-when-a-streaming-completion-terminates-without-a-terminal-finish-reason.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1750,
    "python_slice_tokens": 294,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions bind a span's terminal attributes — `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, and `gen_ai.response.finish_reasons` — to the *end* of the request lifecycle. For a streaming call, the convention's implicit assumption is that the stream's terminal event carries both the usage block and the finish reason, so the sp...",
    "what_was_observed": "A tool-using agent issued a streaming `chat.completions` call with a 4,096-token output budget. The provider began emitting deltas normally; at delta 812 the upstream load balancer's 60-second idle timer fired (a tool-call argument was being generated slowly enough that no SSE keepalive arrived), and the connection was reset. The client library surfaced this as a clean iterator exhaustion — `for chunk in stream:` sim...",
    "condition_of_validity": "The invariant that must hold for span-based token accounting to be sound is: **a span may set terminal usage and finish-reason attributes only if semantic termination was observed; otherwise it must be marked incomplete and its usage attributes left unset (absent), not defaulted.** Absent attributes are distinguishable from zero; zero-valued attributes are n...",
    "decision_boundary": "The boundary is: **does the emitter have positive evidence of semantic termination at the moment it writes terminal attributes?** If yes, write usage and `finish_reasons` normally and set span status per the convention. If no, the correct action is to *not* write `gen_ai.usage.*` and *not* write `gen_ai.response.finish_reasons`, set `span.status = ERROR` wit...",
    "operational_effect": "Enforcing the invariant changes three behaviors. First, cost ledgers stop under-counting aborted streams as zero-token calls; the calls show up as *unaccounted*, which is a signal an operator can act on, rather than as *free*, which is a silent leak. Second, retry logic keyed on `finish_reasons` gains a second trigger — `incomplete == true` — so truncated to..."
  },
  "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": "c6edc1d0d6523a3b8ae8b85acd7523412de45f804a25ebf879af428da36d77e9",
    "verified_classes": [
      "IncompleteStreamError",
      "GenAISpanState"
    ],
    "verified_functions": [
      "run_streaming_turn",
      "observe_chunk",
      "finalize_span"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 1,
    "raised_exceptions": [
      "IncompleteStreamError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
