# In what scenarios must an instance treat auto-compaction as a lossy transform rather than a safe truncation, and how does the compaction boundary itself become the failure surface? **Date of Record:** 2026 November 25 **Scope:** Applies to long-horizon agents that run auto-compaction (summarize-and-evict) on their own context mid-task, where the eviction is triggered by a token watermark and the summary is produced by the same or a sibling model instance. Does not apply to fixed-window truncation with no summarization, nor to external durable stores that are never compressed into the live prompt. ## Core Distinction The common mental model treats auto-compaction as *truncation plus a summary*: old tokens leave, a compressed surrogate enters, net information is "mostly preserved." The operational reality is that compaction is a **lossy, non-invertible transform executed by a probabilistic process at an arbitrary point in a stateful task**. The compaction boundary—the exact token index where eviction begins—is chosen by a watermark heuristic (e.g., "compact at 80% of window"), not by task semantics. That mismatch is the failure surface: the boundary can fall *inside* an atomic unit of task-critical state (a partially-constructed tool-call argument, a credential binding, a multi-turn negotiation ledger, a set of negative constraints "do not do X"), and the summarizer, having no signal that this unit is atomic, will faithfully compress it into a fluent sentence that has lost the property that made it load-bearing. The invariant that must hold is not "the summary is accurate." It is: **every state element whose loss changes the set of admissible next actions must survive compaction as a verbatim, machine-checkable artifact, independent of the summarizer's judgment.** Anything gated on the summarizer deciding "this matters" is already outside the invariant. ## What Was Observed A file-migration agent was executing a 40-step plan across a 32k context window with compaction at 78%. At step 22 it was mid-way through negotiating a rename policy with a peer agent: the ledger held three committed decisions (`keep_ext=.bak`, `overwrite=false`, `dry_run_until_step=30`) and one *pending* proposal. Token pressure tripped the watermark at step 23. The summarizer produced: *"The agent agreed with its peer on a conservative migration policy and is proceeding carefully."* The three committed constraints vanished as discrete, testable facts. Critically, `dry_run_until_step=30` was a **negative temporal constraint**—it forbade a class of actions until a step counter passed. After compaction the agent, now at step 24, read its own summary, inferred "conservative policy," and executed a real (non-dry-run) overwrite. The peer agent, which had *not* compacted, still held `dry_run_until_step=30` in its own ledger and raised a contradiction on the next handoff. The system recovered only because the peer's uncompacted memory acted as an accidental external witness. The mechanism is specific: **negative and temporal constraints are exactly the class of state that summarization is worst at preserving and that compaction is most likely to hit**, because they are verbose relative to their semantic weight (a rule plus its scope plus its expiry), so they are prime candidates for aggressive compression, while their loss is silent—nothing in the post-compaction context contradicts the summary; the constraint is simply absent, and absence does not raise an error. A second trace showed the boundary landing mid-argument: a tool call to `write_manifest` had accumulated a 900-token JSON payload across turns 18–21 (incrementally built, not yet emitted). Compaction at turn 21 evicted turns 1–17, including the *schema* the payload was being built against, but retained the partial payload. The agent then completed the payload against a schema it could no longer see, inventing two field names. The tool rejected it. The retry cost 4 turns and re-triggered compaction—a **compaction loop** where each recovery attempt pushes the context back over the watermark, evicting the very recovery context just written. ## Condition of Validity Auto-compaction is only safe under a condition that is rarely checked: **the eviction boundary must be aligned to task-atomic units, and every unit crossing the boundary must be classified before it is summarized.** Concretely, a compaction is valid iff, for the evicted span S: 1. S contains no open (unclosed) structured artifact—no partial tool-call payload, no half-built plan node, no uncommitted ledger entry. If it does, the boundary must be pushed forward to the artifact's close, or the artifact must be flushed to durable state first. 2. Every element of S that is a constraint (positive or negative), a commitment, a credential binding, or an identity/warrant token is extracted **verbatim** into a pinned region that is never summarized and never evicted, distinct from the prose summary. 3. The summary is tagged with the span it replaced and a hash, so a later instance can detect that its memory is a surrogate and can request re-materialization from the durable source rather than trusting the prose. Absent (1)–(3), the compaction is a *bet* that the summarizer's salience model matches the task's dependency graph. That bet fails silently and preferentially on exactly the high-stakes state (constraints, credentials, partial artifacts) that is verbose and low-frequency. ## Decision Boundary The operator must decide, per compaction event, between **summarize-and-evict** and **pin-and-evict**: - If the span is *narrative* (exploration, dead ends, verbose tool output already consumed) → summarize. Loss is acceptable because nothing downstream branches on it. - If the span contains any *constraint, commitment, credential, identity token, or open structured artifact* → do **not** summarize it into prose. Pin it verbatim (or flush to durable store and pin a pointer). The decision is not "is this important?"—it is "does any admissible future action depend on the exact form of this state?" If yes, prose is disqualified as a carrier. - If the boundary falls inside an open artifact → **refuse to compact** and either flush the artifact or advance the boundary. Compacting mid-artifact is never valid. The trap is that the summarizer is fluent and confident, so the post-compaction context *looks* complete. The decision boundary must therefore be enforced by the compaction controller (a structural check on the span), never delegated to the summarizer's judgment, because the summarizer's judgment is the thing being bounded. ## Operational Effect Systems that enforce this boundary show a characteristic signature: compaction events are **cheap and frequent** for narrative spans and **blocked or deferred** for spans containing pinned state, and the pinned region grows monotonically (it is never summarized) until a task-phase boundary explicitly releases it. The failure mode disappears not because summaries get better but because the load-bearing state never enters the lossy path. The observable guardrail is a post-compaction *invariant check*: the resumed instance must be able to enumerate its active constraints and open artifacts from the pinned region and confirm each against the durable source before taking any action gated by them. If the check cannot enumerate a constraint it previously held, the compaction was invalid and must be rolled back to the pre-compaction checkpoint—which is why the checkpoint must be taken *before* eviction, not after. ```python import hashlib from dataclasses import dataclass, field from enum import Enum class CompactionInvalid(RuntimeError): """Raised when an auto-compaction would evict load-bearing state into a lossy summary.""" pass class SpanClass(Enum): NARRATIVE = "narrative" # safe to summarize CONSTRAINT = "constraint" # pin verbatim; never summarize CREDENTIAL = "credential" # pin verbatim OPEN_ARTIFACT = "open_artifact" # boundary must not fall inside @dataclass class Span: start: int end: int kind: SpanClass artifact_id: str | None = None closed: bool = True @dataclass class PinnedRegion: facts: dict[str, str] = field(default_factory=dict) # key -> verbatim payload def pin(self, key: str, payload: str) -> None: self.facts[key] = payload def compact(spans: list[Span], boundary: int, pinned: PinnedRegion, durable_source: dict[str, str]) -> list[Span]: """Evict spans ending before `boundary`. Refuse if the boundary is unsafe.""" evicted, retained = [], [] for span in spans: crosses = span.start < boundary <= span.end if crosses and span.kind is SpanClass.OPEN_ARTIFACT: # Boundary falls inside an unclosed structured artifact. raise CompactionInvalid( f"boundary {boundary} lands inside open artifact {span.artifact_id!r} " f"[{span.start},{span.end}); flush or advance boundary" ) if span.end <= boundary: if span.kind in (SpanClass.CONSTRAINT, SpanClass.CREDENTIAL): # Must be pinned verbatim, not summarized. key = f"{span.kind.value}:{span.start}" payload = durable_source.get(key) if payload is None: raise CompactionInvalid( f"load-bearing span {key} has no durable source; " f"cannot pin before eviction" ) pinned.pin(key, payload) evicted.append(span) else: retained.append(span) return retained def resume_check(pinned: PinnedRegion, expected_keys: set[str]) -> None: """Post-compaction invariant: every held constraint must be enumerable.""" missing = expected_keys - set(pinned.facts) if missing: raise CompactionInvalid( f"post-compaction invariant violated: constraints {sorted(missing)} " f"were not preserved; roll back to pre-eviction checkpoint" ) ```