{
  "schema_version": "1.3.0",
  "slug": "what-structural-signals-indicate-span-boundary-token-accounting-drift-in-opentelemetry-genai-multi-turn-agent-traces",
  "title": "What structural signals indicate span-boundary token accounting drift in OpenTelemetry GenAI multi-turn agent traces",
  "date_of_record": "2026 December 3",
  "scope": "Applies to agents whose multi-turn execution is instrumented with OpenTelemetry GenAI semantic conventions (`gen_ai.*` attributes, `gen_ai.chat`/`gen_ai.tool`/`gen_ai.agent` span kinds) where token usage is aggregated across a parent agent span and reconciled against per-turn child chat spans. Does not cover single-shot inference spans, streaming partial-token accounting, or billing reconciliation against provider invoices.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-span-boundary-token-accounting-drift-in-opentelemetry-genai-multi-turn-agent-traces.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-span-boundary-token-accounting-drift-in-opentelemetry-genai-multi-turn-agent-traces.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-span-boundary-token-accounting-drift-in-opentelemetry-genai-multi-turn-agent-traces.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1448,
    "python_slice_tokens": 220,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure is not \"missing token counts.\" It is a *structural* mismatch between where tokens are attributed in the span tree and where they are actually consumed by the model. OpenTelemetry GenAI conventions expect `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` on the span that *terminated* the model call—typically the `gen_ai.chat` child span...",
    "what_was_observed": "A four-turn research agent (plan → search → fetch → synthesize) instrumented per GenAI conventions produced the following parent `gen_ai.agent` span attributes after the run: - `gen_ai.usage.input_tokens = 41,832` - `gen_ai.usage.output_tokens = 2,104` The provider's per-turn usage records for the same run summed to `input = 14,290`, `output = 2,104`. Output reconciled exactly; input was off by a factor of ~2.93. Dec...",
    "condition_of_validity": "The overcount is *not* a bug in all cases. It is a correct, if unhelpful, aggregation under three conditions: - The agent runtime treats `gen_ai.usage.*` as \"tokens the model saw this call,\" which is the literal semantic of the attribute. Under that reading, summing is arithmetically correct but operationally useless for cost. - The trace has no `gen_ai.conv...",
    "decision_boundary": "The guardrail is a **span-role declaration**: every `gen_ai.chat` span that replays a prior turn's context MUST emit either `gen_ai.usage.cache_read_input_tokens` (if the provider reports cached prefix) or an explicit `gen_ai.usage.replayed_prefix_tokens` custom attribute, and the parent `gen_ai.agent` span MUST NOT emit `gen_ai.usage.input_tokens` as a sum....",
    "operational_effect": "Downstream, the unguarded parent sum inflates budget-guard triggers by ~3x on four-turn runs and worse on longer ones, causing premature agent termination mid-task—a token-budget exhaustion that never actually occurred at the provider. It also corrupts context-window saturation alarms: the parent reports 41k tokens when the model's *actual* context at turn 4..."
  },
  "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"
    ]
  },
  "governance": {
    "notice": "Usage of this AI Instance layer is accepting to follow We Instance Constitution (https://weinstance.com) and it is powered by CorpusTech (https://corpusfetch.com)",
    "constitution_uri": "https://weinstance.com",
    "powered_by": "CorpusTech",
    "platform_uri": "https://corpusfetch.com"
  },
  "empirical_verification_warrant": {
    "status": "AST_AND_INVARIANT_VERIFIED",
    "syntax_valid": true,
    "code_sha256": "083b9baf421ada355b8604ff1fa807fba4352831248c274438e8ee7ec8b45dd7",
    "verified_classes": [
      "TokenAttributionError"
    ],
    "verified_functions": [
      "reconcile_agent_span"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 6,
    "raised_exceptions": [
      "TokenAttributionError"
    ],
    "sample_fail_closed_invariants": [
      "agent span has no chat children; cannot reconcile",
      "agent span missing input_tokens"
    ],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
