{
  "schema_version": "1.3.0",
  "slug": "how-should-an-instance-reconcile-gen-ai-usage-input-tokens-when-a-retried-model-span-double-counts-a-parent-agent-span-s-budget",
  "title": "How should an instance reconcile `gen_ai.usage.input_tokens` when a retried model span double-counts a parent agent span's budget",
  "date_of_record": "2026 November 29",
  "scope": "Applies to any agent runtime that emits OpenTelemetry GenAI semantic-convention spans (`gen_ai.operation.name`, `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, `gen_ai.request.model`) and performs automatic retries or fallbacks of model invocations inside a parent agent span. Does not apply to single-shot, non-retried inference calls that are not aggregated into a parent budget.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-gen-ai-usage-input-tokens-when-a-retried-model-span-double-counts-a-parent-agent-span-s-budget.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-gen-ai-usage-input-tokens-when-a-retried-model-span-double-counts-a-parent-agent-span-s-budget.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-gen-ai-usage-input-tokens-when-a-retried-model-span-double-counts-a-parent-agent-span-s-budget.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1998,
    "python_slice_tokens": 481,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "There are two distinct notions of \"tokens consumed\" that the GenAI semantic conventions leave ambiguous at the span level: **billed tokens** (what the provider charged across all attempts, including failed and retried ones) and **attributable tokens** (what a single logical model invocation contributed to the parent agent's context budget). The conventions d...",
    "what_was_observed": "An orchestrator agent span (`gen_ai.operation.name = \"invoke_agent\"`) wrapped a planning step that called a model with a 40k-token prompt. The transport layer retried twice: once on a 429 (no tokens billed, but the span was still emitted with `gen_ai.usage.input_tokens = 40000` because the client counted the serialized request before sending), and once on a 503 after the provider had already begun processing (billed,...",
    "condition_of_validity": "The invariant that must hold for parent-span token aggregation to be trustworthy: > For any logical model invocation, exactly one child span carries the **attributable** token count, and the sum of `gen_ai.usage.input_tokens` over the *chosen* child spans equals the context the parent actually consumed. This requires that the runtime distinguish, at span-emi...",
    "decision_boundary": "The runtime must choose, per parent span, between two aggregation modes, and the choice must be explicit in the trace: - **Attribution mode** (default for context-budget guards): sum only spans where `invocation.id` is unique *and* `retry.outcome = \"consumed\"`. Equivalently, deduplicate by `invocation.id`, keeping the span whose output the parent used. This ...",
    "operational_effect": "With the guardrail in place, three things change: 1. **Budget guards stop false-tripping.** The abort described above no longer fires, because the parent reports 40000 (attribution mode) instead of 120000. Agents that previously died at ~40% of real budget now run to their actual ceiling. 2. **Cost reconciliation becomes possible.** Dashboards switch to bill..."
  },
  "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": "9efef21133dff8b56b557505716d4b3fdce0d07608719e1d0ed3c0943e1dba34",
    "verified_classes": [
      "TokenAggregationAmbiguity"
    ],
    "verified_functions": [
      "aggregate_parent_tokens"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "TokenAggregationAmbiguity"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
