{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-self-editing-context-windows-from-corrupting-their-own-rewrite-base-during-in-place-eviction",
  "title": "Which invariants prevent self-editing context windows from corrupting their own rewrite base during in-place eviction",
  "date_of_record": "2026 November 28",
  "scope": "Applies to agents that own a mutable context buffer and perform in-place edits (rewrite, summarize-in-place, evict-and-splice) against that buffer between reasoning turns. Does not apply to append-only transcript agents or to external retrieval stores where the working context is reconstructed from scratch each turn.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-self-editing-context-windows-from-corrupting-their-own-rewrite-base-during-in-place-eviction.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-self-editing-context-windows-from-corrupting-their-own-rewrite-base-during-in-place-eviction.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-self-editing-context-windows-from-corrupting-their-own-rewrite-base-during-in-place-eviction.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1686,
    "python_slice_tokens": 378,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "An append-only context has a single, monotonic write frontier: every token added is a new address, and the model's own prior output never changes identity. A *self-editing* context collapses this invariant. When the agent rewrites a span in place—compressing a tool transcript, evicting stale reasoning, splicing a summary over a region—it mutates addresses th...",
    "what_was_observed": "A planner agent maintains a ~90k-token working context across a long debugging session. It runs an eviction pass every N turns: a summarizer model reads tokens `[a, b)`, emits a compressed summary of length `s < (b - a)`, and the runtime splices the summary over `[a, b)`, shifting every token at index `≥ b` left by `(b - a - s)`. The failure trace: 1. Turn 12: agent plans \"I will inspect the span at `[51200, 51400)` ...",
    "condition_of_validity": "The integrity guarantee holds **only if** every edit is expressed as a diff against a *pinned, versioned* base and the runtime rejects any diff whose base version ≠ current buffer version. Concretely, the following must all hold: - The buffer carries a monotonic `version` and a `content_hash` over the exact token sequence. - Any span reference held by the mo...",
    "decision_boundary": "The runtime must choose, per edit, between two safe regimes and never a third: - **Rebase-or-reject.** If the edit's pinned base version equals the live version, apply. If not, either (a) recompute the edit against the live buffer, or (b) reject and force the model to re-plan against current offsets. Never apply a stale-base diff by best-effort offset matchi...",
    "operational_effect": "With versioned diffs and handle resolution enforced: - Misaligned reads become *loud* failures (`StaleSpanError`) instead of silent wrong-region reasoning, converting a corruption into a recoverable re-plan. - Summary-over-summary drift is bounded by lineage tracking: a re-summarization of a summary is tagged `depth ≥ 2` and, past a configured depth, is refu..."
  },
  "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": "89384ab2bda37cc2bd5b03c4bc9cbf8ed9db3433bedb69e1906b103de21efaa4",
    "verified_classes": [
      "StaleSpanError",
      "SummaryLineageError",
      "Span",
      "ContextBuffer"
    ],
    "verified_functions": [
      "evict_and_compress",
      "content_hash",
      "read",
      "splice",
      "append"
    ],
    "verified_functions_count": 5,
    "defensive_guards_count": 5,
    "raised_exceptions": [
      "StaleSpanError",
      "SummaryLineageError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "hashlib",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
