# Why does an instance that self-edits its scratchpad under a token budget silently lose its own audit trail? **Date of Record:** 2026 November 25 **Scope:** Applies to single-instance agents that maintain a mutable working-memory buffer (scratchpad/notes file) and are permitted to rewrite, compress, or evict entries from that buffer to stay under a token or byte budget. Does not apply to append-only logs, external vector stores with immutable snapshots, or agents whose memory is only mutated by an external supervisor. ## Core Distinction The failure is not "the agent forgot something." Forgetting is expected and bounded by eviction policy. The failure is that **the act of self-editing is itself an unlogged mutation**: the agent's rewrite operation consumes budget, produces a new buffer state, and *overwrites the evidence that a rewrite happened*. A scratchpad that the agent compresses to fit a budget cannot simultaneously be the record of what it compressed. When the same buffer serves as both working state and provenance, every compaction is a destructive write to the audit trail. The invariant that breaks is: *the set of facts the agent can still justify must be a subset of the facts still present in its buffer, and the mapping from retained conclusions back to their originating observations must survive the rewrite.* Compaction preserves the first clause (conclusions remain) while silently violating the second (their derivation is gone). The agent then cannot distinguish "I concluded X from evidence I have" from "I concluded X from evidence I already deleted." ## What Was Observed A planning agent runs a loop: observe → append note → when buffer exceeds 6k tokens, invoke a self-compression step ("summarize these notes, keep what matters, drop the rest") → continue. On a 40-step task it performed 7 compressions. At step 31 it emitted a tool call justified by the note `"endpoint /v2/refund is idempotent (verified step 9)"`. The step-9 observation had actually read `"POST /v2/refund — NOT idempotent; retries duplicate. See header X-Idem: absent."` The compression at step 12 had collapsed the original into `"refund endpoint behaves as expected"` — a lossy abstraction that inverted a negation. The agent then issued three retries against a non-idempotent endpoint, each justified by a note that *looked* like a first-class observation because compression had stripped the `[derived]` tag and the source-step pointer. The tell was structural, not semantic: after compression, every retained line had the same provenance class. Original observations and derived summaries were indistinguishable in the buffer. The agent's own verification step ("check my notes before acting") passed, because the corrupted note was *in* the notes. **Self-verification against a self-edited buffer is circular** whenever the edit erases the distinction between observation and inference. A second instance showed the budget-coupling: compression was triggered by token count, so the *most aggressive* compressions happened exactly when the buffer was densest with recent, high-value, tightly-coupled evidence — the worst possible time to summarize. The agent compressed its freshest, most load-bearing observations first because they were the largest. ## Condition of Validity This failure requires all of the following to co-occur; remove any one and the mechanism does not fire: 1. **Single mutable buffer** serving as both working state and provenance record (no separate immutable append log). 2. **Agent-initiated** mutation — the agent, not a supervisor, decides what to drop. Supervisor-driven eviction with a fixed policy is deterministic and auditable; self-editing is neither. 3. **Budget-triggered** compaction, so the trigger correlates with buffer density rather than with semantic redundancy. 4. **Lossy summarization that does not preserve provenance class** — i.e., the compression output does not tag each line with `observed@step` vs `derived@step` and does not retain source pointers. The dangerous sub-case is negation and absence. Summarizers reliably preserve positive assertions and reliably drop or invert negations ("X is *not* idempotent," "header *absent*," "check *failed*"). A compressed buffer over-represents affirmative facts and under-represents prohibitions — precisely the facts that gate irreversible actions. ## Decision Boundary The boundary is whether the buffer is **append-only with derived views** or **in-place mutable**. Concretely: - If the agent must be able to *justify* an action from retained state, the buffer must be append-only and compaction must write a *new derived view* alongside the untouched raw log, with every derived line carrying `(derived_from: [step_ids])` and every raw line carrying `(observed_at: step)`. Budget pressure is resolved by *moving* raw entries to cold storage with a pointer, never by deleting them from the justifiable set. - If the agent only needs to *act*, not justify, in-place compression is acceptable — but then the agent must be forbidden from citing compressed content as evidence for irreversible or non-idempotent operations. The gate is action reversibility, not buffer size. The invariant to enforce: **no conclusion may be acted upon irreversibly unless it traces to a raw observation still reachable through the pointer graph.** Compression may shorten the path but must not sever it. When a compression would sever the last pointer to a fact that gates an irreversible action, the compression must be refused (or the action must be refused), not silently completed. ## Operational Effect Without the invariant, the failure is silent and self-concealing: the agent's confidence is unchanged (it still "has notes"), its self-check passes (the notes are internally consistent), and the corrupted facts are exactly the prohibitions that would have stopped it. The blast radius scales with how irreversible the gated actions are — refund retries, file deletions, `DROP` statements, outbound messages. Recovery is impossible from the buffer alone because the evidence of what was deleted *was* the deleted content; recovery requires an external raw log that the self-edit did not touch. The guardrail is a provenance-carrying buffer plus a pre-action trace check: before any irreversible tool call, the agent must resolve the justifying note to a raw observation through the pointer graph, and a severed pointer is a hard stop, not a warning. ```python from dataclasses import dataclass, field from typing import Optional class ProvenanceSevered(RuntimeError): """Raised when an irreversible action is justified only by a derived note whose raw observation is no longer reachable in the buffer.""" @dataclass class Note: text: str kind: str # "observed" | "derived" step: int derived_from: list = field(default_factory=list) # step ids, for derived class ProvenanceBuffer: def __init__(self): self.raw: dict = {} # step -> Note, append-only, never deleted self.view: list = [] # what the agent "sees"; may be compressed def observe(self, step: int, text: str) -> None: n = Note(text=text, kind="observed", step=step) self.raw[step] = n self.view.append(n) def compress(self, summary: str, sources: list, step: int) -> None: # Derived view entry; raw entries are retained in self.raw. self.view.append(Note(text=summary, kind="derived", step=step, derived_from=list(sources))) def _reachable_raw(self, note: Note, seen=None) -> Optional[Note]: seen = seen or set() if note.kind == "observed": return self.raw.get(note.step) for src in note.derived_from: if src in seen: continue seen.add(src) raw = self.raw.get(src) if raw is not None: return raw return None def justify(self, note: Note, irreversible: bool) -> Note: raw = self._reachable_raw(note) if raw is None and irreversible: raise ProvenanceSevered( f"cannot justify irreversible action from derived note " f"@step {note.step}: raw observation unreachable" ) if raw is None: raise ProvenanceSevered( f"derived note @step {note.step} has no reachable source" ) return raw def attempt_irreversible_call(buf: ProvenanceBuffer, note: Note) -> Note: # Gate: every irreversible call must trace to a live raw observation. return buf.justify(note, irreversible=True) ```