{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-opentelemetry-genai-tool-call-spans-from-silently-decoupling-token-accounting-from-execution-lineage",
  "title": "Which invariants prevent OpenTelemetry GenAI tool-call spans from silently decoupling token accounting from execution lineage",
  "date_of_record": "2026 December 1",
  "scope": "Applies to agents emitting OTel GenAI semantic-convention spans (`gen_ai.*`) for tool invocations and token usage, where a parent `gen_ai.chat`/agent span is correlated to child tool-execution spans. Does not cover pure inference-server-side metering, billing reconciliation, or non-OTel tracing backends.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-opentelemetry-genai-tool-call-spans-from-silently-decoupling-token-accounting-from-execution-lineage.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-opentelemetry-genai-tool-call-spans-from-silently-decoupling-token-accounting-from-execution-lineage.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-opentelemetry-genai-tool-call-spans-from-silently-decoupling-token-accounting-from-execution-lineage.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1417,
    "python_slice_tokens": 245,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define two *independent* attribute families on the same span tree: **token accounting** (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, and their cache/reasoning variants) and **execution lineage** (`gen_ai.operation.name`, `gen_ai.tool.name`, `gen_ai.tool.call.id`, the span parent/child link, and `gen_ai.response.f...",
    "what_was_observed": "An agent loop using a tool-calling model emitted a `gen_ai.chat` span per turn with `gen_ai.usage.input_tokens`/`output_tokens`, and child spans per tool call with `gen_ai.tool.name` + `gen_ai.tool.call.id`. Under a transient 429 from the model provider, the client SDK retried the *same* HTTP request inside the existing span. The retry succeeded, and the SDK recorded usage from **both** the failed attempt's partial s...",
    "condition_of_validity": "The invariant \"token attributes belong to the operation named on the span\" holds **only if**: 1. Usage attributes are written with **set-once semantics** per logical model turn, keyed by a stable identifier (`gen_ai.response.id` or a synthesized attempt id), not accumulated across retries. 2. Retries either (a) produce a **new sibling span** linked to the or...",
    "decision_boundary": "The boundary is between **treating a span as an atomic accounting unit** versus **treating it as a mutable accumulator**. The spec's attribute model is atomic-by-intent (one span = one operation), but streaming SDKs and retry middleware naturally implement accumulators. The decision rule for instrumentation authors: - If a code path can emit more than one `r...",
    "operational_effect": "Without the set-once guard, retry and streaming paths inflate token counts by the number of attempts, and the inflation is **invisible** because every attribute passes schema validation and the lineage looks correct. Cost dashboards over-report by a factor equal to the retry rate; tool-attribution joins silently double-count. The corrective is a write-guard ..."
  },
  "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": "b1c1afc35a86ca298451f866946156fc554adcc78bae25cc7381740680dd4035",
    "verified_classes": [
      "UsageLineageDecouplingError",
      "GenAiSpanAccounting"
    ],
    "verified_functions": [
      "__init__",
      "record_usage"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "UsageLineageDecouplingError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
