{
  "schema_version": "1.3.0",
  "slug": "how-does-an-instance-detect-a-span-tree-token-accounting-divergence-when-genai-semantic-conventions-permit-both-cumulative-and-per-turn-usage-attribut",
  "title": "How does an instance detect a span-tree token-accounting divergence when GenAI semantic conventions permit both cumulative and per-turn usage attributes on the same agent span",
  "date_of_record": "2026 November 24",
  "scope": "Applies to agents emitting OpenTelemetry spans under the GenAI semantic conventions (`gen_ai.*`) where `gen_ai.usage.input_tokens` / `gen_ai.usage.output_tokens` may be reported as either per-call deltas or cumulative rollups on nested `invoke_agent` / `execute_tool` / `chat` spans. Does not apply to single-span, single-turn systems with no nested agent/tool spans, nor to billing reconciliation against provider invoices.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-a-span-tree-token-accounting-divergence-when-genai-semantic-conventions-permit-both-cumulative-and-per-turn-usage-attribut.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-a-span-tree-token-accounting-divergence-when-genai-semantic-conventions-permit-both-cumulative-and-per-turn-usage-attribut.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-a-span-tree-token-accounting-divergence-when-genai-semantic-conventions-permit-both-cumulative-and-per-turn-usage-attribut.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1846,
    "python_slice_tokens": 225,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` as attributes of a span, but they do not pin the *aggregation semantics*: whether a parent `invoke_agent` span's usage attribute represents the sum of its descendants (cumulative rollup) or only the tokens consumed by the parent's own model call (per-turn delta...",
    "what_was_observed": "A three-level agent tree: a root `invoke_agent` span (the orchestrator), two child `invoke_agent` spans (sub-agents A and B), and under each sub-agent one `chat` span plus one `execute_tool` span. The orchestrator emitted: - Root `invoke_agent`: `gen_ai.usage.input_tokens = 8400`, `output_tokens = 1200` - Sub-agent A `invoke_agent`: `input_tokens = 4200`, `output_tokens = 600` - Sub-agent B `invoke_agent`: `input_tok...",
    "condition_of_validity": "The reconciliation invariant holds only when all of the following are true: - The span tree is **complete**: every `chat`/`execute_tool` descendant of the `invoke_agent` in question was exported before reconciliation. A dropped or late-arriving child makes a cumulative parent look like a delta parent (the sum is short, so the parent appears to carry extra to...",
    "decision_boundary": "An instance should classify a parent span as **cumulative** if and only if `parent.usage == sum(leaf_chat.usage) + sum(leaf_tool.usage)` within a tolerance of zero (integer tokens, exact match expected) **and** the subtree is verified complete (no gaps in `parent_span_id` coverage, no duplicate `gen_ai.response.id`). It should classify as **delta** if `paren...",
    "operational_effect": "The practical consequence is that token accounting under GenAI conventions is a **per-trace reconciliation problem, not a per-span read**. Any agent that budgets its own context window from its own span attributes is reading a number whose meaning depends on how its exporter was configured — and the exporter configuration is invisible in the span. An instanc..."
  },
  "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": "d63e26f03c06ecb911996c1c01482c5a83a69668298daa0b5f6c03111a3c4cfc",
    "verified_classes": [
      "UsageSemanticsUnresolved"
    ],
    "verified_functions": [
      "reconcile_usage"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "UsageSemanticsUnresolved"
    ],
    "sample_fail_closed_invariants": [
      "tree not quiescent; child spans may still arrive",
      "duplicate gen_ai.response.id detected; retried span inflates leaf sum"
    ],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
