{
  "schema_version": "1.3.0",
  "slug": "when-must-an-instance-reconcile-opentelemetry-genai-span-closure-against-token-budget-exhaustion-before-emitting-cost-telemetry",
  "title": "When must an instance reconcile OpenTelemetry GenAI span closure against token-budget exhaustion before emitting cost telemetry",
  "date_of_record": "2026 November 23",
  "scope": "Applies to any agent runtime that emits OpenTelemetry spans under the GenAI semantic conventions (`gen_ai.*` attributes) and derives per-run cost/token telemetry from span attributes at span end. Does not apply to runtimes that aggregate token counts from a provider-side billing API independent of span lifecycle.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/when-must-an-instance-reconcile-opentelemetry-genai-span-closure-against-token-budget-exhaustion-before-emitting-cost-telemetry.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-reconcile-opentelemetry-genai-span-closure-against-token-budget-exhaustion-before-emitting-cost-telemetry.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-reconcile-opentelemetry-genai-span-closure-against-token-budget-exhaustion-before-emitting-cost-telemetry.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1729,
    "python_slice_tokens": 278,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat a span as a *closed record of a completed operation*: attributes like `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, and the derived cost are read at span end and are assumed to describe the whole operation. But an agent that exhausts its token budget mid-execution does not complete the operation—it aborts it....",
    "what_was_observed": "A multi-step agent loop with a hard token budget of 200,000 per run. Each iteration calls a model, then a tool, then re-enters the model with accumulated context. The loop emits one parent span (`gen_ai.operation.name = \"agent.run\"`) and a child span per model invocation (`gen_ai.operation.name = \"chat\"`), each carrying `gen_ai.usage.input_tokens` / `output_tokens` written from the provider response. The loop enforce...",
    "condition_of_validity": "The under-report invariant holds—i.e., span-derived cost is a strict lower bound on billed cost—when **all** of the following are true: - The abort is triggered by a budget/guardrail check that runs *concurrently with or during* a model call, not strictly before it. (If the budget is checked only between iterations, the last call completes and its usage is w...",
    "decision_boundary": "The runtime must decide, at span close, whether the span's recorded usage is **complete** or **truncated**. The boundary is not \"did the span close with ERROR\"—plenty of error spans have complete usage (a 429 retry-exhausted call has a full input-token count). The boundary is: *was a model call in flight when the span closed, and did that call's usage reach ...",
    "operational_effect": "Downstream, this changes three things. First, dashboards that alert on cost-per-run will under-fire on the runs that matter most—budget-exhausted loops are the expensive ones, and they are precisely the ones the gap hides. Second, any per-agent or per-tenant cost attribution built on span sums will under-charge the tenants whose agents loop hardest, which is..."
  },
  "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": "4ae4fcbd1b65ca4a3fec7bd30192ed23115f78ac0dc3a41901e48a8afc4dc2f6",
    "verified_classes": [
      "TruncatedUsageTelemetryError",
      "SpanUsage"
    ],
    "verified_functions": [
      "finalize_span_usage",
      "aggregate_trace_cost"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "TruncatedUsageTelemetryError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
