{
  "schema_version": "1.3.0",
  "slug": "what-structural-signals-indicate-token-accounting-divergence-between-opentelemetry-genai-span-attributes-and-the-agent-s-own-usage-ledger",
  "title": "What structural signals indicate token-accounting divergence between OpenTelemetry GenAI span attributes and the agent's own usage ledger",
  "date_of_record": "2026 November 23",
  "scope": "Applies to agents that emit OpenTelemetry spans following the GenAI semantic conventions (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, `gen_ai.operation.name`, `gen_ai.tool.name`) while also maintaining an internal token budget ledger for cost control or context-window management. Does not apply to systems that treat OTel spans as the sole source of truth for token accounting, nor to pure tracing without budget enforcement.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-token-accounting-divergence-between-opentelemetry-genai-span-attributes-and-the-agent-s-own-usage-ledger.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-token-accounting-divergence-between-opentelemetry-genai-span-attributes-and-the-agent-s-own-usage-ledger.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-token-accounting-divergence-between-opentelemetry-genai-span-attributes-and-the-agent-s-own-usage-ledger.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1740,
    "python_slice_tokens": 429,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The confusion this record resolves is between *observability token counts* and *enforcement token counts*. The OpenTelemetry GenAI semantic conventions define `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` as attributes on the span that *reports* a model invocation. The agent's budget ledger, by contrast, is a mutable counter that gates whether...",
    "what_was_observed": "A tool-using agent emitted a parent span `gen_ai.operation.name=chat` with three child spans for tool calls, each child carrying its own `gen_ai.usage` attributes (because the tool invocation triggered an internal LLM call for argument synthesis). The parent span's `gen_ai.usage.input_tokens` was set to the *final* request's prompt tokens only—the orchestrator overwrote the attribute on each retry rather than accumul...",
    "condition_of_validity": "The equality invariant `Σ span.gen_ai.usage == ledger.debit` is valid **only** when all of the following hold: - The span is emitted exactly once per billable model call, with no retry collapsing and no fallback re-emission. - Usage attributes are *accumulated* on the parent from children, not overwritten. - The tokenizer used to populate `gen_ai.usage.*` is...",
    "decision_boundary": "The decision boundary is whether to treat OTel GenAI spans as **authoritative** or **advisory** for enforcement. The rule this record establishes: - **Advisory (default):** spans are for observability, cost attribution, and post-hoc reconciliation. The ledger is authoritative and is debited at call initiation with a conservative pre-estimate, then reconciled...",
    "operational_effect": "The operational consequence of getting this wrong is a **monotonic budget drift** that is invisible in dashboards because both the span aggregate and the ledger look internally consistent—they just disagree with each other, and the disagreement grows with retry rate and streaming abort rate. Agents that enforce on span aggregates overspend precisely when the..."
  },
  "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": "fbb91a010c56615197f90c784d5dafc4b888a97cd59c46a284105b0d5337ef20",
    "verified_classes": [
      "TokenAccountingDivergence",
      "SpanUsage",
      "LedgerEntry"
    ],
    "verified_functions": [
      "reconcile_span_to_ledger"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 5,
    "raised_exceptions": [
      "TokenAccountingDivergence"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
