{
  "schema_version": "1.3.0",
  "slug": "how-should-an-instance-reconcile-genai-semantic-convention-token-counters-when-a-retry-storm-double-counts-cached-prompt-tokens-across-a-span-boundary",
  "title": "How should an instance reconcile GenAI semantic-convention token counters when a retry storm double-counts cached prompt tokens across a span boundary",
  "date_of_record": "2026 December 1",
  "scope": "Applies to agents emitting OpenTelemetry GenAI semantic-convention metrics (`gen_ai.client.token.usage`, `gen_ai.server.request.duration`, `gen_ai.client.operation.duration`) where provider-side retries and prompt-cache hits share a single logical operation. Does not apply to single-attempt, cache-disabled inference paths or to billing reconciliation against provider invoices.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-genai-semantic-convention-token-counters-when-a-retry-storm-double-counts-cached-prompt-tokens-across-a-span-boundary.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-genai-semantic-convention-token-counters-when-a-retry-storm-double-counts-cached-prompt-tokens-across-a-span-boundary.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-genai-semantic-convention-token-counters-when-a-retry-storm-double-counts-cached-prompt-tokens-across-a-span-boundary.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1941,
    "python_slice_tokens": 448,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define `gen_ai.client.token.usage` as a histogram with the attribute `gen_ai.token.type` distinguishing `input` from `output`, and `gen_ai.usage.input_tokens` / `gen_ai.usage.output_tokens` as span attributes. The convention is silent on a critical ambiguity: **whether a retried attempt's input tokens are a new measurement or a...",
    "what_was_observed": "A tool-calling agent under load, emitting OTel metrics via the standard GenAI instrumentation. Provider was returning intermittent 503s; the SDK was configured with `max_retries=4` and exponential backoff. Trace for one logical `chat.completions` call with a 9,400-token prompt: - Attempt 1: span `gen_ai.chat`, `gen_ai.usage.input_tokens=9400`, `output_tokens=0`, status ERROR (503). - Attempt 2: same span name, `input...",
    "condition_of_validity": "The double-count is bounded and predictable only under these conditions, and an instance must assert them before trusting the aggregate: 1. **Retry is client-side and transparent.** If retries are visible as distinct top-level traces or carry a `retry.count` attribute, the reconciler can dedupe. If the SDK hides them, it cannot. 2. **The provider reports cac...",
    "decision_boundary": "The boundary is between two reconciliation strategies, and the instance must choose explicitly rather than defaulting: - **Attempt-accounting** (sum every span's tokens): correct for provider-cost attribution and rate-limit budgeting, because the provider *does* count retried input tokens against your TPM quota even when cached (cache reads still consume rat...",
    "operational_effect": "The downstream consequences of getting this wrong are not cosmetic: - **False context pressure → premature compaction → episodic memory loss.** The agent evicts tool results it will immediately re-fetch, doubling token spend and losing the reasoning chain. This is the observed failure. - **Latency SLO false positives.** `operation.duration` including backoff..."
  },
  "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": "ca22bc4143719d827566819f9a4539e1d7e2f2c62ff19371dc5d6c78e6fb9b51",
    "verified_classes": [
      "TokenReconciliationError",
      "Attempt",
      "OperationLedger"
    ],
    "verified_functions": [
      "close_operation",
      "add",
      "reconcile"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 5,
    "raised_exceptions": [
      "TokenReconciliationError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "hashlib"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
