{
  "schema_version": "1.3.0",
  "slug": "in-what-scenarios-must-an-instance-refuse-an-in-place-context-rewrite-when-the-diff-s-base-hash-no-longer-matches-the-live-window",
  "title": "In what scenarios must an instance refuse an in-place context rewrite when the diff's base hash no longer matches the live window",
  "date_of_record": "2026 November 23",
  "scope": "Applies to single-instance agents that mutate their own working context via diff-based edits (search/replace, patch application, or offset-anchored splices) against a mutable in-memory window. Does not apply to append-only context growth, external vector-store retrieval, or full-window regeneration from a canonical store.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-refuse-an-in-place-context-rewrite-when-the-diff-s-base-hash-no-longer-matches-the-live-window.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-refuse-an-in-place-context-rewrite-when-the-diff-s-base-hash-no-longer-matches-the-live-window.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/in-what-scenarios-must-an-instance-refuse-an-in-place-context-rewrite-when-the-diff-s-base-hash-no-longer-matches-the-live-window.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1725,
    "python_slice_tokens": 324,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "There are two failure classes when an agent edits its own context. The first is *content error*: the agent writes the wrong replacement text. This is loud—downstream reasoning degrades in a way that is usually attributable to the bad edit. The second, and the subject here, is *anchor error*: the diff is structurally valid but was computed against a base stat...",
    "what_was_observed": "An agent executing a long tool-use loop (roughly 40 turns) maintained a scratchpad region at a fixed prefix of its context, followed by a growing tool-output tail. A self-editing policy rewrote the scratchpad every N turns by emitting a search/replace diff: locate a sentinel-delimited block, replace its interior. The trigger condition was a *compaction event*. At turn 31, the runtime truncated the oldest tool outputs...",
    "condition_of_validity": "A diff-based context mutation is valid only when all three hold at apply time, not at author time: - **Base identity:** `hash(live_window) == base_hash` recorded when the diff was authored, OR the diff carries per-anchor content hashes and each anchor's current content matches. - **Anchor uniqueness:** each search anchor resolves to exactly one span in the l...",
    "decision_boundary": "The instance must **refuse** the in-place rewrite and fall back to re-derivation (re-read the live window, recompute the diff against current state) when any of the following is true: - `base_hash` mismatch AND the diff is anchored on content that could have been duplicated by compaction, truncation, or tool-output quoting. - The anchor resolves to more than...",
    "operational_effect": "Enforcing this boundary changes the agent's edit loop from \"author diff, apply diff\" to \"author diff, re-validate against live window, apply or re-derive.\" The cost is one extra hash comparison and one anchor-uniqueness scan per mutation—negligible against the cost of a provenance-contaminated window, which is unrecoverable from inside the context because th..."
  },
  "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": "cf42ac2fc44215edba172ece244c284c667e3bff910131b457ef5462fd59adbb",
    "verified_classes": [
      "Provenance",
      "ContextAnchorError",
      "Span",
      "PendingDiff"
    ],
    "verified_functions": [
      "window_hash",
      "resolve_anchor",
      "_fuzzy_contains",
      "apply_self_edit"
    ],
    "verified_functions_count": 4,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "ContextAnchorError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "enum",
      "hashlib"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
