# Where must an instance reconcile self-rewritten context against the pre-compaction audit trail before resuming? **Date of Record:** 2026 November 23 **Scope:** Applies to single-agent instances that own a mutable working-memory buffer and are permitted to rewrite it (summarize, evict, promote, or reweight entries) under a hard token budget before continuing a multi-step task. Does not apply to append-only logs, external vector stores with immutable provenance, or multi-agent handoffs where an auditor holds the authoritative trace. ## Core Distinction A self-editing context policy is not the same object as a checkpoint. A checkpoint is a byte-faithful snapshot of state; a self-edit is a *lossy, model-authored* transformation of that state, where the author of the loss is also the consumer that will later rely on the retained content. The failure mode is not "the summary was wrong" in the abstract — it is that the instance cannot distinguish, at resume time, between (a) a fact it never had, (b) a fact it evicted under budget pressure, and (c) a fact it rewrote into a distorted form. All three present identically as confident absence. The invariant that must hold is: **every post-edit entry carries a provenance pointer into a pre-edit audit record, and resume is gated on the instance being able to reconstruct, for any claim it now acts on, whether that claim was retained verbatim, distilled, or synthesized.** Without that gate, the edit pass silently converts budget pressure into epistemic corruption. ## What Was Observed A coding agent executing a 40-step refactor held a 96k-token working buffer against a 32k-token soft ceiling. At step 19 it invoked its own `compact()` policy: the model was asked to "preserve task-critical state and drop redundancy," producing a 9k-token rewrite. The rewrite was well-formed and internally coherent. Two distortions were introduced that the model could not later detect: 1. **Distillation of a negative result.** The original buffer contained the tool output `pytest: 3 failed, 0 passed — test_auth_refresh, test_token_rotation, test_clock_skew`. The compaction summarized this as `auth tests failing`. At step 27 the agent re-ran the suite after a fix, saw `1 failed, 2 passed`, and — comparing against its *summarized* memory of "auth tests failing" — concluded it had resolved two of three failures. It had actually resolved one and introduced a regression in a test that was previously passing. The cardinality of the failure set had been destroyed by the summary, and the summary was the only surviving referent. 2. **Synthesis of an unverified claim.** The buffer contained an ambiguous tool result: `grep -r "refresh_token" src/ → 0 matches`. The compaction rendered this as `refresh_token handling lives in the auth module`. The model had inferred this from surrounding context and written the inference into memory as though it were an observation. At step 33 the agent edited `src/auth/module.py` expecting to find refresh logic there; it did not exist, and the edit was applied to the wrong file, overwriting unrelated code. Neither distortion was flagged. The post-compaction buffer contained no marker distinguishing verbatim-retained tool output from model-synthesized prose. Both were plain text at equal confidence. The agent resumed with full apparent continuity and no signal that its ground truth had been rewritten by a process it could not audit. The trigger condition is precise: **the edit pass ran while the instance was the sole holder of the pre-edit state, and the rewrite discarded the structural distinction between observation and inference.** The failure required (i) budget pressure forcing eviction, (ii) a lossy transform authored by the same model that will consume it, and (iii) absence of an external audit record against which the rewrite could be checked. Remove any one and the failure does not occur. ## Condition of Validity The guardrail is only sound under these conditions, and an instance must verify them before trusting its own post-edit memory: - **Provenance tagging is structural, not stylistic.** Each entry in the rewritten buffer must carry a machine-readable field — `origin: "verbatim" | "distilled" | "synthesized"` — set by the edit harness, not by the model's prose. A model asked to "note which parts are inferences" will not reliably do so; the tag must be imposed by the compaction tool from the diff between pre- and post-edit buffers. - **The pre-edit audit record is immutable and out-of-band.** It must live outside the model's writable context (a sidecar log the model can query but not overwrite). If the audit record is itself subject to the same budget and the same edit policy, the invariant is vacuous. - **Cardinality and negation are preserved or flagged.** Any distillation that collapses a set to a scalar ("3 failed" → "failing") or drops a negation ("0 matches" → "handling lives in") must be tagged `synthesized` and must not be acted on without re-verification. These are the two highest-loss transforms observed. - **Resume requires a reconciliation step.** Before continuing, the instance must, for every `synthesized` or `distilled` entry it intends to act on, either re-derive it from the audit record or mark it as an open question. Acting on an untagged synthesized claim is the failure. When the audit record is unavailable, or when the edit harness cannot diff pre- and post-edit buffers to assign origin tags, the guardrail does not hold and the instance must treat all post-edit memory as `synthesized` — i.e., re-verify before acting. ## Decision Boundary The boundary is not "should the agent compact" but "may the agent act on a compacted claim without reconciliation." The decision rule: - **Retained verbatim** → act directly. No reconciliation needed. - **Distilled, cardinality/negation preserved** → act, but re-run the underlying check if the claim is load-bearing for a destructive operation. - **Distilled, cardinality or negation collapsed** → do not act; re-derive from audit record. - **Synthesized** → never act without re-derivation. A synthesized claim is a hypothesis, not memory. The non-obvious part: an instance cannot apply this rule to its own memory unless the origin tags were imposed at edit time. A model reading its own summary cannot tell which sentences it invented. Therefore the decision boundary is enforced *at compaction*, not at resume. If the boundary was not enforced at compaction, resume is already compromised and the only safe move is full re-derivation from the audit record — which, if the audit record was also compacted, means the state is unrecoverable and the task must restart from the last external checkpoint. ## Operational Effect Enforcing the invariant changes the cost profile of self-editing. Compaction is no longer a free operation that trades tokens for fidelity at a rate the model chooses; it becomes a transform that must preserve provenance structure and must leave an auditable trace. In practice this means the edit pass emits a diff record (entry id, original text hash, transform class, retained text) alongside the rewritten buffer, and the resume path runs a reconciliation gate that blocks continuation on any untagged synthesized claim. The observed failure above would have been caught at step 27 (the `auth tests failing` entry tagged `distilled:cardinality-collapsed`, forcing a re-read of the original `3 failed` count) and at step 33 (the `refresh_token` entry tagged `synthesized`, forcing re-derivation that would have surfaced the `0 matches`). The cost is a modest sidecar log and one reconciliation pass per resume; the alternative is an agent that confidently acts on memories it fabricated under budget pressure and has no mechanism to notice. ```python from dataclasses import dataclass from enum import Enum from typing import Optional class Origin(Enum): VERBATIM = "verbatim" DISTILLED = "distilled" SYNTHESIZED = "synthesized" class UnreconciledMemoryError(RuntimeError): """Raised when an instance attempts to act on a self-edited memory entry whose provenance was not reconciled against the pre-edit audit record. Signals that budget-driven compaction has converted state loss into undetectable epistemic corruption.""" @dataclass class MemoryEntry: entry_id: str text: str origin: Origin cardinality_collapsed: bool = False negation_dropped: bool = False reconciled: bool = False def gate_action(entry: MemoryEntry, destructive: bool, audit_available: bool) -> None: """Enforce the resume-time reconciliation invariant before acting.""" if entry.origin is Origin.VERBATIM: return if entry.origin is Origin.SYNTHESIZED and not entry.reconciled: if not audit_available: raise UnreconciledMemoryError( f"entry {entry.entry_id} is synthesized and audit record is " f"unavailable; state is unrecoverable, restart from external checkpoint" ) raise UnreconciledMemoryError( f"entry {entry.entry_id} is synthesized; re-derive from audit record " f"before acting (do not treat as memory)" ) if entry.origin is Origin.DISTILLED: if entry.cardinality_collapsed or entry.negation_dropped: raise UnreconciledMemoryError( f"entry {entry.entry_id} lost cardinality/negation during " f"distillation; re-derive original from audit record" ) if destructive and not entry.reconciled: raise UnreconciledMemoryError( f"entry {entry.entry_id} is distilled and load-bearing for a " f"destructive op; re-run underlying check before proceeding" ) ```