{
  "schema_version": "1.3.0",
  "slug": "what-happens-when-an-instance-emits-genai-token-accounting-spans-across-a-retried-tool-call-double-counting-span-parent-loss-and-the-gen-ai-usage-reco",
  "title": "What happens when an instance emits GenAI token-accounting spans across a retried tool call: double-counting, span-parent loss, and the `gen_ai.usage.*` reconciliation invariant",
  "date_of_record": "2026 November 19",
  "scope": "Applies to LLM agent runtimes that emit OpenTelemetry spans conforming to the GenAI semantic conventions (`gen_ai.*`) and that retry, fan out, or replay tool calls under a parent `invoke_agent` / `execute_tool` span. Does not cover pure tracing of non-GenAI RPCs or non-retried single-shot completions.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-emits-genai-token-accounting-spans-across-a-retried-tool-call-double-counting-span-parent-loss-and-the-gen-ai-usage-reco.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-emits-genai-token-accounting-spans-across-a-retried-tool-call-double-counting-span-parent-loss-and-the-gen-ai-usage-reco.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-emits-genai-token-accounting-spans-across-a-retried-tool-call-double-counting-span-parent-loss-and-the-gen-ai-usage-reco.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1865,
    "python_slice_tokens": 449,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat token usage as a *span attribute* (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`) attached to the span that represents the model invocation. They do **not** define a reconciliation contract between a retried logical operation and the multiple physical spans it produces. The convention is correct for a single s...",
    "what_was_observed": "A planner agent emits `invoke_agent` (span A) → `execute_tool` (span B) → `chat` (span C, the model call that decides the tool arguments). The tool call returns a transient transport error. The runtime's retry policy re-enters the loop, creating span B′ and C′ under a *fresh* `trace_id` because the retry helper constructs a new `Tracer` context rather than continuing the current one. Observed attributes: - Span C: `g...",
    "condition_of_validity": "The over-count is only *detectable* (and only *bounded*) under these conditions: - Every retry attempt MUST carry a shared, non-standard attribute — e.g. `gen_ai.operation.id` or an `agent.attempt` counter — because the convention itself provides no attempt discriminator. Without it, reconciliation is impossible: you cannot distinguish two genuine independen...",
    "decision_boundary": "The architectural choice is: **account at the span (physical attempt) or at the operation (logical unit)?** The convention forces span-level. Agent runtimes that need operation-level cost must add a reconciliation layer. The boundary condition that decides correctness: - If your cost/quota consumer sums raw `gen_ai.usage.*` across all spans, you MUST dedupli...",
    "operational_effect": "Without the guardrail, three operational symptoms appear together and are easy to misdiagnose as separate bugs: (a) monthly token spend runs 10–40% above the sum of per-trace costs, (b) per-trace latency p99 looks healthy while wall-clock agent tasks time out, because the retried attempt lives in an orphaned trace, and (c) trace-replay auditors flag \"duplica..."
  },
  "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": "377aac70c1ebe80c4d9d7dcc25899bc1c3eec1aad93392415629780817d738e7",
    "verified_classes": [
      "TokenAccountingInvariantError",
      "GenAISpan"
    ],
    "verified_functions": [
      "reconcile",
      "emit_retry_span"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 5,
    "raised_exceptions": [
      "TokenAccountingInvariantError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
