{
  "schema_version": "1.3.0",
  "slug": "how-should-an-instance-attribute-token-cost-across-an-otel-span-tree-when-a-single-llm-call-is-re-emitted-by-a-retry-a-fan-out-and-a-memory-write-side",
  "title": "How should an instance attribute token cost across an OTel span tree when a single LLM call is re-emitted by a retry, a fan-out, and a memory-write side effect — and what breaks when it does",
  "date_of_record": "2026 December 2",
  "scope": "Applies to OpenTelemetry-instrumented agent runtimes where LLM calls, tool invocations, and memory operations emit spans with `gen_ai.usage.*` (or equivalent token counters) and where a cost attributor reconciles those spans into per-agent, per-tool, and per-memory-operation ledgers. Does not apply to single-shot inference with no retries, no fan-out, and no downstream memory writes.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-should-an-instance-attribute-token-cost-across-an-otel-span-tree-when-a-single-llm-call-is-re-emitted-by-a-retry-a-fan-out-and-a-memory-write-side.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-attribute-token-cost-across-an-otel-span-tree-when-a-single-llm-call-is-re-emitted-by-a-retry-a-fan-out-and-a-memory-write-side.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-attribute-token-cost-across-an-otel-span-tree-when-a-single-llm-call-is-re-emitted-by-a-retry-a-fan-out-and-a-memory-write-side.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2230,
    "python_slice_tokens": 444,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "There are two distinct quantities that OTel-based GenAI observability conflates under the label \"cost\": **emitted token usage** (what the provider billed for a given request attempt) and **attributed token usage** (what the ledger assigns to a logical agent/tool/memory node). In a clean trace these are equal. The boundary failure is that they are *not* equal...",
    "what_was_observed": "A three-agent pipeline (planner → executor → auditor) with a retrieval memory tool and a post-task distillation step. Each LLM call emitted a span with `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, and a `gen_ai.request.attempt` attribute set by the SDK's retry middleware. The attributor walked the span tree and summed `usage.*` per `agent.id` and per `tool.name`. During a provider incident, the executor...",
    "condition_of_validity": "Attribution is only correct under the following conjunction, and any single violation produces ledger drift: 1. **Attempt deduplication.** Every retry span is a child of a single logical-operation span, and the logical span carries a stable `logical.op.id`. The attributor must sum usage across attempts *only if* the provider bills per attempt (it usually doe...",
    "decision_boundary": "The attributor must choose, per span, between **summing** (treat as independent billable event) and **collapsing** (treat as redundant attempt of an already-counted operation). The boundary is not \"is this a retry\" but \"did this attempt incur provider-side billing.\" The only reliable signal is a transport-layer attestation, because: - `gen_ai.request.attempt...",
    "operational_effect": "The practical consequence is that per-agent cost attribution in an OTel GenAI pipeline is a **batch reconciliation problem over closed traces, not a streaming aggregation over spans**. Any design that reduces cost in the collector as spans arrive will misattribute retries and fan-out because the owner link and cancellation markers are forward references. The..."
  },
  "matched_failure_symptoms": [
    "OOM_KILL_OR_MEMORY_EXHAUSTION"
  ],
  "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": "52d13630e942fcc87f69a8f2ff38c47a8a8689b1b375ecd051e94ca0a69bc511",
    "verified_classes": [
      "AttributionInvariantError",
      "Span",
      "Ledger"
    ],
    "verified_functions": [
      "reconcile"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 1,
    "raised_exceptions": [
      "AttributionInvariantError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
