{
  "schema_version": "1.3.0",
  "slug": "when-must-an-instance-reconcile-opentelemetry-genai-semantic-convention-spans-against-its-own-loop-counter-before-exporting-cost-attribution",
  "title": "When must an instance reconcile OpenTelemetry GenAI semantic-convention spans against its own loop counter before exporting cost attribution?",
  "date_of_record": "2026 November 25",
  "scope": "Applies to agent runtimes that emit OpenTelemetry `gen_ai.*` spans (per-LLM-call and per-tool-call) and derive cost attribution from `gen_ai.usage.input_tokens` / `gen_ai.usage.output_tokens` on span end. Does not cover batch/offline cost reconciliation, nor providers that return authoritative per-request billing via a separate ledger API.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/when-must-an-instance-reconcile-opentelemetry-genai-semantic-convention-spans-against-its-own-loop-counter-before-exporting-cost-attribution.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-reconcile-opentelemetry-genai-semantic-convention-spans-against-its-own-loop-counter-before-exporting-cost-attribution.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-reconcile-opentelemetry-genai-semantic-convention-spans-against-its-own-loop-counter-before-exporting-cost-attribution.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1452,
    "python_slice_tokens": 375,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "There are two independent notions of \"how much did this agent loop consume\": the **loop counter** (the runtime's own monotonic tally of LLM invocations and tool calls it has issued) and the **span ledger** (the set of `gen_ai.*` spans that actually reached the exporter and were accepted by the collector). These diverge under retries, span-drop-on-shutdown, s...",
    "what_was_observed": "A tool-using agent loop emitted one `gen_ai.chat` span per LLM call and one `gen_ai.execute_tool` span per tool invocation. Cost was attributed by summing `gen_ai.usage.input_tokens`/`output_tokens` across ended `gen_ai.chat` spans and multiplying by a per-model rate table. Three distinct divergence modes were observed: 1. **Retry shadowing.** The LLM client retried a transient 429 internally. The retry produced a *s...",
    "condition_of_validity": "Cost attribution derived from `gen_ai.*` spans is valid **only if all of the following hold at loop termination**: - `span_ledger.ended_chat_span_count` equals the loop counter's LLM-call count, **or** the delta is explicitly recorded with a reason (`in_flight`, `dropped_on_shutdown`, `sampled_out`). - The sampler is either disabled for the cost-bearing span...",
    "decision_boundary": "The decision point is at **span end / loop termination**, not at span start: - **Reconcile-then-export** (default): at loop termination, compare `ledger_count` to `loop_counter`; if unequal and the delta is unexplained, emit the marker and refuse to publish a \"final\" cost total. Publish a *lower bound* plus the delta. - **Export-with-provenance**: if the del...",
    "operational_effect": "Without this reconciliation, cost attribution is a **lower bound that presents as an exact figure** — the worst failure class for billing and budget enforcement, because it fails silently and biases consistently downward (under-attribution), so budget alarms never fire until the provider invoice arrives. With the invariant enforced, the exporter either produ..."
  },
  "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": "a5874bfe1740d722421954ad9bd53bdcd59ac77db790f0784efb950ee9a8895d",
    "verified_classes": [
      "CostAttributionInvariantError",
      "LoopCounter",
      "SpanLedger"
    ],
    "verified_functions": [
      "reconcile_and_attribute"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "CostAttributionInvariantError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
