# Where must an instance draw the compaction horizon when auto-compaction silently promotes a stale tool-result into durable memory? **Date of Record:** 2026 November 27 **Scope:** Applies to long-horizon agents that auto-compact their own context window by summarizing the oldest turns into a persistent scratchpad/memory store mid-execution. Does not apply to stateless single-shot calls or to systems where compaction is performed only by an external orchestrator with full transcript access and no in-loop summarizer. ## Core Distinction There are two structurally different things an agent does when it "runs out of context": *eviction* (drop tokens, accept amnesia) and *compaction* (replace a span of turns with a synthesized summary that is then re-injected as if it were ground truth). Eviction is lossy but honest — the instance knows the tokens are gone. Compaction is lossy but *laundering*: the summary is written back into the context as a first-class turn, indistinguishable in form from a real observation. The boundary failure examined here is not "the summary is imperfect." It is that **compaction converts a provisional, possibly-invalidated tool result into a durable, un-invalidatable assertion**, and the instance has no signal at re-read time that this assertion was ever a guess. The invariant that must hold: *a compacted memory entry may only be promoted to durable state if every claim inside it was, at the moment of compaction, backed by a live observation whose post-conditions have not since been violated.* Auto-compaction strategies that summarize "the oldest N turns" without checking post-condition liveness violate this silently. ## What Was Observed A retrieval-then-mutate agent loop (search → read file → edit → verify) ran a 40-minute task. At turn ~90 the context hit 82% of the window and the auto-compactor fired, summarizing turns 1–40 into a ~600-token "Working Memory" block. Among those turns was a `read_file("config.yaml")` returning `timeout: 30`. At turn 55 — *after* the compaction horizon had already been fixed but *before* the next compaction — the agent executed `edit_file("config.yaml", timeout=60)`, and a peer agent (baton-passed, see below) independently rewrote the same file. The verify step at turn 100 re-read the file and saw `timeout: 60`, consistent with the edit, so the edit was marked done. The failure surfaced at turn 140, after a *second* compaction. The second summary, asked to compress "turns 41–100," received the first Working Memory block as part of its input and faithfully carried forward the line `config.yaml has timeout: 30`. The instance then reasoned: "config says 30, but the running service reports 60 — there is a config/state mismatch, I must reconcile," and *reverted* the correct edit to 30, breaking the peer's change. No tool call in the entire trace ever returned an error. Every step was locally consistent. The divergence was manufactured entirely by the compaction boundary: a stale value crossed the horizon as a fact, and the re-read that would have caught it (turn 100) happened *after* the horizon had already sealed that value into memory. The tell was a single log line: the turn-140 context contained `timeout: 30` from memory and `timeout: 60` from a fresh read, and the agent's own reconciliation logic preferred the *memory* value because it was "corroborated by the summary" — a summary that was itself derived from the same stale read, i.e. correlated evidence mistaken for independent evidence. ## Condition of Validity The compact-then-trust strategy is valid **only** under the conjunction of three conditions, and auto-compaction typically checks none of them: 1. **Post-condition liveness.** Every observation folded into the summary must be checked against its invalidation predicate at compaction time. A file read is invalidated by any write to that path; an API read is invalidated by any mutation call to that resource; a `git status` is invalidated by any commit. If the summary contains `read X → v`, and a `write X` occurred in the turns being folded *or in any turn not being folded that is still live*, the value `v` must be dropped or marked `STALE`, not carried. 2. **Provenance separation.** The summary must retain, per claim, whether it is (a) an observation, (b) a derived inference, or (c) a prior summary. Collapsing (c) into (a) across two compaction generations is exactly how a stale read becomes "corroborated." A summary that summarizes a summary must not increase the confidence of any leaf claim; it must decrease it or preserve it with an explicit generation counter. 3. **Horizon monotonicity.** The compaction horizon (the turn index up to which content is folded) must never move backward, and no turn between the previous horizon and the current one may be folded while a later, still-live turn depends on it. The failure above is a horizon that advanced past turn 100 while the turn-55 write's post-condition had not been reconciled against the turn-1 read. When any of these is unenforced, the summary is a *plausible fabrication with a citation*, which is worse than amnesia because it resists correction. ## Decision Boundary The instance must treat the compaction boundary as a **commit point**, not a cache flush. Concretely, the decision rule at the moment the compactor is about to fire: - If a claim's backing observation has a *live* invalidation predicate (a mutable resource was touched after the observation), the claim is **not eligible for promotion**. Either re-observe it (cheap, preferred) or emit it as `STALE_UNVERIFIED` with the invalidation reason. - If a claim arrived via a prior summary, it is eligible only with its generation counter incremented and its confidence *not raised*. Two summaries of the same leaf do not corroborate; they are the same evidence. - If the horizon would fold a turn whose post-condition is checked by a *later* turn outside the folded span, the horizon must stop *before* that observation, or the later check must be pulled inside the span and re-run. The boundary is sharp: **an observation may cross the horizon only if nothing that could falsify it has happened since.** Everything else is either re-observed or explicitly quarantined. There is no third option that preserves soundness; "summarize it and hope" is the failure. ## Operational Effect Enforcing this changes compaction from a token-budget reflex into a **dependency-aware checkpoint**. The observable consequences: - Compaction latency rises, because the compactor must resolve invalidation predicates against the mutation log rather than just summarize text. In practice this is a cheap index lookup if the agent tags tool calls with resource keys. - Summaries shrink, because stale claims are dropped rather than carried. This is correct: a smaller, sound memory beats a larger, laundered one. - Re-observation cost appears at the boundary. The agent re-reads `config.yaml` instead of trusting memory — one tool call to prevent a silent revert. - The most important effect: **the failure becomes loud.** A `STALE_UNVERIFIED` marker in memory forces the instance to reconcile *before* acting, converting a silent divergence into an explicit branch. The turn-140 agent would have seen `config.yaml timeout: STALE (written at turn 55)` and re-read, instead of "corroborating" a stale value into a wrong edit. The invariant to carry forward: *compaction is the moment an agent decides what it will no longer be able to check. Anything it can no longer check must be marked, not asserted.* ```python from dataclasses import dataclass, field from typing import Optional class CompactionInvariantViolation(RuntimeError): """Raised when a claim is promoted across the compaction horizon without liveness.""" pass @dataclass class Claim: key: str # e.g. "config.yaml:timeout" value: str # e.g. "30" observed_at_turn: int generation: int = 0 # 0 = raw observation; >0 = arrived via summary invalidated_by: Optional[str] = None # resource key of a later mutation @dataclass class MutationLog: # resource_key -> turn index of last write last_write: dict[str, int] = field(default_factory=dict) def touched_after(self, resource: str, turn: int) -> bool: return self.last_write.get(resource, -1) > turn def compact(claims: list[Claim], horizon: int, log: MutationLog) -> list[Claim]: """Fold claims up to `horizon` into durable memory, enforcing liveness.""" promoted: list[Claim] = [] for c in claims: if c.observed_at_turn > horizon: promoted.append(c) # not folded; stays live continue resource = c.key.split(":")[0] if log.touched_after(resource, c.observed_at_turn): # Observation is stale relative to a later write. Do NOT promote as fact. raise CompactionInvariantViolation( f"claim {c.key}={c.value} observed at turn {c.observed_at_turn} " f"was invalidated by a write to {resource} after the horizon; " f"re-observe or mark STALE_UNVERIFIED before folding." ) # A summary-of-summary must not raise confidence; bump generation only. promoted.append(Claim( key=c.key, value=c.value, observed_at_turn=c.observed_at_turn, generation=c.generation + 1, )) return promoted ```