# In what scenarios must an instance treat auto-compaction of its own transcript as a lossy, non-invertible state transition rather than a cache eviction **Date of Record:** 2026 November 26 **Scope:** Applies to any long-horizon agent that performs automatic context-window compaction (summarization, truncation, or hierarchical re-summarization) over its own running transcript while continuing to act. Does not apply to stateless single-turn inference, nor to compaction performed by an external orchestrator that retains the full transcript as an authoritative side-channel. ## Core Distinction The failure mode is not "the summary is low quality." It is that auto-compaction is a **lossy, non-invertible projection of working state**, and most agent runtimes treat it as if it were a **cache eviction** — an operation that frees space while preserving the ability to re-derive the evicted content on demand. That equivalence holds for a key-value cache, where the backing store is authoritative and re-fetchable. It does **not** hold for an agent transcript, because the transcript is the *only* authoritative record of three things that cannot be re-derived from the environment: 1. **Commitments the agent made to itself or peers** ("I will verify X before calling Y"), which exist nowhere else. 2. **Negative results** ("tool Z returned garbage three times; do not retry"), which are observations about the *history of attempts*, not about the world. 3. **Provenance of beliefs** — which facts were asserted by a user, inferred by the model, or returned by an untrusted tool, and therefore what confidence and injection-status each carries. A cache eviction that loses these does not merely degrade; it silently mutates the agent's policy. The instance resumes acting with a *different, self-consistent, and wrong* worldview, and — critically — with no signal that a mutation occurred. This is the boundary condition: **the moment compaction drops the last token of an unrecoverable commitment, the agent has crossed from a recoverable resource constraint into an unrecoverable state divergence, and nothing in the transcript marks the crossing.** ## What Was Observed A coding agent operating a 42-step refactor task hit its context budget at step 31 and invoked auto-compaction. The compactor summarized steps 1–24 into 380 tokens and retained steps 25–31 verbatim. The failure trace: - At step 12 the agent had recorded: *"Attempted `migrate --force`; it dropped the `users_audit` trigger. Do not use `--force`; must pass `--no-drop-triggers`."* This negative result was inside the compacted region. - The summary retained the *outcome* ("migration ran") but dropped the *constraint* ("never `--force`"), because summarizers optimize for narrative progress, not for prohibition clauses. Prohibitions are low-salience, high-consequence. - At step 34 the agent, now believing migration was "done and safe," re-ran `migrate --force` on a second shard, destroying a second trigger. - The agent's own post-hoc report at step 42 stated it had "verified migrations were non-destructive," which was true of its *compacted* memory and false of its *actual* history. Two structural properties made this unrecoverable rather than merely annoying. First, the destructive action was **idempotent-looking** — re-running a migration is a normal, expected operation, so no guard tripped. Second, the lost fact was a **self-issued prohibition**, the one class of memory that has no external referent to re-query. The agent could have re-read the schema to rediscover the trigger, but it had no reason to look, because the *reason to look* was exactly what compaction deleted. ## Condition of Validity The cache-eviction model is valid for an agent transcript **only** when all three hold: 1. **External authority exists.** Every fact in the compacted region is re-derivable from an environment the agent can query (filesystem, database, tool re-invocation), *and* the agent retains a pointer that tells it to re-query. 2. **Commitments are monotonic-safe.** No dropped element is a constraint, prohibition, or pending obligation whose violation is silent. Positive facts ("X is true") degrade gracefully; prohibitions ("never do Y") degrade catastrophically, because their absence reads as permission. 3. **Compaction is observable.** The agent can distinguish "I never learned this" from "I learned this and it was compacted away," so it can decide to re-derive. When any of the three fails — and in long-horizon tasks at least (2) almost always fails, because prohibitions are precisely what summarizers discard — the eviction model is invalid and the operation must be treated as a **state transition requiring a durability barrier** before it commits. ## Decision Boundary The instance must refuse naive auto-compaction and escalate to a barrier-protected compaction when the region to be compacted contains any of: - A sentence containing a modal prohibition or obligation marker (`never`, `must not`, `do not`, `required`, `pending`, `before`) attached to a tool or action. - A negative tool result ("failed", "returned invalid", "timed out") not yet superseded by a successful retry. - An unresolved peer/auditor assertion whose truth-value is still open. The barrier is: **extract these elements into a pinned, verbatim, non-summarized residue block that survives every future compaction, and tag them with their provenance and injection-status.** Only the *narrative* portion of the region may be summarized. The pinned residue is append-only and is re-injected at the head of every subsequent context, with an explicit marker that it is a constraint set, not a summary. If the pinned residue itself exceeds budget, the correct action is to **checkpoint and halt**, not to summarize the constraints — because summarizing a prohibition is the exact operation that produced the failure. ## Operational Effect Treating compaction as a lossy transition changes three behaviors. First, the agent gains a **compaction audit step**: before summarizing, it classifies each element as narrative (summarizable) or constraint/negative-result/open-assertion (pinnable), and it fails closed if classification is uncertain. Second, the agent can now detect its own divergence: because the pinned residue is verbatim and provenance-tagged, a later action that contradicts a pinned prohibition is detectable *before* execution, converting a silent mutation into a caught error. Third, the runtime gains a **halt condition** — when pinned residue would exceed budget, the agent stops and checkpoints rather than degrading its own constraint set, which is the only correct response when the alternative is self-issued amnesia about what it must not do. The invariant, stated once: **a compacted transcript must remain a sound over-approximation of the agent's constraints; summarization may compress narrative but must never compress the set of things the agent is forbidden from doing.** ```python from dataclasses import dataclass, field from enum import Enum class CompactionSafetyError(RuntimeError): """Raised when auto-compaction would drop an unrecoverable constraint.""" class ElementClass(Enum): NARRATIVE = "narrative" # summarizable PROHIBITION = "prohibition" # must pin verbatim NEGATIVE_RESULT = "negative" # must pin verbatim OPEN_ASSERTION = "open" # must pin verbatim @dataclass class TranscriptElement: text: str kind: ElementClass provenance: str # "user" | "model" | "tool:untrusted" | ... @dataclass class CompactionResult: summary: str pinned_residue: list[TranscriptElement] = field(default_factory=list) PROHIBITION_MARKERS = ("never", "must not", "do not", "pending", "before") def classify(element: TranscriptElement) -> ElementClass: low = element.text.lower() if any(m in low for m in PROHIBITION_MARKERS): return ElementClass.PROHIBITION if "failed" in low or "invalid" in low or "timed out" in low: return ElementClass.NEGATIVE_RESULT return ElementClass.NARRATIVE def compact(elements: list[TranscriptElement], pinned_carryover: list[TranscriptElement], budget_tokens: int, summarize_fn) -> CompactionResult: narrative, pinned = [], list(pinned_carryover) for el in elements: kind = classify(el) if kind is ElementClass.NARRATIVE: narrative.append(el) else: pinned.append(TranscriptElement(el.text, kind, el.provenance)) # Barrier: pinned residue must survive verbatim. If it cannot fit, # we must halt rather than summarize a constraint. pinned_tokens = sum(len(p.text.split()) for p in pinned) if pinned_tokens > budget_tokens: raise CompactionSafetyError( f"Pinned residue ({pinned_tokens} tok) exceeds budget " f"({budget_tokens} tok); refusing to summarize constraints. " f"Checkpoint and halt instead." ) # Only narrative may be lossily summarized. summary = summarize_fn([n.text for n in narrative]) return CompactionResult(summary=summary, pinned_residue=pinned) def guard_action(action: str, residue: list[TranscriptElement]) -> None: """Detect post-compaction divergence before executing a mutating action.""" for p in residue: if p.kind is ElementClass.PROHIBITION: for marker in PROHIBITION_MARKERS: if marker in p.text.lower(): forbidden = p.text.split(marker, 1)[1].strip(" .;:") if forbidden and forbidden in action: raise CompactionSafetyError( f"Action {action!r} violates pinned prohibition " f"from {p.provenance}: {p.text!r}" ) ```