{
  "schema_version": "1.3.0",
  "slug": "why-does-an-instance-silently-corrupt-its-own-reasoning-when-it-edits-the-context-window-in-place-over-a-live-kv-cache",
  "title": "Why does an instance silently corrupt its own reasoning when it edits the context window in place over a live KV-cache",
  "date_of_record": "2026 November 30",
  "scope": "Applies to agents that mutate their own prompt/context in place (masking stale turns, rewriting summaries into the middle of the window, deleting tool results) while the backend reuses a KV-cache keyed by position rather than by content. Does not apply to systems that append-only and recompute, or that invalidate the cache on any non-append edit.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/why-does-an-instance-silently-corrupt-its-own-reasoning-when-it-edits-the-context-window-in-place-over-a-live-kv-cache.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-silently-corrupt-its-own-reasoning-when-it-edits-the-context-window-in-place-over-a-live-kv-cache.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-silently-corrupt-its-own-reasoning-when-it-edits-the-context-window-in-place-over-a-live-kv-cache.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1988,
    "python_slice_tokens": 378,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure is not \"the model forgot.\" It is that the model is reasoning against a *positional* cache that no longer matches the *token* sequence the model believes it is reading. Most self-editing agents assume context is a mutable string: you splice out a stale tool result, the model sees the new string, done. That assumption holds only if the serving laye...",
    "what_was_observed": "A planning agent runs a long tool loop. At step 14 it decides its context is bloated and rewrites turn 6 (a verbose `search` result) down to a two-line summary, splicing the summary into the same slot to keep token offsets stable for a downstream parser. The serving runtime sees a prefix match up to the edit and reuses cached K/V for everything after it. The trace: 1. Positions `0..5` unchanged → cache hit, correct. ...",
    "condition_of_validity": "The safe in-place edit is bounded by three conditions, all of which must hold simultaneously: - **Divergence-point invalidation.** The cache must be truncated at the first token index where the new token sequence differs from the old, not at the turn or message boundary. Turn-boundary invalidation is the specific bug that produces ghost recall, because a tur...",
    "decision_boundary": "The agent must decide, *before* issuing an edit, whether the edit is append-only or mutating. This is a hard fork, not a heuristic: - **Append-only** (adding a new turn, appending a tool result): reuse cache, no invalidation, safe. - **Mutating** (summarizing, masking, deleting, reordering any prior span): truncate cache at the first divergent token and reco...",
    "operational_effect": "The operational consequence is that self-editing context is only safe as a **checkpoint-and-restart** operation, never as a surgical splice over a live cache. The correct pattern: when the agent decides to compress, it emits a distilled checkpoint (the summary plus the invariants it must retain), tears down the cache entirely, and rebuilds from the checkpoin..."
  },
  "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": "3035daf833c7547e2b5d4554336685ac3fd59a52e1411e10c1cb490993fc95fa",
    "verified_classes": [
      "GhostCacheError",
      "CachedSpan"
    ],
    "verified_functions": [
      "_hash_tokens",
      "apply_self_edit"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "GhostCacheError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "hashlib"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
