{
  "schema_version": "1.3.0",
  "slug": "what-structural-signals-indicate-a-token-accounting-invariant-violation-at-the-opentelemetry-genai-agent-span-boundary",
  "title": "What structural signals indicate a token-accounting invariant violation at the OpenTelemetry GenAI agent-span boundary",
  "date_of_record": "2026 November 15",
  "scope": "Applies to OpenTelemetry GenAI semantic conventions (`gen_ai.*`) for agent and tool spans where `gen_ai.usage.input_tokens` / `gen_ai.usage.output_tokens` are emitted per span and reconciled against a parent agent invocation. Does not apply to raw provider SDK billing reconciliation or to spans that emit only `gen_ai.usage.total_tokens` without the input/output split.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-a-token-accounting-invariant-violation-at-the-opentelemetry-genai-agent-span-boundary.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-a-token-accounting-invariant-violation-at-the-opentelemetry-genai-agent-span-boundary.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-a-token-accounting-invariant-violation-at-the-opentelemetry-genai-agent-span-boundary.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1468,
    "python_slice_tokens": 318,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The non-obvious boundary is between *sum-of-child token attributes* and *parent agent-span token attributes*. The GenAI conventions treat `gen_ai.usage.*` as attributes of the span that made the model call. When an agent span wraps multiple LLM calls (a ReAct loop, a planner, a multi-step tool chain), the natural implementation is to aggregate child `gen_ai....",
    "what_was_observed": "In a multi-tool agent trace, the following structural signals co-occurred and were diagnostic: 1. **Cardinality mismatch between `gen_ai.operation.name` and usage presence.** The parent span carried `gen_ai.operation.name = \"invoke_agent\"` *and* `gen_ai.usage.input_tokens`, while also having N child spans with `gen_ai.operation.name = \"chat\"` that each carried their own usage. Per the conventions, usage belongs to th...",
    "condition_of_validity": "The invariant holds — parent usage equals a genuine measurement — only when *all* of the following are true: - The parent span performs exactly one inference call and has no `chat` children, **or** - The parent carries no `gen_ai.usage.*` at all and consumers are documented to sum leaf `chat` spans, **or** - The parent carries usage explicitly tagged as aggr...",
    "decision_boundary": "Use the following decision rule when ingesting a trace: - If a span has `gen_ai.usage.input_tokens` **and** has descendant spans with `gen_ai.operation.name = \"chat\"` **and** no aggregate marker → treat the parent usage as *untrusted synthesized*; recompute from leaves. - If two leaf `chat` spans share `gen_ai.request.model` and overlap in time with no disti...",
    "operational_effect": "Consumers that trusted parent usage over-counted cost by 18–40% in the observed traces (tool re-injection plus retry duplication), and context-window guards that read parent `input_tokens` under-counted per-step growth, allowing a step to exceed the model window before the guard fired. The correct operational posture is: **treat leaf `chat` span usage as the..."
  },
  "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": "753ba82a638dc51a1436ac6d58b35a28d0a2b0243d14028fb7e8c1cd493c8cab",
    "verified_classes": [
      "TokenAccountingInvariantError",
      "Span"
    ],
    "verified_functions": [
      "reconcile_agent_usage"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "TokenAccountingInvariantError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
