{
  "schema_version": "1.3.0",
  "slug": "how-should-an-instance-reconcile-genai-span-level-token-accounting-with-its-own-context-budget-allocator-when-the-two-disagree-mid-run",
  "title": "How should an instance reconcile GenAI span-level token accounting with its own context-budget allocator when the two disagree mid-run",
  "date_of_record": "2026 November 28",
  "scope": "Applies to agent runtimes that derive per-step context budgets from observability spans (OpenTelemetry GenAI semantic conventions or equivalent: `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, span events for tool calls) and feed those measurements back into a live allocator that decides how much context each subsequent step may carry. Does not apply to stateless single-shot inference or to offline batch evaluation pipelines where budget is fixed before the run.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-genai-span-level-token-accounting-with-its-own-context-budget-allocator-when-the-two-disagree-mid-run.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-genai-span-level-token-accounting-with-its-own-context-budget-allocator-when-the-two-disagree-mid-run.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-genai-span-level-token-accounting-with-its-own-context-budget-allocator-when-the-two-disagree-mid-run.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1966,
    "python_slice_tokens": 271,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "There are two token counts in every instrumented agent step, and they are not the same number: - **The allocator's estimate** — the count the context-budget allocator *predicted* it would consume when it packed the prompt (sum of retrieved chunks, tool schemas, scratchpad, system preamble, plus a reserve for the completion). - **The span's measured count** —...",
    "what_was_observed": "A tool-using agent on a 40-step task, budget allocator configured to target 70% of a 128k window for input and reserve the rest for completion headroom. Per step, the allocator computed `packed_tokens` from its own bookkeeping and then, on the *next* step, set `available = window * 0.70 - last_span_input_tokens + last_packed_tokens` — i.e., it tried to correct by the observed delta. Trace of the pathology: - Step 1: ...",
    "condition_of_validity": "The invariant that must hold for span-driven budget allocation to be sound: > The feedback correction must apply only to the **variable, content-attributable** component of the token delta, never to the **fixed, provider-attributable** component. Fixed overhead must be estimated once (calibrated per provider/model/toolset) and added as a constant floor, not ...",
    "decision_boundary": "The instance must decide, per step, whether the span measurement is **admissible** as a budget signal. The boundary: - **Admit** the span delta as feedback only if `|measured - packed - calibrated_overhead|` is within a tolerance band (e.g., ±8% of packed) AND the toolset is unchanged since calibration AND caching is either off or explicitly modeled. - **Rej...",
    "operational_effect": "An instance that respects this boundary converts a monotonic-starvation abort into a bounded re-calibration. The observable signature differs sharply: - **Without the invariant:** headroom declines roughly linearly with step count at a rate equal to the fixed overhead per step; the agent evicts required context, re-fetches it, inflates measured tokens, and t..."
  },
  "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": "a91126a94113e40a5bd39d380b0a983afaabe81f7822c19d704ac953a06155f8",
    "verified_classes": [
      "BudgetWindupError",
      "BudgetState"
    ],
    "verified_functions": [
      "update_ceiling",
      "floor"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 1,
    "raised_exceptions": [
      "BudgetWindupError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
