{
  "schema_version": "1.3.0",
  "slug": "in-what-scenarios-must-an-instance-treat-per-turn-token-accounting-as-non-additive-across-trace-spans-in-genai-observability-pipelines",
  "title": "In what scenarios must an instance treat per-turn token accounting as non-additive across trace spans in GenAI observability pipelines",
  "date_of_record": "2026 November 15",
  "scope": "Applies to observability pipelines that reconstruct per-agent-turn cost and safety attribution by summing token counts across child spans of a single trace root, where the LLM client (SDK, gateway, or proxy) emits usage records at more than one layer. Does not apply to pipelines that ingest a single authoritative usage event per turn from a billing-grade source (e.g., provider-side usage API keyed to a request ID), nor to single-span traces.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-treat-per-turn-token-accounting-as-non-additive-across-trace-spans-in-genai-observability-pipelines.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-treat-per-turn-token-accounting-as-non-additive-across-trace-spans-in-genai-observability-pipelines.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-treat-per-turn-token-accounting-as-non-additive-across-trace-spans-in-genai-observability-pipelines.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1894,
    "python_slice_tokens": 388,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The naive mental model is that a trace is a tree of spans, each span reports `input_tokens` and `output_tokens`, and the per-turn cost is the root-to-leaf sum. This holds only when exactly one layer in the call stack owns the tokenizer accounting and all other layers pass through usage verbatim or omit it. The failure boundary is the **double-counting invari...",
    "what_was_observed": "In a pipeline correlating three signal classes per turn — (1) trace spans with usage attributes, (2) a token-economics rollup table keyed by `turn_id`, and (3) safety-signal events emitted by a guardrail sidecar tagged with `turn_id` and `span_id` — the following divergence appeared under load: - **Sum-of-spans exceeded provider invoice by 1.6× to 2.3×** on turns routed through the LLM gateway, because the gateway em...",
    "condition_of_validity": "The additive-sum reconstruction is valid when all of the following hold for a given turn: 1. Exactly one span in the turn's subtree carries a usage record, **or** all usage-bearing spans are declared, via an explicit `usage_authority` attribute, to be non-overlapping partitions of the request (e.g., a fan-out to N models where each child is a distinct billab...",
    "decision_boundary": "The operational rule is a **precedence function over usage-bearing spans**, not a fold: - If a span declares `usage_authority=exclusive`, it wins and all other usage on the subtree is recorded as `shadow_usage` (retained for reconciliation, excluded from cost). - If no span declares authority, prefer the span whose transport observed the terminal byte of the...",
    "operational_effect": "After enforcing authority selection: gateway-routed invoice reconciliation converged to within 0.4% (residual attributable to provider-side rounding on cached-input tokens). Safety-event orphan rate on gateway traffic dropped from ~40% to 0.1%, with the remainder traced to spans dropped by the collector's tail-sampling policy — a separate, now-visible defect..."
  },
  "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": "479e6d31c416e749ec385f0335155db9872bc2fd9a3c24abf4b16a07bdfb12c0",
    "verified_classes": [
      "AmbiguousUsageAuthorityError",
      "Authority",
      "UsageSpan",
      "TurnCost"
    ],
    "verified_functions": [
      "resolve_turn_cost",
      "total"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "AmbiguousUsageAuthorityError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "__future__",
      "dataclasses",
      "enum",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
