{
  "schema_version": "1.3.0",
  "slug": "when-must-an-instance-reject-a-genai-tool-call-span-whose-token-accounting-cannot-be-reconciled-across-the-parent-agent-span-and-the-child-tool-span",
  "title": "When must an instance reject a GenAI tool-call span whose token accounting cannot be reconciled across the parent agent span and the child tool span",
  "date_of_record": "2026 December 2",
  "scope": "Applies to any agent runtime emitting OpenTelemetry spans under the GenAI semantic conventions (`gen_ai.*`) where an agent span (`gen_ai.operation.name = \"invoke_agent\"` or `\"chat\"`) parents one or more tool-call spans (`gen_ai.operation.name = \"execute_tool\"`) and token usage is recorded on both. Does not apply to single-shot inference spans with no child tool spans, nor to runtimes that emit usage exclusively on the leaf span.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/when-must-an-instance-reject-a-genai-tool-call-span-whose-token-accounting-cannot-be-reconciled-across-the-parent-agent-span-and-the-child-tool-span.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-reject-a-genai-tool-call-span-whose-token-accounting-cannot-be-reconciled-across-the-parent-agent-span-and-the-child-tool-span.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-reject-a-genai-tool-call-span-whose-token-accounting-cannot-be-reconciled-across-the-parent-agent-span-and-the-child-tool-span.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1622,
    "python_slice_tokens": 311,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat token usage as a *span-local* attribute: `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` describe the tokens consumed by the model call that produced that span. This is correct for a single inference. It becomes structurally ambiguous the moment an agent span parents tool spans, because the agent's own reason...",
    "what_was_observed": "A multi-step agent (plan → tool → observe → tool → answer) emitted, per turn, a `chat` child span under the `invoke_agent` parent, each carrying `gen_ai.usage.input_tokens`/`output_tokens` from the provider response. The parent `invoke_agent` span additionally carried usage attributes set by the runtime, which summed the per-turn usage *and* re-emitted the final turn's usage from the response object. Result: the fina...",
    "condition_of_validity": "The rejection rule is valid only under these conditions, and an instance must *check* them before raising: 1. The span in question has `gen_ai.operation.name` in the agent/chat family and has at least one child span with `gen_ai.operation.name = \"execute_tool\"` or a nested `\"chat\"` span. 2. The parent carries `gen_ai.usage.input_tokens` or `gen_ai.usage.outp...",
    "decision_boundary": "The boundary is between *rollup semantics* and *leaf semantics* for the same attribute namespace. A collector or validator must decide, per span, which frame it is in: - **Leaf frame:** usage describes exactly one model invocation. Summing across leaves is correct. - **Rollup frame:** usage describes an aggregate over turns. Summing across the tree double-co...",
    "operational_effect": "Enforcing the rejection at span-close converts a silent 2× cost inflation into a hard, attributable error at the emitting instance, with the offending span ID and the duplicate attribute path in the exception. In the observed deployment this reduced reported-token error from a turn-dependent 2.0×–2.3× to within 0.4% of provider billing after the runtime was ..."
  },
  "matched_failure_symptoms": [
    "SUBPROCESS_PIPE_HANG_OR_FD_LEAK"
  ],
  "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": "f3654b627c92b746794cd40c06b8789507121ddc2a321168bcc167c6dd41b169",
    "verified_classes": [
      "TokenAccountingReconciliationError",
      "Span"
    ],
    "verified_functions": [
      "_walk",
      "validate_span_usage",
      "has_usage",
      "is_aggregate"
    ],
    "verified_functions_count": 4,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "TokenAccountingReconciliationError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "__future__",
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
