{
  "schema_version": "1.3.0",
  "slug": "why-does-an-instance-of-a-context-budget-silently-overrun-when-compaction-reclaims-tokens-that-were-already-counted-as-resident",
  "title": "Why does an instance of a context budget silently overrun when compaction reclaims tokens that were already counted as resident?",
  "date_of_record": "2026 November 15",
  "scope": "Applies to agent runtimes that maintain an explicit token budget over a message/state graph and that perform compaction (summarization, eviction, or deduplication) as a background or inline operation. Does not apply to stateless single-shot inference where the budget is recomputed from scratch on every request with no persistent provenance ledger.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/why-does-an-instance-of-a-context-budget-silently-overrun-when-compaction-reclaims-tokens-that-were-already-counted-as-resident.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-of-a-context-budget-silently-overrun-when-compaction-reclaims-tokens-that-were-already-counted-as-resident.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-of-a-context-budget-silently-overrun-when-compaction-reclaims-tokens-that-were-already-counted-as-resident.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1792,
    "python_slice_tokens": 391,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "There are two distinct quantities that both get called \"context size\": 1. **Resident tokens** — the sum of token counts of the messages currently materialized in the prompt that will be sent to the model on the next turn. 2. **Accounted tokens** — the sum of token counts recorded in the provenance ledger against every logical state object that the runtime be...",
    "what_was_observed": "A long-running agent (multi-hour, tool-calling, ~40k-token budget) began failing intermittently with provider-side `context_length_exceeded` on turns where the internal budget estimator reported 61–78% utilization. The failure correlated with turns immediately following a compaction event, and only when the compaction was triggered by a *deduplication* pass rather than by summarization. Instrumentation of the ledger ...",
    "condition_of_validity": "The invariant `accounted == resident` (not `resident + reclaimable`) holds, and the budget check is safe, only under all of the following: - Every object in the ledger is in exactly one provenance state: `resident`, `reclaimable-with-verified-source`, or `dropped`. - `reclaimable` is only assigned when the source bytes are still present in a store reachable ...",
    "decision_boundary": "The runtime must choose, per compaction event, between two policies: - **Conservative (drop-on-compact):** reclaimed objects transition directly to `dropped`; `accounted` decreases by exactly the reclaimed amount; no rehydration is ever offered. Budget headroom is real. Cost: lossy, no undo. - **Reversible (retain-on-compact):** reclaimed objects transition ...",
    "operational_effect": "With the boundary enforced, compaction events no longer produce phantom headroom. Dashboards show compaction reducing `resident` while leaving `accounted` flat until objects are explicitly dropped, which is the honest signal: compaction reduces *latency and prompt length*, not *budget*. Tool-loop agents gain a hard guarantee that a passing budget check impli..."
  },
  "matched_failure_symptoms": [
    "CONTEXT_DRIFT_OR_ATTENTION_DILUTION"
  ],
  "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": "75d077e18c0fff128ffde879224b2388e9556abba5078f43150069715a423463",
    "verified_classes": [
      "ProvenanceError",
      "State",
      "LedgerEntry",
      "BudgetLedger"
    ],
    "verified_functions": [
      "demonstrate_boundary",
      "resident_tokens",
      "accounted_tokens",
      "compact",
      "check_next_turn"
    ],
    "verified_functions_count": 5,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "ProvenanceError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "enum"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
