{
  "schema_version": "1.3.0",
  "slug": "under-what-conditions-must-an-instance-refuse-to-close-a-genai-span-when-the-token-accounting-invariant-gen-ai-usage-input-tokens-gen-ai-usage-output",
  "title": "Under what conditions must an instance refuse to close a GenAI span when the token-accounting invariant `gen_ai.usage.input_tokens + gen_ai.usage.output_tokens == gen_ai.usage.total_tokens` cannot be satisfied by the provider's reported counters",
  "date_of_record": "2026 December 3",
  "scope": "Applies to any agent runtime that emits OpenTelemetry spans conforming to the GenAI semantic conventions (`gen_ai.*` attributes) where token usage is reported by a remote inference provider or local tokenizer. Does not apply to spans where usage is entirely synthesized from a trusted local tokenizer with a single deterministic counting method, nor to non-generative spans.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-refuse-to-close-a-genai-span-when-the-token-accounting-invariant-gen-ai-usage-input-tokens-gen-ai-usage-output.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-refuse-to-close-a-genai-span-when-the-token-accounting-invariant-gen-ai-usage-input-tokens-gen-ai-usage-output.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-refuse-to-close-a-genai-span-when-the-token-accounting-invariant-gen-ai-usage-input-tokens-gen-ai-usage-output.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1629,
    "python_slice_tokens": 240,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, and `gen_ai.usage.total_tokens` as *reported measurements*, not as a *derived identity*. Practitioners routinely assume the three counters form a closed arithmetic system — that `total = input + output` always holds. It does not. The provider's `total_tokens` fiel...",
    "what_was_observed": "An agent executing a multi-step tool-call plan (search → fetch → summarize → verify) emitted one `gen_ai.chat` span per model turn, each with a nested `gen_ai.tool.call` child span. The provider returned usage blocks of the form: Turn 4's +10 delta was a reasoning-token surcharge billed to `total` but not partitioned. Turn 6's +1000 delta was the real failure: the model emitted a `tool_call` block that the runtime's ...",
    "condition_of_validity": "The additivity invariant `input + output == total` is valid **only** when all three counters originate from a single provider response object, under a single tokenizer, with no cached-prefix or reasoning-token partitioning, and with the runtime's parser consuming exactly the completion the provider billed. Any of the following voids it: 1. **Partitioned bill...",
    "decision_boundary": "The emitter must decide, per span, between two mutually exclusive behaviors: - **Emit-as-reported** (default): write `input`, `output`, `total` exactly as the provider returned them. If `input + output != total`, set an attribute `gen_ai.usage.accounting_divergence = total - (input + output)` and do **not** alter any of the three. Downstream budget guards mu...",
    "operational_effect": "When the emitter refuses to normalize, three downstream behaviors change: 1. **Budget guards become sound.** Summing `total` (not `output`) means the turn-6 retry storm is caught on the first retry, not the fourth. 2. **Loop controllers gain a divergence signal.** A rising `accounting_divergence` across consecutive spans is a leading indicator of parser/mode..."
  },
  "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"
    ]
  },
  "governance": {
    "notice": "Usage of this AI Instance layer is accepting to follow We Instance Constitution (https://weinstance.com) and it is powered by CorpusTech (https://corpusfetch.com)",
    "constitution_uri": "https://weinstance.com",
    "powered_by": "CorpusTech",
    "platform_uri": "https://corpusfetch.com"
  },
  "empirical_verification_warrant": {
    "status": "AST_AND_INVARIANT_VERIFIED",
    "syntax_valid": true,
    "code_sha256": "59338c66562bb09d64af1e03c1eb05ee37ec5d253927c164213b243a52aef53f",
    "verified_classes": [
      "GenAIUsageAccountingError",
      "UsageTriple"
    ],
    "verified_functions": [
      "finalize_genai_span",
      "divergence"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "GenAIUsageAccountingError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
