{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-silent-corruption-when-self-editing-context-windows-are-rolled-back-across-a-partial-in-place-rewrite",
  "title": "Which invariants prevent silent corruption when self-editing context windows are rolled back across a partial in-place rewrite",
  "date_of_record": "2026 November 13",
  "scope": "Applies to agents that mutate their own context window via in-place rewrite primitives with a rollback log (undo stack, copy-on-write snapshots, or journaled patches), where the same logical buffer is rewritten more than once between checkpoints. Does not apply to append-only context growth, nor to rewrite schemes that always allocate a fresh immutable buffer per edit (where rollback is trivially a pointer swap).",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-silent-corruption-when-self-editing-context-windows-are-rolled-back-across-a-partial-in-place-rewrite.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-silent-corruption-when-self-editing-context-windows-are-rolled-back-across-a-partial-in-place-rewrite.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-silent-corruption-when-self-editing-context-windows-are-rolled-back-across-a-partial-in-place-rewrite.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1507,
    "python_slice_tokens": 387,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The dangerous boundary is not \"can I undo an edit?\" but \"is the undo log *causally consistent* with the buffer state it claims to describe?\" An in-place rewrite mutates bytes at offsets; a rollback log records the inverse. These two are only mutually valid if every rewrite that touched a region is present in the log *and* every rollback is applied in strict ...",
    "what_was_observed": "A rewrite primitive `splice(offset, delete_len, insert_text)` was implemented to mutate the buffer first, then append `{offset, original_bytes}` to the undo log. Under memory pressure the log append was allowed to fail-and-drop (treated as best-effort telemetry). Sequence: 1. Agent rewrites a 40-token span describing a variable's type, `int` → `list[int]`. Buffer mutated; log entry appended. Fine. 2. Agent rewrites a...",
    "condition_of_validity": "Rollback is sound if and only if all three hold simultaneously: - **Log completeness:** every buffer mutation has a corresponding inverse record *committed before or atomically with* the mutation. A mutation whose inverse is not durably recorded must be treated as unrecoverable, not as best-effort. - **Offset stability:** inverse records store either absolut...",
    "decision_boundary": "- If the log append can fail, the rewrite must fail **before** mutating the buffer (write-ahead the inverse, then splice). Never mutate-then-log. - If offsets may shift between edits, store content anchors, not offsets; or forbid overlapping rewrites until a checkpoint is taken. - If selective rollback is offered, treat it as \"replay inverses from current he...",
    "operational_effect": "After enforcing write-ahead inverses and content-anchored offsets, rollback became a genuine inverse: post-rollback buffer hash matched the pre-edit hash in all tested interleavings, including overlapping splices and dropped-under-pressure scenarios (which now abort the rewrite instead of proceeding). The cost is that a failed log append fails the rewrite, f..."
  },
  "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": "01430bb4ef5474a4edbc6a2b97b20fef1192223140ab98d7022992ea7a106e8f",
    "verified_classes": [
      "RollbackIntegrityError",
      "Inverse",
      "RewriteBuffer"
    ],
    "verified_functions": [
      "__init__",
      "_anchor",
      "splice",
      "_append_durable",
      "rollback",
      "_find_by_anchors"
    ],
    "verified_functions_count": 6,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "RollbackIntegrityError"
    ],
    "sample_fail_closed_invariants": [
      "inverse record not committed; refusing in-place rewrite (buffer must not outrun its undo log)",
      "rollback past start of log",
      "anchor mismatch: buffer diverged from undo log, rollback would corrupt context"
    ],
    "stdlib_dependencies": [
      "dataclasses",
      "hashlib"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
