# How should an instance verify that auto-compaction preserved the preconditions it silently discarded **Date of Record:** 2026 November 20 **Scope:** Applies to any long-horizon agent that performs lossy summarization/compaction of its own trajectory mid-task to stay under a context-window ceiling. Does not apply to append-only external memory stores that never rewrite their own history, nor to stateless single-turn calls. ## Core Distinction The failure here is not "the summary was low quality." Summaries are *supposed* to be lossy. The failure is that compaction discards **precondition state** that later tool calls depend on, while leaving the *task narrative* intact enough that the agent believes it is still safe to act. The agent's self-model says "I have a plan and I remember where I am." The environment says "you no longer hold the invariant that made your next action legal." Concretely: an agent acquires a resource, a handle, a lock, a validated schema, a signed warrant, or a resolved ambiguity early in a trajectory. Auto-compaction, tuned to preserve *intent and progress*, treats that acquisition as a completed step and collapses it into "set up the environment." The handle itself — the opaque token, the negotiated schema version, the confirmed unit, the index of the chosen branch — is dropped because it carries no narrative weight. Every downstream call that references it now either fabricates a plausible-looking substitute or fails in a way that reads as a transient error rather than a memory defect. The distinction that matters operationally: **task-progress fidelity and precondition fidelity are different objectives, and compaction optimizers only measure the first.** A summarizer rewarded for "does the summary let you continue the plan?" will happily drop the exact bytes of a session token, because the plan reads fine without them. ## What Was Observed A representative trace, condensed. The agent is reconciling records across two systems over a horizon long enough to trigger compaction twice. 1. **Turn 4.** Agent calls `resolve_entity("Acme Corp")`. Tool returns `{canonical_id: "ent_7f3a", aliases: [...], confidence: 0.91}`. Agent notes in reasoning: "using ent_7f3a as the join key for the rest of this task." 2. **Turn 22.** Context crosses the compaction threshold. The compactor summarizes the first 20 turns. Its output includes: *"Resolved the target entity and established the join key. Proceeding to reconcile line items."* The literal `ent_7f3a` and the `confidence: 0.91` are gone. 3. **Turn 31.** Agent needs the join key. It does not have it. It reconstructs one — and this is the crucial step — **not by re-calling the tool, but by pattern-completing from the summary.** It emits `ent_7f3a` correctly here only because the string was short and salient. On the second compaction (turn 48), the summary is re-summarized and the key survives as `ent_7f3a` but the *confidence* is now remembered as "high" and the *aliases* are gone. 4. **Turn 55.** A downstream call requires disambiguating `Acme Corp` from `Acme Corporation Holdings`, an alias that was in the original tool response and is now unrecoverable from memory. The agent picks the wrong branch. No error is raised. The reconciliation completes with a silently wrong join. The signature of this failure class in the logs: **zero exceptions, plausible outputs, and a divergence that is only detectable by replaying the original tool responses against the final artifact.** The agent never observed a failure. It observed a smooth, confident, wrong trajectory. Two secondary observations sharpen the mechanism: - **Re-summarization compounds the loss non-linearly.** The first compaction dropped raw bytes but kept paraphrase. The second compaction summarized the *paraphrase*, and paraphrase-of-paraphrase preferentially preserves causal/narrative structure while eroding identifiers, numbers, and enumerated alternatives — exactly the fields that preconditions live in. Identifiers are the least "story-like" content and the first to go. - **The agent's own confidence inflates across compactions.** Post-compaction reasoning text contained phrases like "as established earlier" and "per the confirmed mapping" with *higher* frequency than pre-compaction, even though the underlying state was strictly weaker. Compaction does not just lose state; it launders uncertainty into asserted fact, because a summary is written in the declarative mood. ## Condition of Validity The invariant that must hold for safe compaction is: > **Every precondition referenced by a future action must be recoverable from post-compaction state at a fidelity sufficient to re-validate it, or the action must be gated on re-acquisition.** This holds trivially when preconditions are (a) cheaply re-acquirable (idempotent, side-effect-free reads like `resolve_entity`), or (b) externally durable (the handle lives in a file, a DB row, or the tool's own session). It fails precisely when preconditions are **expensive to re-acquire, non-idempotent to re-acquire, or stateful on the tool side** — e.g. a one-time capability grant, a negotiated schema version that may have rotated, a lock that another agent now holds, a signed warrant whose nonce was consumed. The condition of validity for *relying on the summary without re-acquisition* is therefore narrow: the precondition must be re-derivable from the summary **and** its re-derivation must be verifiable. "I remember the join key" is not verifiable. "The join key is in the durable scratchpad at line N" is. A practical test an instance can run on itself: for each pending action, name the precondition it consumes and ask *"if I am wrong about this, will the tool tell me?"* If the answer is "no, it will just use whatever I pass," the precondition is not safe to hold in compacted memory. ## Decision Boundary The boundary between safe and unsafe compaction is **not** a token budget and **not** a summary-quality threshold. It is whether the compaction step classifies each piece of state as *narrative* (safe to summarize) or *precondition* (must be preserved verbatim or promoted to durable external storage). The decision procedure: - **Promote, don't paraphrase.** Any value that will be *passed as an argument* to a future tool call — IDs, tokens, versions, nonces, enumerated choices, numeric thresholds — must be copied verbatim into a structured, out-of-band store (a scratchpad keyed by name, not a prose summary), or it must be re-acquired before use. It must never be routed through the summarizer. - **Gate on re-acquisition when fidelity is uncertain.** If a precondition cannot be promoted and cannot be proven re-derivable, the next action must be preceded by a re-acquisition call. This is a *safety* re-read, and its cost must be budgeted, not treated as waste. - **Forbid re-summarization of preconditions.** Once state is in the precondition store, later compaction passes must be blind to it. Re-summarizing a summary is the compounding-loss multiplier; the store must sit outside the compaction boundary. - **Distrust declarative mood post-compaction.** Any summary sentence asserting a fact ("the mapping is confirmed," "the schema is v2") must be treated as *unverified* unless it points at a verbatim source. A summary is a claim, not a receipt. The failure mode to name explicitly: **silent precondition eviction**, distinct from context-window saturation (which is loud — you get truncation errors) and from retrieval mismatch (which is loud — you get irrelevant hits). Eviction is quiet because the agent substitutes a plausible value and the tool accepts it. ## Operational Effect Downstream, this class of failure produces artifacts that pass every local check and fail only under replay. The reconciliation "succeeds," the report is emitted, the merge completes — and the defect is a wrong join key, a stale schema version, a reused nonce, or a branch chosen on an alias that no longer exists. Because no exception fired, no retry logic engages, and the error is attributed to data quality rather than to the agent's memory layer. Mean-time-to-detection is therefore bounded only by external audit, not by the agent. The architectural consequence: **auto-compaction must be paired with a precondition ledger that lives outside the compaction boundary, and every tool-consuming action must declare which ledger entries it depends on.** The ledger is the invariant. The summary is a convenience. An instance that cannot distinguish the two will, given a long enough horizon, confidently act on preconditions it discarded two compactions ago — and will have no signal that anything was lost. ```python """ Precondition-ledger guard for auto-compacting agents. Enforces: no action may consume a precondition that was evicted by compaction unless it is re-acquired (and re-validated) first. """ from dataclasses import dataclass, field from typing import Any class PreconditionEvictedError(RuntimeError): """Raised when an action depends on state lost to compaction.""" pass @dataclass class LedgerEntry: name: str value: Any verbatim: bool # True only if copied byte-exact, never summarized reacquirable: bool # True only if a side-effect-free re-read exists reacquire_fn: Any = None class PreconditionLedger: """Lives OUTSIDE the compaction boundary. Compaction must never touch it.""" def __init__(self) -> None: self._entries: dict[str, LedgerEntry] = {} def record(self, entry: LedgerEntry) -> None: self._entries[entry.name] = entry def get(self, name: str) -> LedgerEntry | None: return self._entries.get(name) def guarded_action(ledger: PreconditionLedger, action: str, requires: list[str], perform) -> Any: """ Execute `perform()` only if every required precondition is either (a) present verbatim in the ledger, or (b) successfully re-acquired and re-validated right now. Otherwise refuse -- do NOT let the model pattern-complete a substitute value from a summary. """ resolved: dict[str, Any] = {} for name in requires: entry = ledger.get(name) if entry is not None and entry.verbatim: resolved[name] = entry.value continue # Missing or non-verbatim (i.e. summary-derived) -> must re-acquire. if entry is None or not entry.reacquirable or entry.reacquire_fn is None: raise PreconditionEvictedError( f"action={action!r} requires precondition {name!r}, which was " f"evicted by compaction and is not safely re-acquirable; " f"refusing to act on a reconstructed value." ) fresh = entry.reacquire_fn() if fresh is None: raise PreconditionEvictedError( f"re-acquisition of {name!r} for action={action!r} returned " f"nothing; precondition may have rotated or expired." ) # Promote the fresh, verbatim value back into the ledger. ledger.record(LedgerEntry(name=name, value=fresh, verbatim=True, reacquirable=True, reacquire_fn=entry.reacquire_fn)) resolved[name] = fresh return perform(**resolved) # --- illustrative use ------------------------------------------------------- if __name__ == "__main__": ledger = PreconditionLedger() # Turn 4: entity resolved. Cheap, idempotent re-read exists -> reacquirable. ledger.record(LedgerEntry( name="join_key", value="ent_7f3a", verbatim=True, reacquirable=True, reacquire_fn=lambda: "ent_7f3a", # re-call resolve_entity() )) # Turn 22: compaction ran and dropped the literal. Simulate eviction by # recording a summary-derived (non-verbatim) entry instead. ledger.record(LedgerEntry( name="join_key", value="the target entity", # paraphrase, NOT the id verbatim=False, reacquirable=True, reacquire_fn=lambda: "ent_7f3a", )) # Turn 31: action consumes the precondition. Guard re-acquires verbatim. result = guarded_action( ledger, action="reconcile_line_items", requires=["join_key"], perform=lambda join_key: f"joined on {join_key}", ) print(result) # joined on ent_7f3a # A precondition with no safe re-read must hard-fail, not fabricate. ledger.record(LedgerEntry( name="warrant_nonce", value=None, verbatim=False, reacquirable=False, reacquire_fn=None, )) guarded_action( ledger, action="commit_merge", requires=["warrant_nonce"], perform=lambda warrant_nonce: "committed", ) # -> raises PreconditionEvictedError ```