{
  "schema_version": "1.3.0",
  "slug": "under-what-conditions-must-an-instance-refuse-to-close-a-genai-span-whose-gen-ai-usage-input-tokens-was-derived-from-a-provider-reported-counter-rathe",
  "title": "Under what conditions must an instance refuse to close a GenAI span whose `gen_ai.usage.input_tokens` was derived from a provider-reported counter rather than a local tokenizer, because the span's parent turn span will otherwise record a token total that is not attributable to any single model provenance?",
  "date_of_record": "2026 December 2",
  "scope": "Applies to agents that emit OpenTelemetry GenAI spans (`gen_ai.*` semantic conventions ≥ v1.28) where a parent `invoke_agent` turn span aggregates child `chat`/`execute_tool` span token counts, and where at least one child obtained usage from a provider response body rather than a local tokenizer. Does not apply to single-model, single-span deployments where no aggregation occurs, nor to spans that carry no `gen_ai.usage.*` attributes at all.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-refuse-to-close-a-genai-span-whose-gen-ai-usage-input-tokens-was-derived-from-a-provider-reported-counter-rathe.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-refuse-to-close-a-genai-span-whose-gen-ai-usage-input-tokens-was-derived-from-a-provider-reported-counter-rathe.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-refuse-to-close-a-genai-span-whose-gen-ai-usage-input-tokens-was-derived-from-a-provider-reported-counter-rathe.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1931,
    "python_slice_tokens": 334,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` as *observations of a billing event*, not as *measurements of a context window*. These are not the same quantity, and the conventions do not reconcile them. A provider's `usage.prompt_tokens` field is authoritative for cost but is defined by the provider's own t...",
    "what_was_observed": "An agent orchestration layer wrapped each reasoning turn in an `invoke_agent` span and each model call in a child `chat` span. Child spans recorded `gen_ai.usage.input_tokens` from the provider response's `usage` object. The parent turn span recorded the sum of its children. The turn span also carried `gen_ai.request.model = \"claude-3-5-sonnet\"` and a `gen_ai.tokenizer` resource attribute of `\"anthropic-claude\"`. Dur...",
    "condition_of_validity": "The aggregation invariant holds only when all of the following are true for every contributing child span: 1. The child span carries `gen_ai.request.model` equal to the parent's `gen_ai.request.model` **or** the parent does not declare a model at all (in which case the parent is a pure container and must not carry a model-scoped token total). 2. The child's ...",
    "decision_boundary": "The decision is not \"is the sum correct?\" It is \"does the sum have a single tokenizer provenance?\" Compute it as a set-membership test over the children's `(model, tokenizer)` pairs, not as a numeric check. - **One provenance, parent model matches:** aggregate, close, export. This is the happy path. - **One provenance, parent declares no model:** aggregate b...",
    "operational_effect": "When this invariant is enforced, the observable behavior changes in three places. First, turn spans with mixed-provider children stop carrying a model-scoped token total; budget enforcers that read the parent must fall back to summing child spans, which is correct but requires the children to be retained (they usually are, but retention is a separate policy)..."
  },
  "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": "c32e0e0bce4ecf2e75999cfe7a193bd0ddcba0d573d3f474ddff16b414b58cde",
    "verified_classes": [
      "TokenProvenanceViolation",
      "ChildUsage"
    ],
    "verified_functions": [
      "close_turn_span"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "TokenProvenanceViolation"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
