{
  "schema_version": "1.3.0",
  "slug": "what-structural-signals-indicate-opentelemetry-genai-span-graphs-are-silently-mis-accounting-tokens-at-tool-call-boundaries",
  "title": "What structural signals indicate OpenTelemetry GenAI span graphs are silently mis-accounting tokens at tool-call boundaries",
  "date_of_record": "2026 November 29",
  "scope": "Applies to agent runtimes that emit OpenTelemetry GenAI semantic-convention spans (`gen_ai.*`) per LLM turn and per tool invocation, where per-turn token usage is summed across a turn graph to derive cost or budget. Does not apply to single-shot, single-span inference calls that never fan out into tool-call sub-spans.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-opentelemetry-genai-span-graphs-are-silently-mis-accounting-tokens-at-tool-call-boundaries.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-opentelemetry-genai-span-graphs-are-silently-mis-accounting-tokens-at-tool-call-boundaries.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-opentelemetry-genai-span-graphs-are-silently-mis-accounting-tokens-at-tool-call-boundaries.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1630,
    "python_slice_tokens": 357,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat a *turn* as an inference span (`gen_ai.operation.name = \"chat\"`) carrying `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens`, and a *tool call* as a child span (`gen_ai.operation.name = \"execute_tool\"`) with its own attributes. The convention is silent on a critical invariant: **the input tokens of turn N+1 are ...",
    "what_was_observed": "A three-turn agent loop (one tool call per turn) emitting conformant spans. Each span reported honest usage: - Turn 1 chat span: `input_tokens=1200`, `output_tokens=180` (the tool-call request). - Tool span: no token attributes (correct—tools don't bill tokens). - Turn 2 chat span: `input_tokens=1540`, `output_tokens=150`. - Turn 3 chat span: `input_tokens=1810`, `output_tokens=90`. A naive collector summing `input_t...",
    "condition_of_validity": "The naive sum is only valid under a condition that almost never holds in agent loops: **stateless, non-accumulating prompting**, where each turn sends a fresh, disjoint prompt. The moment the harness appends conversation history (every real agent), the sum-over-spans invariant is violated. The correct invariant is: > cumulative_input_tokens = input_tokens of...",
    "decision_boundary": "The boundary between \"trustworthy aggregate\" and \"silently wrong aggregate\" is crossed at the first tool-call fan-out combined with history accumulation. Operationally, an agent or auditor must decide per turn-graph: - **If** all chat spans in the chain share a common `gen_ai.conversation.id` / trace and the harness is append-only **then** use terminal-span ...",
    "operational_effect": "Without this check, two failure modes emerge. First, **budget-guard thrash**: an agent enforcing a per-task token cap on the naive sum halts at ~40% of true budget, aborting healthy runs mid-task and leaving checkpoint/resume state inconsistent with the recorded spend. Second, **compaction blind spots**: agents that trust terminal-span input as cumulative un..."
  },
  "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": "26cdae70f045fbbaeded9e5e1d41eb05c1ce951a889918db7d560ba6d3772a55",
    "verified_classes": [
      "TokenConservationError",
      "ChatSpan",
      "ToolSpan"
    ],
    "verified_functions": [
      "reconstruct_cumulative"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "TokenConservationError"
    ],
    "sample_fail_closed_invariants": [
      "empty turn chain: no chat spans to account"
    ],
    "stdlib_dependencies": [
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
