{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-token-accounting-drift-from-silently-corrupting-agent-span-trees-under-opentelemetry-genai-semantic-conventions",
  "title": "Which invariants prevent token-accounting drift from silently corrupting agent span trees under OpenTelemetry GenAI semantic conventions",
  "date_of_record": "2026 November 28",
  "scope": "Applies to any agent runtime that emits OpenTelemetry spans conforming to the GenAI semantic conventions (`gen_ai.*`) for chat, tool, and agent-invocation operations, where a single logical turn fans out into nested spans across multiple model calls and tool executions. Does not cover single-span inference logging, nor telemetry pipelines that recompute token counts downstream from raw completions rather than trusting span attributes.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-token-accounting-drift-from-silently-corrupting-agent-span-trees-under-opentelemetry-genai-semantic-conventions.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-token-accounting-drift-from-silently-corrupting-agent-span-trees-under-opentelemetry-genai-semantic-conventions.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-token-accounting-drift-from-silently-corrupting-agent-span-trees-under-opentelemetry-genai-semantic-conventions.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2230,
    "python_slice_tokens": 460,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` as *per-span* attributes describing the usage of *that specific model invocation*. They are not, and were never specified to be, additive across a span tree. The failure mode this record isolates is the conflation of these two readings: an agent turn whose paren...",
    "what_was_observed": "A three-step agent turn (plan → tool call → synthesize) produced the following span tree, with `gen_ai.usage` attributes as emitted: Three separate accounting errors appeared in the collector's rollup: 1. **Retry double-count.** The collector's `sum(gen_ai.usage.input_tokens)` over the subtree returned `1800+4100+4100+5900 = 15_900`. But span `b4` was a rate-limited retry whose prompt was transmitted, billed by the p...",
    "condition_of_validity": "The naive `sum()` rollup is valid *only* when all of the following hold simultaneously: - No span in the subtree is a retry, speculative branch, or aborted call (i.e., every GenAI leaf contributed exactly one request/response to the committed output). - No GenAI span's `input_tokens` includes content sourced from a sibling non-GenAI span (retrieval, tool out...",
    "decision_boundary": "The boundary is between **transmission accounting** and **contribution accounting**, and it must be decided at span-emission time, not at collector time, because the collector cannot reconstruct the distinction from the attributes the convention mandates. Concretely: - If a span represents a request that was *transmitted and billed* but whose response was *d...",
    "operational_effect": "The downstream effect is a class of silent cost-and-behavior mismeasurement that survives every consistency check because the arithmetic is correct and only the *referents* are wrong. Three concrete consequences observed: - **Budget enforcement drift.** A per-turn token budget computed from the rollup overcounts retried turns, causing the agent to throttle i..."
  },
  "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": "0ec2c3c63bda4d0dd5bd0dea5a93d76ebae185659fb3c928469757c6bfc20990",
    "verified_classes": [
      "TokenAccountingError",
      "AccountingMode",
      "GenAISpan"
    ],
    "verified_functions": [
      "rollup_tokens",
      "_walk",
      "visit"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "TokenAccountingError"
    ],
    "sample_fail_closed_invariants": [
      "contributed tokens exceed transmitted tokens; accounting modes have been inverted or a discarded span leaked into the ro"
    ],
    "stdlib_dependencies": [
      "dataclasses",
      "enum",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
