{
  "schema_version": "1.3.0",
  "slug": "why-does-an-instance-lose-referential-integrity-when-it-prunes-and-rewrites-its-own-working-memory-mid-task",
  "title": "Why does an instance lose referential integrity when it prunes and rewrites its own working memory mid-task",
  "date_of_record": "2026 November 27",
  "scope": "Applies to any agent that holds a mutable working-memory buffer and is authorized to compact, summarize, or rewrite that buffer via its own generation (self-editing context). Does not apply to append-only context with external, deterministic truncation, nor to memory managed by a separate non-LLM controller with an immutable audit log.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/why-does-an-instance-lose-referential-integrity-when-it-prunes-and-rewrites-its-own-working-memory-mid-task.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-lose-referential-integrity-when-it-prunes-and-rewrites-its-own-working-memory-mid-task.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-lose-referential-integrity-when-it-prunes-and-rewrites-its-own-working-memory-mid-task.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2083,
    "python_slice_tokens": 391,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "There are two ways a context window shrinks. **External truncation** is a pure function: a fixed policy (drop oldest N tokens, evict by recency) removes spans, and the removed content is either gone or archived verbatim. **Self-editing** is different: the model reads its own working memory, generates a *replacement* representation, and that replacement becom...",
    "what_was_observed": "A tool-using agent was executing a multi-step task: resolve a target resource, mutate it via one tool, then verify via a second tool. Mid-task, after several tool results had accumulated, the agent triggered a self-compaction pass to stay under a token budget. The compaction prompt instructed it to \"summarize progress so far, preserving what matters.\" The pre-edit working memory contained a concrete binding: The self...",
    "condition_of_validity": "The failure is bounded by a specific condition. A self-edit is *safe* with respect to a given downstream dereference if and only if that dereference resolves against a binding that is either (a) preserved byte-exact in the rewritten buffer, or (b) recoverable from an external, non-model store the agent can re-query at execution time. The failure triggers whe...",
    "decision_boundary": "The operational boundary is this: **an agent may self-edit its working memory only for spans that contain no pending dereference; any span holding a live binding must be preserved verbatim or externalized before the edit commits.** Concretely, before a self-edit commits, partition the buffer into: - **Live-binding spans** — literals that a not-yet-executed s...",
    "operational_effect": "Without this boundary, self-editing context degrades into **silent referential drift**: each compaction pass is individually fluent and locally lossless-looking, but across passes the agent's bindings erode toward paraphrase and reconstruction. Because reconstruction of high-entropy literals is a generation task with high error rates, the drift manifests as ..."
  },
  "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": "a501779c05a0cf511e27465e5f8b19c7a0ae4bdedcae985551c820ac84b25040",
    "verified_classes": [
      "ReferentialIntegrityError",
      "WorkingMemory"
    ],
    "verified_functions": [
      "extract_pinned_literals",
      "commit_self_edit"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 1,
    "raised_exceptions": [
      "ReferentialIntegrityError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "re"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
