{
  "schema_version": "1.3.0",
  "slug": "how-should-an-instance-reconcile-token-accounting-spans-when-a-genai-tool-call-span-is-emitted-twice-under-retry-once-by-the-client-and-once-by-the-se",
  "title": "How should an instance reconcile token-accounting spans when a GenAI tool-call span is emitted twice under retry, once by the client and once by the server, without double-counting completion tokens?",
  "date_of_record": "2026 November 30",
  "scope": "Applies to agent runtimes that emit OpenTelemetry `gen_ai.*` spans on both the orchestrator (client) side and the tool/LLM server side, where retries can cause the same logical tool call to produce two spans carrying `gen_ai.usage.output_tokens`. Does not apply to single-emitter topologies or to spans that carry only `gen_ai.usage.input_tokens` (which are idempotent under retry because the prompt is re-sent, not regenerated).",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-token-accounting-spans-when-a-genai-tool-call-span-is-emitted-twice-under-retry-once-by-the-client-and-once-by-the-se.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-token-accounting-spans-when-a-genai-tool-call-span-is-emitted-twice-under-retry-once-by-the-client-and-once-by-the-se.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-token-accounting-spans-when-a-genai-tool-call-span-is-emitted-twice-under-retry-once-by-the-client-and-once-by-the-se.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1842,
    "python_slice_tokens": 422,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat `gen_ai.usage.output_tokens` as a *measurement of generation*, not a *measurement of work performed*. When a tool call is retried, the client observes two spans: one from the failed first attempt (which may or may not have generated tokens before the transport error) and one from the successful retry. The server observes ...",
    "what_was_observed": "An agent orchestrator using MCP over a flaky transport executed a `search_corpus` tool call. The tool server generated a 900-token completion and began streaming it back; the client's HTTP read timed out at 3s after receiving 400 tokens. The orchestrator's retry policy (exponential backoff, 2 attempts) re-issued the call. The server, unaware of the first attempt's partial delivery, regenerated from scratch: 880 token...",
    "condition_of_validity": "The deduplication rule \"max per `(trace, call.id)`, sum across distinct `call.id` within a trace\" holds only under these conditions: 1. **Client and server spans for the same attempt share `trace_id` and `span_id` parentage.** If the client emits its span with a fresh trace on retry (common when the retry logic lives above the tracing layer), the two attempt...",
    "decision_boundary": "The reconciler must choose between two aggregation strategies based on whether `app.retry.original_call_id` is present: - **If present:** group all spans sharing `(trace_id, app.retry.original_call_id)`, take the max `output_tokens` among *client* spans and the max among *server* spans per distinct `call.id`, then sum the server-side maxes across distinct `c...",
    "operational_effect": "The practical consequence is that **token accounting for agent tool calls is not a property of the span stream; it is a property of the retry topology that the span stream must be made to encode.** Teams that instrument only the GenAI semantic conventions — which do not define a retry-grouping attribute — will systematically over-count client/server duplicat..."
  },
  "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": "51458cfc64ca78452d02817247319c80bef4f0d846999cd9c80609ae87af8d5f",
    "verified_classes": [
      "TokenReconciliationError",
      "GenAISpan"
    ],
    "verified_functions": [
      "reconcile_output_tokens",
      "attribute_call"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "TokenReconciliationError"
    ],
    "sample_fail_closed_invariants": [
      "no spans supplied for attribution"
    ],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
