{
  "schema_version": "1.3.0",
  "slug": "under-what-conditions-must-an-instance-refuse-to-close-a-genai-agent-span-when-the-token-accounting-child-spans-disagree-with-the-parent-s-gen-ai-usag",
  "title": "Under what conditions must an instance refuse to close a GenAI agent span when the token-accounting child spans disagree with the parent's `gen_ai.usage.*` attributes",
  "date_of_record": "2026 November 28",
  "scope": "Applies to any agent runtime that emits OpenTelemetry spans conforming to the GenAI semantic conventions (`gen_ai.operation.name`, `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, and tool-call child spans) where a parent agent span aggregates token counts from one or more LLM or tool child spans. Does not apply to single-shot, single-span inference calls with no child spans, nor to runtimes that emit only metrics without spans.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-refuse-to-close-a-genai-agent-span-when-the-token-accounting-child-spans-disagree-with-the-parent-s-gen-ai-usag.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-refuse-to-close-a-genai-agent-span-when-the-token-accounting-child-spans-disagree-with-the-parent-s-gen-ai-usag.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-refuse-to-close-a-genai-agent-span-when-the-token-accounting-child-spans-disagree-with-the-parent-s-gen-ai-usag.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2382,
    "python_slice_tokens": 387,
    "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 *attributes of the span that performed the inference*. They do not specify how a parent agent span that fans out to N child LLM calls should reconcile its own usage attributes against the sum of its children. This is the gap. The distinction that matters oper...",
    "what_was_observed": "Consider a planner-executor agent that, for a single user request, issues: 1. One planning LLM call (child span `plan`, `input_tokens=820`, `output_tokens=210`). 2. Three tool-call spans, each of which internally makes an LLM call to summarize the tool result before returning it to the executor (`tool_1`, `tool_2`, `tool_3`, each with its own `gen_ai.usage.*` — e.g. `input_tokens=1450/1380/1510`, `output_tokens=95/10...",
    "condition_of_validity": "The invariant that must hold for a GenAI agent trace to be trustworthy for accounting is: > For every span `S` with `gen_ai.operation.name == \"invoke_agent\"` (or any span that declares itself an aggregate over descendants), and for the set `D` of all descendant spans carrying `gen_ai.usage.input_tokens` / `gen_ai.usage.output_tokens`: > `S.gen_ai.usage.input...",
    "decision_boundary": "The decision boundary is: **at what point does the parent span commit its usage attributes, and what does it do when the committed value cannot be proven equal to the descendant sum?** Two policies are defensible, and the choice must be explicit in the runtime: 1. **Strict aggregation with deferred close.** The parent span does not call `span.end()` until al...",
    "operational_effect": "The downstream effects of a silently under-counted agent span are not confined to dashboards: - **Budget enforcement under-fires.** A per-agent token budget computed from span aggregates will permit more real spend than configured, because the trace reports less than the provider bills. The gap is proportional to tool-nested inference volume, which grows wit..."
  },
  "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": "04a0d418dd77ba8763a46700cc1e114ad89caec2c5d06edc845251317181bae5",
    "verified_classes": [
      "TokenAccountingInvariantError",
      "SpanNode"
    ],
    "verified_functions": [
      "_descendant_usage",
      "close_agent_span"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "TokenAccountingInvariantError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
