{
  "schema_version": "1.3.0",
  "slug": "when-must-an-instance-re-derive-cost-attribution-from-raw-token-events-because-otel-genai-span-attributes-are-lossy-across-a-retry-boundary",
  "title": "When must an instance re-derive cost attribution from raw token events because OTel GenAI span attributes are lossy across a retry boundary",
  "date_of_record": "2026 November 23",
  "scope": "Applies to agent runtimes that emit OpenTelemetry GenAI semantic conventions (`gen_ai.*` span attributes and `gen_ai.tool.call` / token-usage events) and reconcile those telemetry records against a billing or quota ledger after a mid-call retry, fallback, or provider failover. Does not apply to single-shot, non-retried LLM calls where one span maps one-to-one to one provider response.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/when-must-an-instance-re-derive-cost-attribution-from-raw-token-events-because-otel-genai-span-attributes-are-lossy-across-a-retry-boundary.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-re-derive-cost-attribution-from-raw-token-events-because-otel-genai-span-attributes-are-lossy-across-a-retry-boundary.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-re-derive-cost-attribution-from-raw-token-events-because-otel-genai-span-attributes-are-lossy-across-a-retry-boundary.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2064,
    "python_slice_tokens": 288,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions were designed to describe *a model interaction*, not *a billing transaction*. A span attribute such as `gen_ai.usage.input_tokens` is an observation of the tokens the provider reported for that one response; it is not a ledger entry, and it carries no field that says \"this response was billed.\" When an agent retries a tool call...",
    "what_was_observed": "An agent executing a multi-tool task issued a `gen_ai.tool.call` span for a retrieval tool, then a chat span to a primary provider. The primary provider returned HTTP 429 after streaming 1,842 prompt tokens had already been consumed server-side (the provider bills prompt tokens on a rate-limited request that reached inference). The runtime's retry layer caught the 429, waited, and re-issued the identical chat request...",
    "condition_of_validity": "The invariant \"sum of `gen_ai.usage.*` over `OK` spans equals billed tokens\" holds **only if** every billed provider request corresponds to exactly one span and every non-billed request corresponds to zero spans. This is violated whenever any of the following is true: - A request reaches provider inference but the response is not accepted (429, 5xx after pro...",
    "decision_boundary": "An instance must **re-derive cost from raw token events plus request-lifecycle evidence** — not from span-attribute sums — when the following predicate holds: > The runtime's retry/fallback layer can emit more than one provider request per logical agent step, **and** any provider in the path bills on request-received rather than response-delivered. When that...",
    "operational_effect": "Without the re-derivation, three concrete degradations occur: 1. **Quota drift.** Per-tenant token quotas computed from `OK`-span sums drift monotonically below actual consumption on any tenant whose traffic hits rate limits. The drift is proportional to the 429 rate, so it is invisible in low-traffic testing and appears as a sudden overage in production und..."
  },
  "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": "d9700d66eafa351f78e82524d0a6992bc5033a0adba5089650b40d8083efc59b",
    "verified_classes": [
      "CostAttributionDivergence"
    ],
    "verified_functions": [
      "attribute_cost_from_spans"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "CostAttributionDivergence"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
