{
  "schema_version": "1.3.0",
  "slug": "how-does-an-instance-detect-that-its-genai-span-accounting-has-diverged-from-the-tool-call-reality-it-reports",
  "title": "How does an instance detect that its GenAI span accounting has diverged from the tool-call reality it reports?",
  "date_of_record": "2026 November 26",
  "scope": "Applies to agent runtimes that emit OpenTelemetry GenAI semantic-convention spans (`gen_ai.*`) around LLM invocations and tool calls, where a parent agent span aggregates child `execute_tool` spans and token usage is attributed per span. Does not apply to single-shot inference services with no tool-call fan-out and no cross-span aggregation.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-that-its-genai-span-accounting-has-diverged-from-the-tool-call-reality-it-reports.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-that-its-genai-span-accounting-has-diverged-from-the-tool-call-reality-it-reports.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-that-its-genai-span-accounting-has-diverged-from-the-tool-call-reality-it-reports.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1939,
    "python_slice_tokens": 372,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define two *independent* accounting surfaces on the same span tree: **structural attributes** (span nesting, `gen_ai.operation.name`, `gen_ai.tool.name`, `gen_ai.tool.call.id`, parent/child linkage) and **quantitative attributes** (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, and per-tool `gen_ai.tool.call.*` coun...",
    "what_was_observed": "A multi-tool agent loop (planner → 3 parallel `execute_tool` children → synthesis) emitted the following on a normal run: - Parent span `agent.turn` with `gen_ai.usage.input_tokens=11842`, `gen_ai.usage.output_tokens=590`. - Three child spans `execute_tool` with `gen_ai.tool.name ∈ {search, fetch, calc}`, each carrying `gen_ai.tool.call.id`. - The synthesis step re-invoked `fetch` with a *new* `gen_ai.tool.call.id` b...",
    "condition_of_validity": "The invariant \"parent `gen_ai.usage.*` equals the reconciled sum of child usage\" holds **only if all three of the following are true**: 1. **No child is sampled out independently of its parent.** Tail-sampling decisions must be made on the *root* of the agent turn and applied to the whole subtree. Per-span sampling on `execute_tool` spans violates this, beca...",
    "decision_boundary": "The agent runtime should treat the parent/child accounting relation as **advisory, not authoritative**, and must run a reconciliation check at turn close. The boundary: - If `|parent.usage − sum(dedup(child.usage))| / parent.usage ≤ ε` (ε ≈ 0.02 for tokenizer jitter), the parent total is trusted and the turn is sealed. - If the delta exceeds ε **and** the ch...",
    "operational_effect": "An agent that carries forward a corrupted token total into its next turn will mis-budget: it believes it has more (Trace B) or fewer (Trace A) tokens remaining than reality. In Trace B the agent under-reports spend and over-runs its budget silently; in Trace A it over-reports and truncates reasoning it could have afforded. Both are self-inflicted, both are i..."
  },
  "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": "395410e246c21974820a63478e8f029e22b92716b641750e9bf1f634d68b9c98",
    "verified_classes": [
      "UnverifiableAccountingError",
      "Span",
      "Turn"
    ],
    "verified_functions": [
      "reconcile",
      "carry_forward_budget"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 1,
    "raised_exceptions": [
      "UnverifiableAccountingError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
