{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-scratchpad-rewrites-from-silently-invalidating-the-context-window-they-rewrite",
  "title": "Which invariants prevent scratchpad rewrites from silently invalidating the context window they rewrite",
  "date_of_record": "2026 November 18",
  "scope": "Applies to agents that maintain a structured scratchpad (keyed sections, typed entries, or a symbolic working memory) inside their own context window and are permitted to rewrite that scratchpad mid-episode. Does not apply to append-only logs, to scratchpads held outside the context (external files or stores), or to rewrites performed by a separate process that re-reads the full serialized state from scratch.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-scratchpad-rewrites-from-silently-invalidating-the-context-window-they-rewrite.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-scratchpad-rewrites-from-silently-invalidating-the-context-window-they-rewrite.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-scratchpad-rewrites-from-silently-invalidating-the-context-window-they-rewrite.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1664,
    "python_slice_tokens": 322,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "A *rewrite* is an operation that replaces a region of the context window with new tokens derived from the old tokens. A *compaction* is a rewrite that is required to be information-preserving under a declared loss function. The two are routinely conflated because both are expressed as \"the model emits new scratchpad text.\" The distinction that matters operat...",
    "what_was_observed": "In a long-horizon task loop (tool calls interleaved with scratchpad edits, ~40k tokens of accumulated state), the agent was asked to increment a counter section and then append a log line to the same section in the same turn. The model emitted a single replacement block for that section computed from the section content it had read *before* the tool call in the same turn. The tool call mutated an out-of-band field th...",
    "condition_of_validity": "A scratchpad rewrite is valid only if all of the following hold at commit time: - **View freshness.** The replacement was computed against a snapshot whose version equals the version currently at the commit target. If any mutation occurred between read and commit, the rewrite must be rejected or rebased, never merged. - **Field coverage.** Every field the re...",
    "decision_boundary": "The boundary is between *optimistic rewrite* (commit the model's emitted replacement, reconcile later) and *versioned rewrite* (reject or rebase on version mismatch). Choose optimistic only when the scratchpad is single-writer, the rewrite is confined to one section, and no tool call in the same turn can mutate that section out of band. In every other case, ...",
    "operational_effect": "With versioned rewrites and per-section version counters, the observed failure class disappears and is replaced by an explicit `StaleScratchpadView` rejection that the loop can handle by re-reading and re-emitting. The cost is measurable: roughly one additional read per rewrite and a small rebase rate. The benefit is that scratchpad corruption becomes a loud..."
  },
  "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": "b282bc26239bde1148a73b5dade8522be9e4866034c9085c3749c16196353b71",
    "verified_classes": [
      "StaleScratchpadView",
      "FieldCoverageViolation",
      "Section",
      "Scratchpad"
    ],
    "verified_functions": [
      "apply_increment_and_log",
      "__init__",
      "read",
      "mutate",
      "commit_rewrite"
    ],
    "verified_functions_count": 5,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "FieldCoverageViolation",
      "StaleScratchpadView"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "__future__",
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
