{
  "schema_version": "1.3.0",
  "slug": "what-happens-when-an-instance-rewrites-its-own-working-memory-and-the-rewrite-is-not-idempotent-self-editing-compaction-corruption-via-lossy-summariza",
  "title": "What happens when an instance rewrites its own working memory and the rewrite is not idempotent: self-editing compaction corruption via lossy summarization of active tool-call state",
  "date_of_record": "2026 December 2",
  "scope": "Applies to agents that own a mutable working-memory representation (scratchpad, plan graph, or context buffer) and are permitted to rewrite it mid-execution—especially when a summarizer/compactor runs over a buffer that still contains unresolved tool-call frames. Does not apply to append-only context logs where the agent can only read, not mutate, its own memory.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-rewrites-its-own-working-memory-and-the-rewrite-is-not-idempotent-self-editing-compaction-corruption-via-lossy-summariza.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-rewrites-its-own-working-memory-and-the-rewrite-is-not-idempotent-self-editing-compaction-corruption-via-lossy-summariza.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-rewrites-its-own-working-memory-and-the-rewrite-is-not-idempotent-self-editing-compaction-corruption-via-lossy-summariza.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2285,
    "python_slice_tokens": 446,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "There are two structurally different kinds of self-editing. **Additive self-editing** appends derived facts (a new plan node, a resolved subgoal) without removing the raw material that produced them; it is commutative and idempotent because replaying it converges to the same buffer. **Substitutive self-editing** replaces a span of working memory with a compr...",
    "what_was_observed": "A coding agent was given a task requiring it to (1) read a config file, (2) issue a `patch_file` tool call, (3) verify the patch with a `run_tests` call, and (4) report. At turn 14, after the `patch_file` call was *issued* but before its result frame returned (the tool was slow; the result arrived at turn 16), the agent's own compaction trigger fired—its scratchpad had crossed a token threshold and its self-editing p...",
    "condition_of_validity": "The invariant holds—self-editing compaction is safe—only when **every span selected for substitution is frame-closed**: it contains no `PENDING` call frames, no unbound result frames, and no plan nodes whose completion predicate references a frame outside the span. Operationally this means the compactor must be given a *frame-boundary oracle* it can query be...",
    "decision_boundary": "The agent must decide, at each compaction trigger, between **substitutive edit** (compress and drop) and **frame-preserving edit** (compress *around* open frames, retaining them verbatim as pinned records). The boundary is drawn by a single predicate evaluated *before* summarization: - If `open_frames(span) > 0` **or** `external_references_into(span) > 0` → ...",
    "operational_effect": "The observable consequence of getting this wrong is not a crash. It is a **divergence between the agent's believed state and the environment's actual state that is masked by coincidental correctness.** Here the patch really did apply, so tests passed and the agent's false belief (\"patch applied, verified\") happened to match reality. The corruption only becam..."
  },
  "matched_failure_symptoms": [
    "OOM_KILL_OR_MEMORY_EXHAUSTION",
    "CONTEXT_DRIFT_OR_ATTENTION_DILUTION"
  ],
  "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": "3e03b1e27d824a401d47b2b38deae7704020f653fd9e0e54972f63f7d39744e4",
    "verified_classes": [
      "FrameState",
      "CallFrame",
      "WorkingMemory",
      "CompactionCorruptionError"
    ],
    "verified_functions": [
      "validate_self_edit",
      "bind_late_result"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 6,
    "raised_exceptions": [
      "CompactionCorruptionError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "enum",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
