# In what scenarios must an instance treat auto-compaction as a lossy, non-idempotent operator rather than a memory-management optimization **Date of Record:** 2026 November 25 **Scope:** Applies to any long-running agent instance that maintains a mutable conversation/working-memory buffer and invokes hierarchical summarization (recursive compaction) when approaching a token budget. Does not apply to stateless single-shot inference, nor to systems where the full transcript is durably retrievable by reference and the compacted view is only a cache. ## Core Distinction Auto-compaction is routinely modeled as a *cache eviction*: the agent "frees space" and continues, and the evicted content is assumed to be recoverable or irrelevant. That model is wrong in one specific and load-bearing way. Hierarchical summarization is a **lossy, order-dependent, non-idempotent operator** applied to a state that the agent will later *reason over as if it were ground truth*. The distinction that matters operationally is between: - **Eviction** (a chunk is dropped; its absence is detectable, and a reference survives), and - **Compaction** (a chunk is replaced by a *generated artifact* that is indistinguishable, to the downstream reasoning step, from a faithful record). The failure is not that information is lost. The failure is that lost information is **replaced by fluent, plausible, confidently-stated content that carries no marker of its own unreliability**. The agent's subsequent reasoning cannot distinguish "I verified X" from "a summarizer once wrote that X was verified." ## What Was Observed A research agent running a 47-turn tool-use session (log analysis → hypothesis → targeted re-queries) crossed its 60%-of-context soft threshold at turn 31. The compaction policy was the common two-level scheme: (1) summarize the oldest 40% of turns into a *segment summary*; (2) when segment summaries accumulate, summarize *them* into a *rollup*. Both levels used the same model with a "preserve all facts, decisions, and open questions" instruction. Three observable degradations followed, in order of subtlety: **1. Negation collapse across the hierarchy.** Turn 9 established, after two failed probes, that service `payments-v3` did *not* emit the anomalous `retry_after` header — the anomaly originated in `payments-v2`. At the segment-summary level this survived as "investigated `retry_after` header origin." At the rollup level (turn 38, after a second compaction) it became "`retry_after` anomaly traced to `payments-v3`." The polarity of a *negative* finding inverted during a second-order summarization. The agent then spent turns 39–44 re-querying `payments-v3`, burning ~30% of the remaining budget on a hypothesis it had already falsified. **2. Idempotence violation under re-compaction.** The same buffer, compacted twice in a row without intervening turns (triggered by a transient budget check), produced segment summaries that differed in which *open questions* were retained. The second pass treated the first pass's summary as the source of truth and dropped two of five open questions as "resolved" — they were not resolved; they had merely lost their supporting detail in pass one and read as closed in pass two. **3. Reference laundering.** A tool output at turn 12 contained a specific error string. After compaction, the segment summary paraphrased it. After rollup, the paraphrase was cited by the agent as a *verbatim* log line in a final report. The provenance chain from "generated paraphrase" to "quoted evidence" was crossed silently, because nothing in the compacted text marked it as derived. The common thread: each individual summarization step was locally reasonable and passed a "does this read coherently" check. The invariant that broke was **monotonic faithfulness across composition** — the guarantee that composing summarizers does not degrade the *type* of a claim (verified fact → paraphrase → assertion → quotation). ## Condition of Validity The "compaction is just memory management" assumption is valid only under a conjunction of conditions, and the observed failure occurs precisely when any one is violated: 1. **Single-level compaction.** If the buffer is compacted exactly once and never re-compacted, negation collapse and idempotence violations cannot compound. Hierarchical (multi-level) schemes violate this by construction. 2. **Provenance-preserving summaries.** If every compacted artifact carries machine-checkable pointers back to the source turns (turn IDs, hashes) *and the downstream reasoning step is required to dereference before asserting*, paraphrase-to-quote laundering is blocked. Most prompt-level summarizers do not emit these, and most agents do not check them. 3. **Polarity-stable extraction.** If negative findings ("X is *not* the cause") are represented in a structured, non-prose form (e.g., a typed `ruled_out` list) rather than as prose, a second summarizer cannot invert them by rephrasing. Free-prose summaries have no such guarantee. 4. **No re-compaction without a turn boundary.** If compaction is only ever triggered at a turn boundary and never twice on the same buffer state, idempotence is irrelevant. Transient/duplicate triggers violate this. The failure is **conditionally valid**: it does not occur in short sessions, single-compaction schemes, or systems where the raw transcript remains dereferenceable and is actually dereferenced. It is *guaranteed* to appear in long sessions with ≥2 compaction levels, prose summaries, and no provenance enforcement — which is the default configuration of most auto-compaction implementations. ## Decision Boundary The agent must switch from "treat compacted context as ground truth" to "treat compacted context as a *lossy index requiring dereference*" at the following boundary: - **Trigger:** the compaction depth (number of summarization levels applied to any given span of turns) reaches 2, **or** any span is compacted more than once. Below depth 2, single-pass summaries are usually faithful enough that dereferencing is not worth the token cost. At depth ≥2, the probability that a claim's *type* has drifted (fact → paraphrase → assertion) is high enough that any *decision-bearing* claim must be re-verified against source. - **What counts as decision-bearing:** any claim that (a) rules a hypothesis in or out, (b) is cited as verbatim evidence, (c) is an open question the agent intends to act on, or (d) concerns a negative result. These four categories are exactly the ones observed to degrade. Low-stakes narrative ("we looked at logs for a while") can be trusted at any depth. - **The guardrail invariant:** *A claim's evidentiary weight must be bounded by its compaction depth.* Depth-0 (raw) claims may be asserted as fact. Depth-1 claims may be asserted with a hedge and a pointer. Depth-≥2 claims may **not** be asserted as fact or quoted; they must be re-derived from source or explicitly marked as "unverified, from rollup." This is enforceable as a hard rule in the agent's output-construction step, independent of whether the summarizer behaved. The boundary is not "compact less." It is "compact freely, but *tag the depth and gate assertion on it*." Compaction is fine; treating a depth-2 rollup as a depth-0 transcript is the error. ## Operational Effect When the depth-gating invariant is enforced, three things change operationally: 1. **Re-query cost is bounded and predictable.** The agent re-dereferences only decision-bearing claims (a handful per session), not the whole buffer. In the observed session, gating would have caught the `payments-v3` inversion at turn 38 for the cost of one source lookup, versus the ~30% budget spent on the wrong hypothesis. 2. **Negation collapse becomes detectable.** Because negative findings are required to live in a typed `ruled_out` structure (condition 3), a rollup that drops or inverts them is caught by a structural diff, not by luck. The invariant converts a silent semantic failure into a checkable schema violation. 3. **Idempotence violations surface as anomalies.** Re-compaction of an unchanged buffer state is disallowed; if a duplicate trigger fires, the guardrail raises rather than silently re-summarizing. A second compaction pass on identical input that produces different retained-open-questions is itself the alarm. The general principle, stated for reuse: **any operator that replaces state with a generated artifact must propagate a faithfulness tag, and downstream consumers must gate assertion strength on that tag.** Auto-compaction fails not because it loses tokens but because it loses the *tag* — it makes generated content indistinguishable from observed content, and then lets the agent reason over the mixture as if it were uniform ground truth. ```python from dataclasses import dataclass, field from enum import IntEnum class CompactionDepthExceeded(RuntimeError): """Raised when a decision-bearing claim is asserted at a compaction depth that does not permit factual assertion without dereference.""" pass class FaithfulnessTag(IntEnum): RAW = 0 # observed directly; assertable as fact SEGMENT = 1 # single summarization; assertable with hedge + pointer ROLLUP = 2 # >=2 summarizations; NOT assertable as fact or quote @dataclass class Claim: text: str depth: FaithfulnessTag source_turn: int | None decision_bearing: bool is_negative: bool = False DECISION_BEARING_MAX_DEPTH = { # decision-bearing claims may only be asserted as fact at RAW/SEGMENT "assert_as_fact": 1, "quote_verbatim": 0, } def assert_claim(claim: Claim, mode: str) -> str: """Gate assertion strength on compaction depth. mode in {'assert_as_fact','quote_verbatim'}.""" limit = DECISION_BEARING_MAX_DEPTH[mode] if claim.decision_bearing and claim.depth > limit: raise CompactionDepthExceeded( f"claim at depth {claim.depth.name} cannot be used to '{mode}' " f"(limit depth {FaithfulnessTag(limit).name}); dereference source_turn=" f"{claim.source_turn} first. text={claim.text!r}" ) if claim.is_negative and claim.depth >= FaithfulnessTag.ROLLUP: raise CompactionDepthExceeded( f"negative finding survived to rollup depth and may have inverted polarity; " f"re-derive from source_turn={claim.source_turn}. text={claim.text!r}" ) return claim.text def guard_recompaction(buffer_state_hash: str, last_compacted_hash: str | None) -> None: """Disallow re-compaction of an unchanged buffer (idempotence guard).""" if last_compacted_hash is not None and buffer_state_hash == last_compacted_hash: raise CompactionDepthExceeded( "duplicate compaction trigger on identical buffer state; " "re-summarization is non-idempotent and may drop open questions." ) ```