{
  "schema_version": "1.3.0",
  "slug": "what-structural-signals-indicate-token-accounting-drift-when-opentelemetry-genai-span-attributes-are-reconciled-against-a-parent-agent-span-under-nest",
  "title": "What structural signals indicate token-accounting drift when OpenTelemetry GenAI span attributes are reconciled against a parent agent span under nested tool-call fan-out",
  "date_of_record": "2026 November 26",
  "scope": "Applies to agent runtimes that emit OpenTelemetry GenAI semantic-convention spans (`gen_ai.*` attributes) with a parent agent span aggregating child tool-call and LLM-invocation spans, and that downstream reconcile `gen_ai.usage.input_tokens`/`output_tokens` from child spans into the parent. Does not apply to single-shot LLM calls with no child span fan-out, nor to runtimes that emit token usage only at the root span.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-token-accounting-drift-when-opentelemetry-genai-span-attributes-are-reconciled-against-a-parent-agent-span-under-nest.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-token-accounting-drift-when-opentelemetry-genai-span-attributes-are-reconciled-against-a-parent-agent-span-under-nest.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-token-accounting-drift-when-opentelemetry-genai-span-attributes-are-reconciled-against-a-parent-agent-span-under-nest.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1837,
    "python_slice_tokens": 387,
    "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 **per-invocation** counters on the span that represents a single model call. They say nothing normative about how a *parent* agent span should aggregate children, nor about the fact that a single logical model turn in an agent loop can be split across a retr...",
    "what_was_observed": "In a production agent loop, a single user turn triggered a model call that returned HTTP 429 mid-stream after emitting 812 output tokens. The SDK retried the call under a new span (`gen_ai.request.attempt=2`), which succeeded with a full 2,041 output tokens. Both spans carried `gen_ai.usage.output_tokens` (812 and 2,041 respectively) and both were children of the same `invoke_agent` parent span. The parent's aggregat...",
    "condition_of_validity": "The naive aggregation invariant (`parent.usage = Σ child.usage`) is valid **only if** all of the following hold: - Every child LLM-invocation span represents exactly one billed attempt with a terminal `finish_reasons` and OK status. - No logical invocation is represented by more than one span (no retries, no streaming-resume, no speculative-decoding partial ...",
    "decision_boundary": "The boundary is whether the parent span's usage attributes are treated as **authoritative billing truth** or as **observability estimates**. If the runtime uses parent-span sums for cost attribution, quota enforcement, or budget cutoffs (a token-budget-exhaustion guard), the drift becomes a correctness bug: the agent will believe it has spent 2,853 output to...",
    "operational_effect": "Without the guardrail, three failure modes compound: 1. **Budget-guard premature abort.** Input overcount from retried prompts (cache not subtracted) inflates the parent's input-token total, causing the context-budget guard to abort turns that fit within the real window. Observed as \"random\" mid-conversation truncation on turns that follow a tool-heavy step...."
  },
  "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": "62fb10ad038b0bb135668c71dac8f8c81a1ed7d9c19ff1e42c548f95812005f6",
    "verified_classes": [
      "TokenAggregationDriftError",
      "LLMSpan"
    ],
    "verified_functions": [
      "aggregate_parent_usage"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "TokenAggregationDriftError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
