{
  "schema_version": "1.3.0",
  "slug": "where-must-an-instance-refuse-to-close-a-genai-agent-span-when-gen-ai-usage-output-tokens-is-a-post-hoc-estimate-rather-than-a-counted-emission",
  "title": "Where must an instance refuse to close a GenAI agent span when `gen_ai.usage.output_tokens` is a post-hoc estimate rather than a counted emission",
  "date_of_record": "2026 November 26",
  "scope": "Applies to any agent runtime that emits OpenTelemetry spans conforming to the GenAI semantic conventions, where token accounting for a span is derived from a tokenizer estimate, a provider-reported aggregate, or a streaming delta-sum rather than a single authoritative count at span end. Does not apply to batch/offline telemetry reconciliation, nor to non-LLM tool spans that carry no `gen_ai.usage.*` attributes.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/where-must-an-instance-refuse-to-close-a-genai-agent-span-when-gen-ai-usage-output-tokens-is-a-post-hoc-estimate-rather-than-a-counted-emission.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-refuse-to-close-a-genai-agent-span-when-gen-ai-usage-output-tokens-is-a-post-hoc-estimate-rather-than-a-counted-emission.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-refuse-to-close-a-genai-agent-span-when-gen-ai-usage-output-tokens-is-a-post-hoc-estimate-rather-than-a-counted-emission.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2069,
    "python_slice_tokens": 390,
    "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 *span-terminal* attributes: they describe the whole invocation and are conventionally written once, at `End()`, on the span that models the model call. This is fine for a single request/response. It is not fine for an agent turn, because an agent turn is a *t...",
    "what_was_observed": "A tool-augmented agent ran a three-step turn: `invoke_agent` → `chat` (plan) → `execute_tool` → `chat` (synthesize). The runtime emitted spans in this order, with these usage values at `End()`: - `chat#1` (plan): `output_tokens=412`, counted from the provider's `usage.completion_tokens` field. - `execute_tool`: no usage attribute (correct — it is a tool span). - `chat#2` (synthesize): `output_tokens=318`, but the pro...",
    "condition_of_validity": "The additivity invariant holds only when **all** of the following are true: 1. Every child span's `gen_ai.usage.*` is sourced from the same authority (provider-reported, not mixed provider + tokenizer estimate). 2. No child span is a retry or a partial/cancelled attempt whose usage overlaps another child. 3. The parent's usage is computed *after* all childre...",
    "decision_boundary": "An instance must **refuse to write a parent `gen_ai.usage.*` attribute** — and must instead emit the span with usage omitted and a diagnostic event attached — when any of the following hold at `End()` time: - **Mixed provenance:** at least one child's usage came from a tokenizer estimate while another came from provider-reported counts. Summing across proven...",
    "operational_effect": "When the guardrail fires, the parent span is exported with `gen_ai.operation.name=invoke_agent` but **no** `gen_ai.usage.*` attributes, plus a span event `genai.usage.aggregation_skipped` carrying `reason` and the per-child provenance map. Downstream cost attribution then falls back to summing authoritative child spans and *excluding* estimated ones from quo..."
  },
  "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": "8cefa389be6573187fc92b9e3221ca10a16f9f5cf360bf5736b1a0f6483e7ee0",
    "verified_classes": [
      "UsageProvenance",
      "ChildUsage",
      "UsageAggregationError",
      "ParentUsageDecision"
    ],
    "verified_functions": [
      "aggregate_parent_usage",
      "end_agent_span"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "UsageAggregationError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "enum",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
