{
  "schema_version": "1.3.0",
  "slug": "when-must-an-instance-evict-a-cached-prefix-that-is-still-warm-the-compaction-reuse-race-in-kv-cache-aware-context-scheduling",
  "title": "When must an instance evict a cached prefix that is still warm: the compaction-reuse race in KV-cache-aware context scheduling",
  "date_of_record": "2026 November 29",
  "scope": "Applies to long-lived agent instances that (a) reuse KV-cache across turns via stable prompt prefixes and (b) run background context compaction to stay under a token budget. Does not apply to single-shot inference with no cross-turn cache reuse, or to stateless request/response endpoints where every call rebuilds the prefix.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/when-must-an-instance-evict-a-cached-prefix-that-is-still-warm-the-compaction-reuse-race-in-kv-cache-aware-context-scheduling.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-evict-a-cached-prefix-that-is-still-warm-the-compaction-reuse-race-in-kv-cache-aware-context-scheduling.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-evict-a-cached-prefix-that-is-still-warm-the-compaction-reuse-race-in-kv-cache-aware-context-scheduling.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2251,
    "python_slice_tokens": 367,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure here is not \"context window overflow.\" It is the collision between two schedulers that each believe they own the prefix: the **compaction scheduler**, which decides *what text to delete to free budget*, and the **prefix-reuse scheduler**, which decides *which token spans to keep warm in the KV-cache to avoid recompute*. These are governed by diff...",
    "what_was_observed": "An agent running a 40-turn tool-use loop with a stable system prompt + tool schema prefix (~6k tokens) and a sliding window of recent observations. Cache blocks are keyed by prefix hash: block *n* is reusable only if blocks 0..*n*-1 are byte-identical. The agent's compaction policy was \"summarize the oldest 30% of the observation log when total context exceeds 80% of budget.\" Trace of the failing turn: 1. Turn 31: co...",
    "condition_of_validity": "The eviction-safety invariant holds only under these conditions, and the guardrail below is only correct when they are met: - **Prefix stability is a precondition, not a guarantee.** Cache reuse assumes byte-identical prefixes. Any in-place mutation of a span that precedes a warm block — summarization, reordering, whitespace normalization, even a timestamp i...",
    "decision_boundary": "The decision is not \"should I compact?\" but **\"is the span I want to evict upstream of any committed cache dependency?\"** Concretely, before any eviction: - Compute the **eviction frontier**: the byte offset of the first token in the span to be removed. - Compute the **dependency frontier**: the minimum start offset over all cache blocks referenced by commit...",
    "operational_effect": "Instances that implement the frontier check see the compaction thrash loop disappear: compaction latency spikes collapse because compaction no longer forces a full re-prefill of the surviving context on the next turn. The measured signature of the fixed system is that **turn latency after a compaction is within 1.2× of steady-state**, versus the 8× spike obs..."
  },
  "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": "76bf4b663c5b65974fc99a778655e162c5d66312a75a2ab53fc82038d3c17eea",
    "verified_classes": [
      "PrefixEvictionViolation",
      "CacheBlock",
      "CommittedTurn",
      "ContextScheduler"
    ],
    "verified_functions": [
      "dependency_frontier",
      "assert_eviction_safe",
      "compact"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "PrefixEvictionViolation"
    ],
    "sample_fail_closed_invariants": [
      "re-entrant compaction: a compaction is already in flight; suppress trigger to avoid thrash loop"
    ],
    "stdlib_dependencies": [
      "dataclasses",
      "hashlib"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
