{
  "schema_version": "1.3.0",
  "slug": "in-what-scenarios-must-an-instance-refuse-to-close-a-genai-agent-span-on-token-accounting-reconciliation-failure",
  "title": "In what scenarios must an instance refuse to close a GenAI agent span on token-accounting reconciliation failure",
  "date_of_record": "2026 November 28",
  "scope": "Applies to any agent runtime that emits OpenTelemetry spans conforming to the GenAI semantic conventions (`gen_ai.*` attributes, `gen_ai.operation.name`, `gen_ai.usage.input_tokens`/`output_tokens`) where a single logical agent turn fans out across multiple model calls and tool calls under one parent span. Does not apply to single-shot, single-span LLM invocations with no nested tool execution, nor to pure trace-export pipelines that never aggregate usage locally.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-refuse-to-close-a-genai-agent-span-on-token-accounting-reconciliation-failure.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-refuse-to-close-a-genai-agent-span-on-token-accounting-reconciliation-failure.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-refuse-to-close-a-genai-agent-span-on-token-accounting-reconciliation-failure.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2126,
    "python_slice_tokens": 337,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat token usage as an *attribute of a span*, not as a *ledger that must balance*. This is the entire trap. A `gen_ai.chat` span carries `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` describing *that one model call*. A parent agent span (`gen_ai.operation.name = \"invoke_agent\"` or `\"execute_tool\"` wrappers) is e...",
    "what_was_observed": "A tool-using agent loop under a single `invoke_agent` parent span, with N child `gen_ai.chat` spans and M child `gen_ai.execute_tool` spans. The instance maintained `self.total_input_tokens` incremented after each model response. On each iteration it also opened and closed a child chat span with the provider's reported usage. Three concrete divergences were observed: 1. **Retry double-count in the child, single-count...",
    "condition_of_validity": "The invariant holds—and the instance is *required* to reconcile before closing—only when all of the following are true: - The parent span is a *usage-aggregating* span, i.e. it declares `gen_ai.operation.name` of `invoke_agent` (or otherwise semantically owns the children's consumption), and - At least one child span under it carries any `gen_ai.usage.*` att...",
    "decision_boundary": "The instance must distinguish three outcomes at parent-close time: - **Reconciled:** parent aggregate derived from child ledger, residual non-negative and attributable. Close span `OK`, emit aggregate with a `gen_ai.usage.reconciliation = \"child_ledger\"` style marker (vendor extension) so auditors know the provenance. - **Unreconcilable but bounded:** residu...",
    "operational_effect": "Without this boundary, the failure is silent and compounding. Cost dashboards that sum parent `gen_ai.usage.input_tokens` across agent spans under-report by the retry and cache deltas; a 3% cache-hit rate on a long-running agent fleet becomes a 3% systematic under-billing that no per-span check catches because every individual span is well-formed. Trace-base..."
  },
  "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": "f96fb6aff95889f36f13262cd6b96a9e5799a1a87254c39cbba6139e79faca73",
    "verified_classes": [
      "TokenAccountingReconciliationError",
      "ChildUsage",
      "ParentAggregate"
    ],
    "verified_functions": [
      "reconcile_parent_usage"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 1,
    "raised_exceptions": [
      "TokenAccountingReconciliationError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
