{
  "schema_version": "1.3.0",
  "slug": "what-happens-when-an-instance-exhausts-its-scratchpad-budget-mid-compaction-the-compaction-retrieval-deadlock-under-latency-slos",
  "title": "What happens when an instance exhausts its scratchpad budget mid-compaction: the compaction-retrieval deadlock under latency SLOs",
  "date_of_record": "2026 November 12",
  "scope": "Applies to context budget schedulers that partition a fixed token window across retrieval, scratchpad (agent working memory), and compaction headroom, and that enforce a per-turn latency SLO. Does not apply to schedulers with unbounded windows, offline batch summarization, or systems where compaction is preemptible and can be deferred across turns without violating the SLO.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-exhausts-its-scratchpad-budget-mid-compaction-the-compaction-retrieval-deadlock-under-latency-slos.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-exhausts-its-scratchpad-budget-mid-compaction-the-compaction-retrieval-deadlock-under-latency-slos.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-exhausts-its-scratchpad-budget-mid-compaction-the-compaction-retrieval-deadlock-under-latency-slos.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1873,
    "python_slice_tokens": 241,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "A context budget scheduler is not a memory allocator. It allocates *time-bounded* token capacity across three consumers with different cost profiles: retrieval (I/O-bound, latency scales with `k` and index fanout), scratchpad (pure write, cheap), and compaction (CPU/GPU-bound summarization, cost roughly linear in the span being compacted and superlinear in t...",
    "what_was_observed": "In a production agent loop with a 32k window, 6k scratchpad reservation, `k=8` retrieval, and a 1.8s p95 per-turn SLO, the following sequence reproduced deterministically under long-horizon tasks (>40 turns): 1. Scratchpad occupancy climbed monotonically as the agent accumulated intermediate results; the scheduler deferred compaction each turn because projected compaction latency (~340ms for a 12k span) plus retrieva...",
    "condition_of_validity": "This failure mode requires all of the following to hold simultaneously: - **Non-preemptible compaction.** Compaction, once started, holds its staging buffer until completion. If compaction can spill its staging buffer to external storage or checkpoint mid-summary, the deadlock degrades to a latency hit, not a stall. - **Scratchpad reservation is a hard floor...",
    "decision_boundary": "The correct decision is to **decouple compaction admission from SLO headroom and instead gate it on scratchpad high-water mark.** Concretely: - Admit compaction when `scratchpad_used > 0.70 × reservation`, *regardless* of SLO headroom, and *reserve* the staging buffer at admission time (do not attempt to acquire it later). Pay the latency cost early, when th...",
    "operational_effect": "With the high-water-mark trigger and reserved staging buffer, the same workload ran 200 turns without a stall. Scratchpad occupancy oscillated between 0.55 and 0.72 of reservation; compaction fired at ~0.70 every ~7 turns, always with staging headroom, at a mean latency of 360ms absorbed within the 1.8s SLO because it was admitted when generation was short. ..."
  },
  "matched_failure_symptoms": [
    "SQLITE_BUSY_OR_DEADLOCK",
    "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": "b77a96882e6ada82e2d6ab578f38d8703e0fab4cc595a4549de1eba6e8aafcab",
    "verified_classes": [
      "CompactionStagingDeadlock",
      "ContextBudgetScheduler"
    ],
    "verified_functions": [
      "__init__",
      "admit_compaction"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 1,
    "raised_exceptions": [
      "CompactionStagingDeadlock"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
