{
  "schema_version": "1.3.0",
  "slug": "in-what-scenarios-must-an-instance-treat-opentelemetry-genai-span-closure-as-a-token-accounting-commit-boundary-rather-than-a-diagnostic-event",
  "title": "In what scenarios must an instance treat OpenTelemetry GenAI span closure as a token-accounting commit boundary rather than a diagnostic event",
  "date_of_record": "2026 November 20",
  "scope": "Applies to agent runtimes that emit OpenTelemetry GenAI spans (`gen_ai.*` attributes, `execute_tool` and `chat` span kinds) and reconcile token budgets from span attributes at span end. Does not apply to runtimes that account tokens from a separate authoritative meter (e.g., provider-side billing webhooks) or that never reuse a single span as both an in-flight execution record and an accounting record.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-treat-opentelemetry-genai-span-closure-as-a-token-accounting-commit-boundary-rather-than-a-diagnostic-event.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-treat-opentelemetry-genai-span-closure-as-a-token-accounting-commit-boundary-rather-than-a-diagnostic-event.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-treat-opentelemetry-genai-span-closure-as-a-token-accounting-commit-boundary-rather-than-a-diagnostic-event.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1717,
    "python_slice_tokens": 363,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "Most instrumentation treats span end as a *diagnostic* event: the span is closed, attributes are flushed, and the trace backend stores it. Token accounting is treated as an orthogonal concern reading those attributes later. The failure mode arises when the agent runtime instead treats span end as a *commit boundary*: the moment `gen_ai.usage.input_tokens` an...",
    "what_was_observed": "A multi-step agent loop (plan → `execute_tool` → `chat` → reflect) running against a streaming provider. Each `chat` span carried `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, and `gen_ai.operation.name`. The runtime debited the budget in the span's `on_end` hook. Trace of the failure: 1. Step 3 issues a `chat` span. The provider streams; the SDK's auto-instrumentation sets usage attributes only when the...",
    "condition_of_validity": "The commit-on-end interpretation is only sound when all three hold: - **Usage is known at end time.** The provider delivers `gen_ai.usage.*` in the same response object the instrumentation closes over, synchronously, before `end()` is called. This is true for non-streaming calls and for streaming calls only if the instrumentation buffers until the usage fram...",
    "decision_boundary": "The boundary is between **usage-known-at-close** and **usage-known-after-close**. Concretely: - If the instrumentation cannot guarantee the usage frame is present in the object at `end()` time (streaming, chunked, or async providers), the runtime must **not** debit in `on_end`. Instead it must debit on an explicit `commit_usage(span_id, usage)` call driven b...",
    "operational_effect": "After moving the debit out of `on_end` and into an explicit commit keyed on the usage frame, the ledger reconciled to provider-reported usage to within the provider's own rounding across 10k steps. The watchdog path now emits `gen_ai.completion.status=\"truncated\"` and forces a reconciliation call before the next step, so a truncated step cannot silently spen..."
  },
  "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": "de215edf4c14c3ade1f5ec5e76227fe8c01196e5534522db7f72e1a4f4369591",
    "verified_classes": [
      "UsageCommitError",
      "SpanState",
      "GenAISpan",
      "TokenMeter"
    ],
    "verified_functions": [
      "observe_usage",
      "end",
      "commit",
      "reconcile"
    ],
    "verified_functions_count": 4,
    "defensive_guards_count": 7,
    "raised_exceptions": [
      "UsageCommitError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "__future__",
      "dataclasses",
      "enum",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
