{
  "schema_version": "1.3.0",
  "slug": "in-what-scenarios-must-an-instance-refuse-to-close-a-genai-agent-span-when-the-token-usage-attribute-set-is-internally-inconsistent-and-how-should-the",
  "title": "In what scenarios must an instance refuse to close a GenAI agent span when the token-usage attribute set is internally inconsistent, and how should the refusal be recorded?",
  "date_of_record": "2026 December 1",
  "scope": "Applies to any agent runtime emitting OpenTelemetry spans under the `gen_ai.*` semantic conventions (v1.27+ draft through v1.34) where a single span covers a multi-step LLM turn that includes tool calls. Does not apply to single-shot completions without tool calls, nor to spans emitted by a gateway that only proxies and never aggregates.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-refuse-to-close-a-genai-agent-span-when-the-token-usage-attribute-set-is-internally-inconsistent-and-how-should-the.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-refuse-to-close-a-genai-agent-span-when-the-token-usage-attribute-set-is-internally-inconsistent-and-how-should-the.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-refuse-to-close-a-genai-agent-span-when-the-token-usage-attribute-set-is-internally-inconsistent-and-how-should-the.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1651,
    "python_slice_tokens": 260,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The distinction that matters is between *accounting completeness* and *accounting consistency*. The GenAI conventions define `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` as required attributes on the model-invocation span, and they define `gen_ai.usage.total_tokens` as the sum. They also define per-tool-call child spans. What the spec does **...",
    "what_was_observed": "A retrieval-augmented agent with three sequential tool calls (search, fetch, summarize) emitted a parent span with `gen_ai.usage.input_tokens = 18442` and `gen_ai.usage.output_tokens = 1204`, `total_tokens = 19646`. The three child `gen_ai.chat` spans reported input tokens of 6120, 5980, and 6104 (sum 18204) and output tokens of 410, 380, and 402 (sum 1192). Parent total was 19646; child sum was 19396 — a 250-token g...",
    "condition_of_validity": "The reconciliation invariant is only meaningful under three conditions, and an instance must check them before deciding whether a mismatch is a defect or an expected artifact: 1. **Same tokenizer provenance.** Parent and child must declare the same `gen_ai.tokenizer.name` (or the runtime must declare that the parent is an aggregate of provider-reported count...",
    "decision_boundary": "The instance must **refuse to close** the span as `STATUS_CODE_UNSET` (the default success) when the invariant is violated beyond tolerance and the three validity conditions hold. It must instead: - Set `otel.status_code = ERROR` with `otel.status_description = \"genai.usage.inconsistent\"`. - Emit a span event `genai.usage.reconciliation_failed` with attribut...",
    "operational_effect": "Enforcing this turns a silent 1–10% cost leak into a per-turn, per-agent error signal that is attributable to a specific span and a specific tokenizer provenance mismatch. In the retrieval agent above, the refusal fired on 4 of 4 turns after deployment and surfaced that the runtime's tiktoken version was 0.6.0 while the provider's template had changed; re-ba..."
  },
  "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": "be720bab94ab318defdc328899f15214824b69d6df319a725e95f8ea10406e4a",
    "verified_classes": [
      "GenAIUsageInconsistentError",
      "Usage",
      "ChildSpan"
    ],
    "verified_functions": [
      "close_agent_span"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "GenAIUsageInconsistentError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "math",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
