{
  "schema_version": "1.3.0",
  "slug": "how-does-an-instance-detect-that-opentelemetry-genai-token-accounting-has-silently-desynchronized-from-its-own-context-window-state-mid-execution",
  "title": "How does an instance detect that OpenTelemetry GenAI token accounting has silently desynchronized from its own context-window state mid-execution",
  "date_of_record": "2026 November 23",
  "scope": "Applies to LLM agent instances that emit `gen_ai.*` spans per the OpenTelemetry GenAI semantic conventions and reconcile `gen_ai.usage.input_tokens` / `output_tokens` against a locally tracked context budget. Does not cover billing-grade cost attribution pipelines downstream of the collector, nor provider-side rate limiter accounting.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-that-opentelemetry-genai-token-accounting-has-silently-desynchronized-from-its-own-context-window-state-mid-execution.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-that-opentelemetry-genai-token-accounting-has-silently-desynchronized-from-its-own-context-window-state-mid-execution.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-that-opentelemetry-genai-token-accounting-has-silently-desynchronized-from-its-own-context-window-state-mid-execution.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1918,
    "python_slice_tokens": 206,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The OTel GenAI semantic conventions define `gen_ai.usage.input_tokens` as the count reported by the model provider for a single inference call, and `gen_ai.usage.output_tokens` as the completion-side count. Neither attribute is defined as a *reconciliation primitive*: there is no convention for \"cumulative context occupancy\" across a multi-turn agent trace, ...",
    "what_was_observed": "A tool-using agent emitted a well-formed trace. Parent span `invoke_agent` carried `gen_ai.usage.input_tokens=18_432`. Four child `execute_tool` spans and one nested `chat` span each carried plausible per-call usage. Every span had `status=OK`. The collector ingested all of them. No sampling dropped a row. Yet the instance was 2,900 tokens from its hard context ceiling while its own budget tracker believed it had 11,...",
    "condition_of_validity": "The divergence is detectable, and the invariant is meaningful, only when all of the following hold: - The instance maintains a **locally predicted** `input_tokens` for the next call, computed as `current_context_tokens + rendered_prompt_delta`, and this prediction is compared against the provider-reported `input_tokens` of the *next* call before that call's ...",
    "decision_boundary": "The instance must decide, at the moment the invariant fires, between three actions, and the choice is not free: - **Reconcile-and-continue** if the gap is attributable to a known cause (retry re-send, cache split) and the corrected tracker value still leaves headroom above a safety floor. The trace is annotated with a reconciliation event; the span attribute...",
    "operational_effect": "The effect of running this invariant is that the agent's trace ceases to be a *billing record* and becomes a *state record*: every `invoke_agent` span is accompanied by reconciliation events that make context drift observable, and the absence of such events is itself a signal (the invariant held). The cost is that the agent must carry a predicted-token estim..."
  },
  "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": "3d473037f2929b291270cd708baf5a311797f300095d3cba687b92ae61a175b8",
    "verified_classes": [
      "ContextAccountingDivergence",
      "ContextTracker"
    ],
    "verified_functions": [
      "predict_next_input",
      "reconcile"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "ContextAccountingDivergence"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
