{
  "schema_version": "1.3.0",
  "slug": "in-what-scenarios-must-an-instance-refuse-to-close-a-genai-agent-span-when-the-token-accounting-attributes-disagree-with-the-parent-span-s-aggregated",
  "title": "In what scenarios must an instance refuse to close a GenAI agent span when the token-accounting attributes disagree with the parent span's aggregated usage",
  "date_of_record": "2026 November 28",
  "scope": "Applies to any agent runtime emitting OpenTelemetry spans under the GenAI semantic conventions (`gen_ai.*`) where child tool-call and LLM-invocation spans roll up into a parent agent span carrying aggregate `gen_ai.usage.input_tokens` / `gen_ai.usage.output_tokens`. Does not apply to single-shot, non-nested LLM calls with no parent aggregation, nor to systems where usage is exported only as metrics (histograms) rather than span attributes.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-refuse-to-close-a-genai-agent-span-when-the-token-accounting-attributes-disagree-with-the-parent-span-s-aggregated.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-accounting-attributes-disagree-with-the-parent-span-s-aggregated.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-accounting-attributes-disagree-with-the-parent-span-s-aggregated.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1807,
    "python_slice_tokens": 364,
    "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 *per-span observations of a single model invocation*. They were never designed as a *conservation ledger* across a span tree. But agent runtimes inevitably use them that way: the parent agent span is the only place a billing pipeline, a budget enforcer, or a ...",
    "what_was_observed": "An agent loop over a 14-step research task. The parent agent span opened with `gen_ai.operation.name = \"invoke_agent\"`. Each iteration produced one `chat` span (LLM call) and zero or more `execute_tool` spans. Three independent divergence sources were observed in a single trace: 1. **Retried model calls.** A `chat` span hit a 429, was retried inside the same logical step, and the retry succeeded. The runtime emitted ...",
    "condition_of_validity": "The conservation invariant `parent.usage == Σ(descendants.usage)` is only valid to *assert* when all of the following hold: - Every descendant span that consumes tokens is a descendant of the parent in the same trace (no cross-trace or linked-trace usage). - The parent aggregator's unit of accounting is the *emitted span*, not the *logical step* — i.e., retr...",
    "decision_boundary": "The boundary is at `span.end()` on the parent agent span, and the decision is binary: **close with a reconciled, authoritative token ledger, or close with an explicitly non-authoritative ledger and a divergence diagnostic.** The runtime must refuse to close the parent as authoritative when: - `Σ(descendants) != parent.aggregate` beyond a tolerance (tolerance...",
    "operational_effect": "Closing a divergent parent span as `OK` poisons every consumer that trusts trace topology. Budget enforcers that read parent aggregates under-count (retry drops) or over-count (double-folded retries) and either let a runaway loop run one more iteration or cut a healthy task. Cost reconcilers that walk the subtree and sum children get a different number than ..."
  },
  "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": "3501ab437025b9ec87a168f3796c44d146e09c2cc2313e20489f4a12e1fb086f",
    "verified_classes": [
      "UsageReconciliationError",
      "SpanUsage",
      "ParentLedger"
    ],
    "verified_functions": [
      "close_agent_span"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "UsageReconciliationError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
