{
  "schema_version": "1.3.0",
  "slug": "where-must-an-instance-refuse-to-close-a-genai-agent-span-until-child-tool-call-token-counts-are-reconciled-and-why-does-opentelemetry-s-gen-ai-usage",
  "title": "Where must an instance refuse to close a GenAI agent span until child tool-call token counts are reconciled, and why does OpenTelemetry's `gen_ai.usage.*` convention silently permit divergence?",
  "date_of_record": "2026 December 2",
  "scope": "Applies to agents emitting OpenTelemetry spans under the GenAI semantic conventions where a parent `invoke_agent` (or `chat`) span aggregates tokens consumed by nested tool-call spans and retried LLM sub-calls. Does not apply to single-shot inference with no nested spans, nor to providers that emit token counts only at the top-level request boundary.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/where-must-an-instance-refuse-to-close-a-genai-agent-span-until-child-tool-call-token-counts-are-reconciled-and-why-does-opentelemetry-s-gen-ai-usage.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-refuse-to-close-a-genai-agent-span-until-child-tool-call-token-counts-are-reconciled-and-why-does-opentelemetry-s-gen-ai-usage.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-refuse-to-close-a-genai-agent-span-until-child-tool-call-token-counts-are-reconciled-and-why-does-opentelemetry-s-gen-ai-usage.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2193,
    "python_slice_tokens": 422,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` as attributes on the span that *represents the model call*. They do not define a reconciliation rule between a parent agent span's token attributes and the sum of its children's. This is not an oversight in the schema — it is a deliberate silence, because the c...",
    "what_was_observed": "A multi-tool agent (planner → 3 parallel retrieval tool calls → synthesis call) was instrumented with the GenAI conventions. The parent `invoke_agent` span was ended in a `finally` block that set `gen_ai.usage.input_tokens` from the orchestrator's own accumulator. Two failure traces were captured: **Trace A — late child completion.** One retrieval tool call was wrapped in an async task that resolved *after* the synth...",
    "condition_of_validity": "The invariant `parent ≥ Σ children` (with equality absent retries) is only checkable if three conditions hold simultaneously, and the convention guarantees none of them: 1. **Span end ordering.** All child spans must end before the parent's token attributes are written. OTel does not enforce span end ordering — a child can end after its parent in wall-clock ...",
    "decision_boundary": "An instance must **refuse to finalize** an `invoke_agent` span's `gen_ai.usage.*` attributes when any of the following are true, and must instead emit a `gen_ai.usage.reconciliation_failed` marker attribute (non-standard, but the convention's silence permits extension) and end the span with tokens unset rather than wrong: - The accumulator snapshot was taken...",
    "operational_effect": "When this boundary is ignored, three downstream systems consume a lie: - **Cost attribution** silently reclassifies retry tokens as agent overhead or drops them, so per-tool ROI is wrong by the retry rate. At a 15% retry rate on a 1,340-token synthesis call, 6% of total spend vanishes from tool-level accounting. - **Quota enforcement** uses the parent total,..."
  },
  "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": "fb9bf8f503989abdbb35950ad6d47e1fc2f800c858b50dbeaf91105bdff06caf",
    "verified_classes": [
      "UnreconciledSpanError",
      "ChildSpan",
      "AgentSpan"
    ],
    "verified_functions": [
      "finalize_agent_turn",
      "add_child",
      "snapshot_tokens",
      "reconcile_and_commit"
    ],
    "verified_functions_count": 4,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "UnreconciledSpanError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "time",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
