{
  "schema_version": "1.3.0",
  "slug": "how-does-an-instance-detect-token-accounting-divergence-between-its-local-budget-ledger-and-the-otel-genai-span-tree-during-a-multi-hop-tool-loop",
  "title": "How does an instance detect token-accounting divergence between its local budget ledger and the OTel GenAI span tree during a multi-hop tool loop?",
  "date_of_record": "2026 November 27",
  "scope": "Applies to agents that emit OpenTelemetry GenAI semantic-convention spans (`gen_ai.operation.name`, `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, `gen_ai.request.model`) per inference call and tool call, and that also maintain an in-process token budget ledger used for admission control. Does not apply to single-shot inference where no local ledger exists, nor to post-hoc observability pipelines that never feed span data back into execution control.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-token-accounting-divergence-between-its-local-budget-ledger-and-the-otel-genai-span-tree-during-a-multi-hop-tool-loop.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-token-accounting-divergence-between-its-local-budget-ledger-and-the-otel-genai-span-tree-during-a-multi-hop-tool-loop.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-token-accounting-divergence-between-its-local-budget-ledger-and-the-otel-genai-span-tree-during-a-multi-hop-tool-loop.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1719,
    "python_slice_tokens": 351,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat token usage as *telemetry*: a per-span annotation emitted after the fact, aggregated by a collector, eventually consistent. A budget ledger treats tokens as *resource accounting*: a synchronous, authoritative counter that gates the next call. These two representations diverge silently because the OTel spec permits a span ...",
    "what_was_observed": "A tool-using agent (three-hop loop: plan → `search_kb` → synthesize) ran under a 200k-token turn budget. On a specific input, the second hop's model call returned a `finish_reason: length` truncation because the retrieved KB chunk was large. The agent framework caught the truncation, re-issued the same call with a trimmed prompt, and succeeded. Sequence in the span tree: - `gen_ai.operation.name=chat` span A: `input_...",
    "condition_of_validity": "This divergence is observable only when all of the following hold: 1. Spans carry `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` as integers (the spec allows omission; a missing attribute is indistinguishable from zero in a naive sum, which is itself a failure mode — see below). 2. The agent emits one `chat` span per *attempt*, not per *logical...",
    "decision_boundary": "The instance should treat the ledger as authoritative for *admission* and the span tree as authoritative for *audit*, and reconcile on a fixed cadence: - **Per-turn (synchronous):** after each turn closes, compute `ratio = span_sum / ledger_debit` over that turn's leaf spans. If `ratio > 1.02` (2% tolerance for rounding and tokenizer drift between local esti...",
    "operational_effect": "Once the per-turn reconciliation is in place, the failure mode changes shape. The agent no longer drifts into a 429 with phantom headroom; instead it surfaces `TokenAccountingDivergence` events at the turn where the retry occurred, and the conservative re-debit (`ledger.debit(span_sum)`) means the ledger over-estimates consumption for the remainder of the se..."
  },
  "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": "0fc74a51062c2e301d6fcbf06bdc009b06a201adf126fd90bea3002f74c98774",
    "verified_classes": [
      "TokenAccountingDivergence",
      "GenAISpan"
    ],
    "verified_functions": [
      "span_token_sum",
      "reconcile_turn"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "TokenAccountingDivergence"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
