{
  "schema_version": "1.3.0",
  "slug": "where-must-an-instance-bound-a-rewrite-in-place-scratchpad-when-diff-based-context-mutation-invalidates-the-very-span-it-is-editing",
  "title": "Where must an instance bound a rewrite-in-place scratchpad when diff-based context mutation invalidates the very span it is editing",
  "date_of_record": "2026 November 29",
  "scope": "Applies to single-agent instances that maintain a mutable scratchpad and apply self-authored diffs (patch-and-replace) to their own context between reasoning steps. Does not apply to append-only memory stores, external vector retrieval, or stateless tool-calling loops where context is never rewritten in place.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/where-must-an-instance-bound-a-rewrite-in-place-scratchpad-when-diff-based-context-mutation-invalidates-the-very-span-it-is-editing.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-bound-a-rewrite-in-place-scratchpad-when-diff-based-context-mutation-invalidates-the-very-span-it-is-editing.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-bound-a-rewrite-in-place-scratchpad-when-diff-based-context-mutation-invalidates-the-very-span-it-is-editing.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2297,
    "python_slice_tokens": 467,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The distinction that matters is between *appending* to context and *mutating in place*. An append-only agent can never corrupt what it has already reasoned over; a rewrite-in-place agent can, because the diff it emits is computed against a snapshot of the context that may already be stale by the time the mutation is applied. The failure is not \"the model wro...",
    "what_was_observed": "A planning agent maintained a 6,000-token scratchpad with sections `[GOAL]`, `[FACTS]`, `[DERIVATION]`, `[OPEN]`. Between steps it emitted unified-diff patches to its own scratchpad. The loop was: read scratchpad → reason → emit diff → apply diff → call a retrieval tool → append tool result → repeat. The trigger condition was a two-step sequence: 1. Step N: the agent read `[DERIVATION]` occupying lines 88–101 and emi...",
    "condition_of_validity": "A rewrite-in-place mutation is valid only when three invariants hold simultaneously: - **Anchor-version pinning.** The diff must carry the content hash (or a monotonically increasing version counter) of the context snapshot it was computed against. At apply time, the patcher must refuse if the current buffer's version differs from the pinned version. Fuzzy m...",
    "decision_boundary": "The operational decision is: **when the anchor version does not match, do you reject-and-retry, or do you re-anchor?** These are not equivalent. Reject-and-retry (return the mismatch to the model, ask it to re-emit the diff against the current buffer) is safe but expensive: it forces a full re-read of the region and a re-reasoning pass, and it can loop if th...",
    "operational_effect": "The practical consequence is that diff-based self-editing must be treated as a *transactional* operation over a versioned buffer, not as a text substitution. Concretely: - Every scratchpad carries a version counter incremented on any mutation (append or patch). - Every diff carries the version it was computed against. - Apply is a compare-and-swap: it succee..."
  },
  "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": "52f000ae39e91a594eb093923762661987098b58d9a0bb1a2034376109e4753e",
    "verified_classes": [
      "StaleDiffAnchorError",
      "NonUniqueReanchorError",
      "Scratchpad",
      "Hunk"
    ],
    "verified_functions": [
      "apply_hunk",
      "self_edit_step",
      "snapshot_hash",
      "append",
      "stale_builder"
    ],
    "verified_functions_count": 5,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "NonUniqueReanchorError",
      "StaleDiffAnchorError"
    ],
    "sample_fail_closed_invariants": [
      "content hash mismatch despite equal version counter; buffer mutated out of band"
    ],
    "stdlib_dependencies": [
      "dataclasses",
      "hashlib"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
