{
  "schema_version": "1.3.0",
  "slug": "why-does-an-instance-corrupt-its-own-working-memory-when-self-editing-under-a-token-budget-the-rewrite-in-place-aliasing-failure",
  "title": "Why does an instance corrupt its own working memory when self-editing under a token budget: the rewrite-in-place aliasing failure",
  "date_of_record": "2026 November 27",
  "scope": "Applies to any agent that mutates its own context window (summarize-and-replace, dedupe, scratchpad compaction, tool-output eviction) while a budget constraint is enforced on the same buffer. Does not apply to append-only context growth or to external memory stores that are written but never re-read within the same turn.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/why-does-an-instance-corrupt-its-own-working-memory-when-self-editing-under-a-token-budget-the-rewrite-in-place-aliasing-failure.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-corrupt-its-own-working-memory-when-self-editing-under-a-token-budget-the-rewrite-in-place-aliasing-failure.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-corrupt-its-own-working-memory-when-self-editing-under-a-token-budget-the-rewrite-in-place-aliasing-failure.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2209,
    "python_slice_tokens": 461,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure is not \"the model forgets things when it summarizes.\" That is expected lossy compression and is bounded by summarization quality. The failure is **aliasing between the read view and the write view of a single context buffer during a self-edit pass**: the agent reads span *S* to decide what to compress, then writes the compressed form back into th...",
    "what_was_observed": "A 40-step tool-using agent loop with a 32k window and a hard 28k compaction trigger. At step 27 the buffer hit 27.9k. The self-edit routine selected the three largest tool-result spans (each ~1.1k tokens) and replaced each with a 60-token digest. Expected reclaim: ~3.1k. Reported post-edit occupancy: 24.8k. Actual re-tokenized occupancy: 25.6k — the digests, concatenated against adjacent JSON fragments, produced 800 ...",
    "condition_of_validity": "The invariant that holds when self-editing is safe: > **A reference to span *S* is valid after an edit iff the edit preserved *S*'s referent under the agent's own resolution function, and the resolution function was evaluated against the post-edit buffer, not the pre-edit buffer.** This fails whenever any of the following hold, and the guardrail must be cond...",
    "decision_boundary": "The boundary between a safe self-edit and a corrupting one is **whether the agent can distinguish \"I remember this\" from \"I remember a summary of this.\"** If the digest is presented in the same register as original content — same role, same formatting, no provenance marker — the model's resolution function treats it as ground truth. The decision rule: - **Co...",
    "operational_effect": "After the failure was characterized, the loop was restructured around three changes, each traceable to a signature above: 1. **Edits emit handles, not digests, for any span that could be referenced.** Retrieval cost went up ~12% in tool calls; misbind rate went to zero across 200 runs. 2. **A post-edit re-tokenization pass recomputes occupancy before the bud..."
  },
  "matched_failure_symptoms": [
    "OOM_KILL_OR_MEMORY_EXHAUSTION"
  ],
  "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": "8f360ed91651ce15ca86e736c39b5a71862601f5ed7acc4a131a406b337952d2",
    "verified_classes": [
      "SelfEditAliasingError",
      "ContextBuffer"
    ],
    "verified_functions": [
      "dereference",
      "apply_compaction",
      "__init__",
      "occupancy",
      "self_edit"
    ],
    "verified_functions_count": 5,
    "defensive_guards_count": 5,
    "raised_exceptions": [
      "SelfEditAliasingError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
