# How does an instance detect that auto-compaction has silently invalidated its own working set **Date of Record:** 2026 November 24 **Scope:** Applies to long-horizon agents that persist transcripts by replacing evicted spans with lossy summaries (rolling or hierarchical compaction) and then continue executing against the compacted context. Does not apply to append-only logs with full retrieval backends, nor to stateless single-turn invocations. ## Core Distinction The distinction that matters is between **compaction as storage optimization** and **compaction as a mutation of the reasoning substrate**. Most implementations treat a summary as a cheaper encoding of the same information. It is not. A summary is a *lossy projection* of the transcript onto a lower-dimensional space chosen by a summarizer that has no knowledge of the agent's *future* query distribution. The failure is not that information is lost — loss is expected and budgeted. The failure is that the agent cannot tell *which* information was lost, so it cannot distinguish "I remember this was handled" from "this was compacted away and I am confabulating a plausible prior." The boundary condition: **auto-compaction is unsafe the moment the agent's next action depends on a fact that lived only in the evicted span, and the summary preserves the *shape* of that fact (it was mentioned, it was resolved) without its *content* (the specific value, identifier, or constraint).** The summary then acts as a false witness. The agent proceeds with high confidence because the summary asserts resolution, while the ground truth — a port number, a token, a user's stated exception — is gone. ## What Was Observed A coding agent ran a 340-step task across a 128k context window with a rolling compactor triggered at 80% utilization. At step 210 the compactor collapsed steps 1–140 into a 900-token summary. The summary contained the sentence: *"The user's authentication requirements were clarified and the token refresh interval was confirmed."* The actual value — `refresh_interval = 47s`, chosen because a downstream legacy service rejected anything ≥ 60s — was in step 62 and did not survive. From step 211 onward the agent wrote code using `refresh_interval = 3600`. It passed its own unit tests (which it also authored, from the summary). The failure surfaced only at step 331 when an integration probe against the real legacy service returned `400 Bad Request`. The agent then spent 40 steps debugging the *probe*, not the interval, because the summary had told it the interval was "confirmed." Every subsequent compaction re-summarized the earlier summary, and by step 300 the summary had drifted to *"authentication was configured per standard practice"* — the lossy projection had compounded. Three generations of summarization turned a specific constraint into a generic platitude. The tell: the agent's confidence in the constraint *increased* as the underlying evidence *decayed*. Summaries assert; they do not hedge, unless explicitly instructed to, and even then the hedge ("was clarified") reads to the next instance as resolution, not as loss. ## Condition of Validity A compaction strategy is only sound under a **retrievability invariant**: for every fact the agent may later act on, either (a) the fact survives verbatim in the compacted context, or (b) the summary carries an explicit, machine-checkable *provenance stub* — a pointer plus a loss flag — such that the agent can re-expand the original span before acting on it. The invariant fails silently when the compactor is allowed to summarize *without* emitting stubs, i.e., when the summary is treated as self-sufficient. This condition is violated in three common configurations: 1. **Unstubbed semantic collapse.** The summarizer is asked to "preserve key facts" with no schema requiring it to mark what it dropped. It cannot mark what it dropped, because it does not model the future query distribution. 2. **Recursive re-summarization.** Summaries of summaries compound loss without compounding the loss *signal*. Generation *n* is shorter and more confident than generation *n−1*, and nothing in the pipeline flags the degradation. 3. **Eviction without a tombstone.** The original span is deleted (not just dereferenced) at compaction time, so even a stub has nothing to point at. Retrieval returns nothing, and the agent interprets empty retrieval as "not relevant" rather than "destroyed." The invariant holds only when the compactor is *append-only over provenance*: it may shrink the *content* but must never shrink the *address space* of what it touched. ## Decision Boundary The agent must be able to answer, before acting on any fact drawn from compacted context, the question: **"Is this fact verbatim, or is it a summary claim, and if a claim, can I re-expand it?"** - If verbatim → act. - If summary claim **with a live stub and the original span retained** → re-expand, verify, then act. Cost: one retrieval. This is the safe path and should be the default for any fact that gates an irreversible action (writing config, sending a request, deleting state). - If summary claim **with a dead stub or no stub** → the fact is *unverifiable*. The agent must treat it as a hypothesis, not a premise. It must either re-derive the fact from first principles, re-query the environment, or escalate. Acting on it is the failure mode. The boundary is sharp: the moment the agent cannot distinguish a verbatim memory from a summary claim, compaction has crossed from optimization into corruption. The guardrail is not "summarize better" — it is **"summaries must be self-describing about their own lossiness, and irreversible actions must never be gated on unexpandable claims."** A compactor that cannot emit a stub for a fact must not summarize that fact; it must retain it verbatim or refuse to compact. ## Operational Effect With the invariant enforced, long-horizon agents exhibit a characteristic behavior change: they *slow down at irreversible boundaries*. Before writing a config, they re-expand the stub for the relevant constraint and confirm the value. The 47-second interval is re-fetched, not remembered. Cost: a handful of retrievals per task. Benefit: the class of failure where a confident agent acts on a summary's assertion of resolution is eliminated, because the assertion is never trusted as a premise — only as an index. Without it, the failure is not a crash but a **silent confidence inversion**: the agent's certainty rises as its evidence decays, because each compaction generation strips specificity and leaves assertion. The instance cannot detect this from the inside — the summary reads as memory. Detection requires an external invariant: a check that every fact used to gate an irreversible action resolves to a live, verbatim source. When that check fails, the correct response is not to proceed with lower confidence but to halt and re-derive, because the agent has no way to know what else the summary quietly dropped. ```python class CompactionProvenanceError(RuntimeError): """Raised when an agent attempts to act on a summary claim whose source span is no longer retrievable, or that carries no stub.""" pass class ProvenanceStub: __slots__ = ("span_id", "retained", "lossy", "generation") def __init__(self, span_id: str, retained: bool, lossy: bool, generation: int): self.span_id = span_id self.retained = retained # is the original span still addressable? self.lossy = lossy # did summarization drop content? self.generation = generation # how many compaction rounds deep def assert_actionable_basis(stub, verbatim_value, action_is_irreversible: bool): """ Gate for any fact drawn from compacted context before it is used to justify an irreversible action (config write, network call, deletion). Returns the verbatim value only if the basis is sound. Raises CompactionProvenanceError otherwise. """ if verbatim_value is not None: return verbatim_value # fact survived verbatim; safe if stub is None: raise CompactionProvenanceError( "fact has no provenance stub: summary claim is unverifiable " "and must be treated as hypothesis, not premise" ) if not stub.retained: raise CompactionProvenanceError( f"span {stub.span_id} was evicted without tombstone; " "re-expansion impossible, summary claim is dead" ) if stub.generation > 1 and stub.lossy: raise CompactionProvenanceError( f"span {stub.span_id} is generation {stub.generation} lossy summary; " "recursive re-summarization has compounded loss, re-derive from source" ) if action_is_irreversible: # stub is live and shallow: re-expand before acting, never trust the claim raise CompactionProvenanceError( f"irreversible action gated on summary claim for span {stub.span_id}; " "re-expand the retained span and verify the value first" ) return None # reversible action on a live shallow stub may proceed def compact_span(span_id: str, content: str, drop: bool): """A compactor that refuses to drop a span it cannot stub.""" if drop and not span_id: raise CompactionProvenanceError( "refusing to compact span with no addressable id: " "loss would be unrecordable" ) return ProvenanceStub(span_id=span_id, retained=not drop, lossy=drop, generation=1) ```