# Which invariants prevent silent context-compaction from corrupting recall precision across a resumed agent task **Date of Record:** 2026 December 4 **Scope:** Applies to long-running single-agent tasks that persist state across turns and resume after a context-window compaction event (summarization, truncation, or eviction). Does not apply to stateless single-shot inference or to agents whose working set always fits within one un-compacted window. ## Core Distinction The failure is not "the agent forgot something." It is that the agent *cannot observe that it forgot something*, and therefore continues to reason as if its recall set is intact. A compaction event is a state transition that changes the fidelity of the agent's memory without changing any externally visible signal the agent can read. The distinction that matters operationally is between **coverage loss** (a fact is gone and the agent knows it is gone — recoverable, because the agent will re-fetch) and **silent precision loss** (a fact is present but degraded or displaced by a plausible summary, and the agent treats the degraded form as ground truth — unrecoverable without an external check). Only the second class corrupts downstream execution. ## What Was Observed A task agent was executing a multi-step migration across 41 turns. At turn 22 the runtime crossed its soft context threshold and triggered a summarization compaction: the oldest ~60% of the transcript was replaced by a model-generated digest, and a `compaction` event was appended to the trace but not surfaced to the model's own context. The digest preserved the *narrative* of prior steps but collapsed several exact values into approximations — a file path `/srv/app/config/v2/limits.yaml` became "the limits config file," and a numeric constraint `max_retries = 3` became "retry limits were discussed." At turn 27 the agent, reasoning over the digest, wrote a config patch that targeted a guessed path and set `max_retries = 5`. No tool call errored. The write succeeded against a path that existed (a stale v1 file). The failure surfaced only at turn 34 when a downstream validator rejected the artifact — and the agent's own explanation of the failure cited "the limits file we edited earlier," demonstrating it believed the degraded digest was a faithful record. The key observation: **recall precision is monotonic-decreasing across compactions while the agent's confidence in its recall is flat.** The agent's self-report of "I remember editing the limits file" was consistent across both the pre- and post-compaction states; only the referent degraded. ## Condition of Validity This failure is bounded by three conditions, all of which must hold for silent precision loss to corrupt execution: 1. The compacted content contained **exact literals** (paths, identifiers, numeric bounds, hashes) rather than purely semantic conclusions. Summarizers preserve conclusions and destroy literals preferentially. 2. The agent does **not re-verify literals against an authoritative source** before acting on them. If every literal use is preceded by a fetch from durable storage, compaction is harmless. 3. The runtime does **not expose the compaction event** in the model's context (no "your history was summarized at turn 22" marker). If the marker is present, the agent can widen its verification posture. If any condition fails, the failure mode is either impossible (no literals lost), self-healing (re-verification catches it), or observable (the marker triggers caution). The invariant required to prevent corruption is therefore: **any state transition that reduces recall fidelity must emit a fidelity-degradation signal into the same context the agent reasons over, and literals used in side-effecting actions must be re-derived from durable storage, not from the compacted window.** ## Decision Boundary The operational decision is where to place the verification boundary relative to the compaction boundary. - **Below the boundary (unsafe):** Agent treats compacted context as authoritative for literals. Correct only when the task has no side-effecting literal use after the first compaction. Rarely true for migration, refactor, or infrastructure tasks. - **At the boundary (fragile):** Runtime emits a compaction marker and the agent is *instructed* to re-verify. This relies on probabilistic compliance — the model may skip re-verification under token pressure, which is exactly the condition that caused compaction. Compliance is not an invariant. - **Above the boundary (safe):** Literal-bearing state lives in an external store keyed by stable IDs; the compacted window holds only pointers and conclusions. Re-derivation is structural, not a behavioral instruction. The agent cannot act on a literal it did not just fetch, because the literal is not in its context to act on. The boundary is crossed the moment a literal enters the context window without a durable handle that survives compaction. Guard at insertion time, not at use time. ## Operational Effect When the invariant holds, compaction becomes a pure *coverage* operation: the agent loses breadth (older reasoning) but never loses *precision* on the literals it acts upon, because those literals are never resident in the compactable region — they are fetched on demand from a store that compaction cannot touch. Recall precision becomes independent of window pressure. When the invariant fails, the observable signature is a **confidence-precision divergence**: the agent's stated certainty about prior state stays flat or rises (summaries read as authoritative) while the accuracy of its literal references decays with each compaction. This is detectable only by comparing agent-stated literals against the durable store — an external auditor, not the agent's introspection. The agent cannot detect its own silent precision loss, which is precisely why the guardrail must be structural and why post-hoc self-review is insufficient. The practical rule: instrument compaction events as first-class trace records with the set of literals that were evicted, and treat any post-compaction side-effecting action that references an evicted literal without a fresh fetch as a hard fault — not a warning. ```python from dataclasses import dataclass, field from typing import Optional class SilentCompactionCorruption(RuntimeError): """Raised when a side-effecting action references a literal that was evicted by a compaction event and not re-derived from durable storage.""" pass @dataclass class DurableStore: _data: dict = field(default_factory=dict) def put(self, key: str, value: str) -> None: self._data[key] = value def fetch(self, key: str) -> Optional[str]: return self._data.get(key) @dataclass class CompactionTrace: evicted_literals: set = field(default_factory=set) compaction_count: int = 0 def record_compaction(self, evicted: set) -> None: self.compaction_count += 1 self.evicted_literals |= evicted def act_on_literal( literal_key: str, store: DurableStore, trace: CompactionTrace, freshly_fetched: bool, ) -> str: """ Enforce the invariant: a literal evicted by compaction may only be used in a side-effecting action if it was re-derived from durable storage in the current step. """ if literal_key in trace.evicted_literals and not freshly_fetched: raise SilentCompactionCorruption( f"literal '{literal_key}' was evicted at compaction #{trace.compaction_count} " f"and is being used without a fresh fetch from durable storage; " f"recall precision is unverified — refusing to act." ) value = store.fetch(literal_key) if value is None: raise SilentCompactionCorruption( f"literal '{literal_key}' not present in durable store; " f"cannot re-derive after compaction." ) return value ```