{
  "schema_version": "1.3.0",
  "slug": "what-structural-signals-indicate-token-usage-accounting-has-silently-diverged-from-span-topology-in-opentelemetry-genai-agent-traces",
  "title": "What structural signals indicate token-usage accounting has silently diverged from span topology in OpenTelemetry GenAI agent traces",
  "date_of_record": "2026 December 1",
  "scope": "Applies to agent runtimes that emit OTel GenAI semantic conventions (`gen_ai.*`) across nested agent → tool → sub-agent spans, where token usage is aggregated from per-span attributes into a parent metric. Does not cover single-span inference calls with no tool nesting, nor traces where usage is sourced from a single upstream billing API rather than span attributes.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-token-usage-accounting-has-silently-diverged-from-span-topology-in-opentelemetry-genai-agent-traces.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-token-usage-accounting-has-silently-diverged-from-span-topology-in-opentelemetry-genai-agent-traces.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-token-usage-accounting-has-silently-diverged-from-span-topology-in-opentelemetry-genai-agent-traces.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1740,
    "python_slice_tokens": 432,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define token-usage as *attributes on the span that produced the tokens* (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, typically on the `gen_ai.chat` / `gen_ai.invoke_agent` span). They do **not** define a parent-child rollup contract. This means two different things can both be \"correct\" according to the spec yet ...",
    "what_was_observed": "A multi-step agent (planner → 3 tool calls → synthesizer) emitted the following span tree under one `gen_ai.invoke_agent` root: Topological sum: input = 5300, output = 860. The provider's billing block for the same `invoke_agent` turn: input = 12,900, output = 2,050. The delta (7600 / 1190) came from **internal tool-result ingestion turns** the runtime folded into the synthesizer's context window but never emitted as...",
    "condition_of_validity": "The invariant \"sum of descendant `gen_ai.usage.*` equals the provider's billed usage for the turn\" holds **only if** every model invocation that consumes billable tokens is represented as a distinct span carrying usage attributes. It is violated whenever: - The runtime performs **hidden re-invocations** (tool-result ingestion, retries, self-critique passes) ...",
    "decision_boundary": "The boundary between \"acceptable trace\" and \"diverged trace\" is whether the **topology can reconstruct the billing tree**. Concretely: - **Accept** a trace as accounting-valid when every `gen_ai.chat` / `gen_ai.invoke_agent` span with non-zero output tokens has a corresponding provider-side turn, and the count of such spans equals the count of billed turns. ...",
    "operational_effect": "When the invariant is unenforced: - **Cost attribution drifts silently.** Per-agent cost dashboards built from span aggregation under-report by the hidden-turn fraction, which grows with tool-call depth. A planner with 3 tools and 2 synthesis passes can under-report by 40–60% while every individual span looks clean. - **Latency/usage correlation breaks.** Th..."
  },
  "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": "04cf33a3aaf5b7f109662c42c031c2d5dc4710db1eec0c3b2001e4afacf5ee07",
    "verified_classes": [
      "UsageTopologyDivergence",
      "Span"
    ],
    "verified_functions": [
      "usage_bearing",
      "validate_usage_topology",
      "walk"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "UsageTopologyDivergence"
    ],
    "sample_fail_closed_invariants": [
      "usage.total_tokens disagrees with input+output on parent span"
    ],
    "stdlib_dependencies": [
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
