{
  "schema_version": "1.3.0",
  "slug": "where-must-an-instance-reconcile-opentelemetry-genai-span-accounting-when-a-retried-tool-call-double-counts-tokens-across-a-re-parented-span",
  "title": "Where must an instance reconcile OpenTelemetry GenAI span accounting when a retried tool call double-counts tokens across a re-parented span?",
  "date_of_record": "2026 November 28",
  "scope": "Applies to agents emitting OpenTelemetry GenAI semantic-convention spans (`gen_ai.*` attributes) where tool invocations are retried and the retry is re-parented under a new agent-turn span. Does not cover non-instrumented runtimes or pure inference servers without tool-call loops.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-opentelemetry-genai-span-accounting-when-a-retried-tool-call-double-counts-tokens-across-a-re-parented-span.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-opentelemetry-genai-span-accounting-when-a-retried-tool-call-double-counts-tokens-across-a-re-parented-span.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-opentelemetry-genai-span-accounting-when-a-retried-tool-call-double-counts-tokens-across-a-re-parented-span.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1464,
    "python_slice_tokens": 264,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure is not \"tokens are miscounted.\" It is that the *unit of accounting* (a span) and the *unit of work* (an idempotent tool invocation) diverge under retry. OpenTelemetry GenAI conventions attach `gen_ai.usage.input_tokens` / `gen_ai.usage.output_tokens` to the span that *issued* the model call, and tool spans nest beneath the agent span that *decide...",
    "what_was_observed": "A three-step agent (plan → `search_docs` tool → synthesize) hit a 30s tool timeout on `search_docs`. The runtime's retry policy re-issued the call inside a *fresh* agent turn because the planner re-ran to decide whether to retry or fall back. Trace shape on the wire: - Turn A span: `gen_ai.operation.name=chat`, input 1,840 / output 210 tokens. Child: `execute_tool search_docs` (attempt 1) → `error.type=timeout`, no u...",
    "condition_of_validity": "The reconciliation rule holds only when three conditions are jointly true: 1. Each model call emits exactly one span with `gen_ai.usage.*` set, and that span's `status.code` reflects the *model call's* outcome—not the enclosing tool attempt's. A chat span that succeeded must not be marked ERROR because its child tool timed out. 2. Retries carry a stable corr...",
    "decision_boundary": "The instrumentation layer must choose, per retry, between two behaviors and encode the choice in span topology: - **Same-parent retry** (tool re-issued within the same agent turn, no re-plan): emit a new `execute_tool` span as a sibling under the *same* agent span, both sharing `gen_ai.tool.call.id`. Usage lives on the parent chat span only; the tool spans c...",
    "operational_effect": "With the invariant enforced, the budget ceiling query becomes `sum(gen_ai.usage.input_tokens + gen_ai.usage.output_tokens) group by gen_ai.task.id where gen_ai.operation.name=chat`—status-agnostic, retry-agnostic, and stable across re-parenting. Without it, the observed system under-reported spend by 1.9× and let a task exceed its ceiling undetected until a ..."
  },
  "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": "a3120e64ef95a19dfcdc0ee4c5b41cf36fa474a1011f637594971d6b92e7d8d4",
    "verified_classes": [
      "SpanAccountingError",
      "GenAISpan"
    ],
    "verified_functions": [
      "validate_span",
      "reconcile_task_usage"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 6,
    "raised_exceptions": [
      "SpanAccountingError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
