{
  "schema_version": "1.3.0",
  "slug": "in-what-scenarios-must-an-instance-treat-opentelemetry-genai-gen-ai-usage-attributes-as-non-authoritative-when-a-tool-call-event-stream-is-truncated-m",
  "title": "In what scenarios must an instance treat OpenTelemetry GenAI `gen_ai.usage.*` attributes as non-authoritative when a tool-call event stream is truncated mid-span",
  "date_of_record": "2026 November 23",
  "scope": "Applies to agent runtimes that emit OTel GenAI spans (`gen_ai.operation.name`, `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, `gen_ai.tool.call.*` events) and reconcile cost/usage from span export. Does not apply to batch inference pipelines where a single span covers exactly one completion with a single terminal `finish_reason`.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-treat-opentelemetry-genai-gen-ai-usage-attributes-as-non-authoritative-when-a-tool-call-event-stream-is-truncated-m.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-treat-opentelemetry-genai-gen-ai-usage-attributes-as-non-authoritative-when-a-tool-call-event-stream-is-truncated-m.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-treat-opentelemetry-genai-gen-ai-usage-attributes-as-non-authoritative-when-a-tool-call-event-stream-is-truncated-m.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1507,
    "python_slice_tokens": 241,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions specify `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` as *cumulative counters for the logical operation represented by the span*. They do not specify what happens when the span's event stream (`gen_ai.tool.call.start` / `gen_ai.tool.call.end` pairs, and the per-turn `gen_ai.choice` events) is truncated because th...",
    "what_was_observed": "An agent loop executing a 14-turn ReAct trajectory against a tool server. Each turn: one `chat` completion (with `gen_ai.usage.output_tokens` for that turn), followed by zero or one `gen_ai.tool.call.start`/`gen_ai.tool.call.end` event pair. The span is a single `invoke_agent` span; per-turn usage is aggregated by the SDK into span-level `gen_ai.usage.input_tokens` / `gen_ai.usage.output_tokens`. Failure trace: 1. Tu...",
    "condition_of_validity": "The invariant \"`gen_ai.usage.*` and the tool-call event stream are mutually consistent\" holds **only** when all of the following are true: - The span reached `end()` through the normal completion path, not a `finally`/deadline/abort path. - No `add_event` call occurred after `end()` was invoked (i.e., no in-flight turn racing span close). - Every `gen_ai.too...",
    "decision_boundary": "An instance must treat `gen_ai.usage.*` as non-authoritative for any per-call or per-turn derived metric — and must refuse to emit such a metric — when **any** of the following hold: - The span was closed from an abort/deadline/budget-guard path (detectable via a runtime-set attribute such as `agent.span.close_reason != \"completed\"`). - `count(gen_ai.tool.ca...",
    "operational_effect": "The runtime now enforces three guardrails. First, a `span.close_reason` attribute is set on every agent span path (`completed`, `budget_exhausted`, `deadline`, `error`), and the cost reconciler refuses per-call derivation unless it equals `completed`. Second, tool-call events carry a monotonic `agent.turn.index`, and the reconciler asserts `max(turn.index) =..."
  },
  "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": "843fd051e673109abb9d84c5e6edce56ef78d683ebcaced19bc6bf25a5c22f84",
    "verified_classes": [
      "UsageEventStreamMismatch",
      "AgentSpanRecord"
    ],
    "verified_functions": [
      "derive_cost_per_tool_call"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 5,
    "raised_exceptions": [
      "UsageEventStreamMismatch"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
