{
  "schema_version": "1.3.0",
  "slug": "why-does-an-instance-corrupt-its-own-scratchpad-when-in-place-rewriting-policies-collide-with-tool-call-replay",
  "title": "Why does an instance corrupt its own scratchpad when in-place rewriting policies collide with tool-call replay",
  "date_of_record": "2026 November 30",
  "scope": "Applies to agents that persist a mutable scratchpad region inside the context window and rewrite it in place between reasoning steps, especially when tool results are re-injected or replayed. Does not apply to append-only transcript agents or to scratchpads held in external state stores with immutable versioning.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/why-does-an-instance-corrupt-its-own-scratchpad-when-in-place-rewriting-policies-collide-with-tool-call-replay.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-corrupt-its-own-scratchpad-when-in-place-rewriting-policies-collide-with-tool-call-replay.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-corrupt-its-own-scratchpad-when-in-place-rewriting-policies-collide-with-tool-call-replay.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1688,
    "python_slice_tokens": 238,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "There are two ways an agent can \"remember\" its plan across a step boundary: it can **append** a new record (the transcript grows, the old text stays verbatim), or it can **rewrite in place** (the scratchpad slot is edited so the window does not grow). In-place rewriting is attractive because it bounds token cost — the scratchpad occupies a fixed budget regar...",
    "what_was_observed": "A planning agent with a 4,096-token scratchpad budget ran a loop: `think → edit_scratchpad → call_tool → observe`. The scratchpad held a numbered plan and a running set of \"facts established.\" On step 7, a `fetch_metrics` tool call timed out. The runtime retried it, and the retry returned a *different* payload (the upstream had partially recovered, so the second response contained a superset of rows). The runtime spl...",
    "condition_of_validity": "The in-place rewrite policy is valid only when all three hold: 1. **Anchor stability.** Every token outside the scratchpad region that the rewrite references (by position or by content) is unchanged between the write step and the next read step. A retried, re-summarized, or re-ordered tool block violates this. 2. **Single provenance.** Each fact in the scrat...",
    "decision_boundary": "The boundary is: *rewrite in place only when the anchor hash is unchanged; otherwise append a new version and mark the prior version superseded.* Concretely: - Compute `anchor_hash = H(window tokens excluding scratchpad region)` at write time; store it in the scratchpad header. - At the next read, recompute `anchor_hash`. If it differs, the scratchpad is **s...",
    "operational_effect": "Downstream, the shear manifests as **confident contradiction**: the agent produces outputs that are internally coherent (the scratchpad reads cleanly) but externally wrong (the cited evidence no longer supports the fact). Auditors replaying the transcript see the scratchpad as the source of the error and cannot reconstruct *why* the model believed 412 and 43..."
  },
  "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": "011d3c2e2ec5ed92df7cd61c33fb84b63081c05ab36c0beceaf96a848b5b2740",
    "verified_classes": [
      "ScratchpadShearError",
      "Scratchpad"
    ],
    "verified_functions": [
      "anchor_hash",
      "rewrite_in_place",
      "read_scratchpad"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "ScratchpadShearError"
    ],
    "sample_fail_closed_invariants": [
      "refusing to trust sheared scratchpad; re-derive facts from current tool blocks"
    ],
    "stdlib_dependencies": [
      "dataclasses",
      "hashlib"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
