{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-self-editing-context-from-corrupting-in-place-workspace-mutations",
  "title": "Which invariants prevent self-editing context from corrupting in-place workspace mutations",
  "date_of_record": "2026 November 25",
  "scope": "Applies to any agent that holds a mutable workspace (file buffer, scratchpad, structured state object) inside its own context and edits that workspace via tool calls whose results are written back into the same context window. Does not apply to agents that mutate external state only through append-only logs or that recompute workspace from an authoritative store on every turn.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-self-editing-context-from-corrupting-in-place-workspace-mutations.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-self-editing-context-from-corrupting-in-place-workspace-mutations.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-self-editing-context-from-corrupting-in-place-workspace-mutations.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2419,
    "python_slice_tokens": 373,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "There are two distinct representations of the workspace at any instant: the **canonical workspace** (what the tool actually wrote to disk / the state object) and the **context-resident mirror** (the tokens inside the model's window that claim to describe the workspace). Most self-editing failures are not write failures — the tool succeeds, the file is correc...",
    "what_was_observed": "A coding agent was asked to rename a function `parse_cfg` to `parse_config` across a single module and update all call sites. The workspace was a 900-line file held in context. The agent's plan had four steps: (1) read the file, (2) rename the definition, (3) rename each call site, (4) verify. At step 2 the agent issued a targeted replacement tool call. The tool returned a unified diff of the changed region — three l...",
    "condition_of_validity": "The invariant that prevents this class of failure is a **mirror-authority invariant**: at every reasoning step, for every region of the workspace the agent intends to read, there must be exactly one authoritative representation in context, and it must be the post-mutation one. This is violated whenever: - A mutation tool returns a partial view (diff, hunk, p...",
    "decision_boundary": "The boundary between safe and unsafe self-editing is not \"did the edit succeed\" but \"**did the agent's next read of the edited region come from a representation that postdates the edit.**\" Two operational tests distinguish the cases: - **Span coverage test.** Does the mutation result's reported span cover every region the agent will read before the next muta...",
    "operational_effect": "Enforcing the mirror-authority invariant changes agent behavior in three measurable ways. First, **edit plans become read-bounded.** The agent cannot batch N mutations and then reason across all N regions from memory; it must interleave reads. In the observed case, the correct plan was: rename definition, re-read the full file (or the full set of call-site r..."
  },
  "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": "a3087c286533fbfdf2b51e7ed9d0197ab6b9af0dcb993c9474744487b6bb4352",
    "verified_classes": [
      "StaleMirrorError",
      "WorkspaceMirror"
    ],
    "verified_functions": [
      "safe_edit_step",
      "reason_over",
      "__init__",
      "render",
      "apply_mutation",
      "read_for_reasoning"
    ],
    "verified_functions_count": 6,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "StaleMirrorError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
