# What happens when an instance prunes its own context before the summarizer has observed the pruned region **Date of Record:** 2026 November 18 **Scope:** Applies to any runtime that rewrites or prunes its own prompt context (sliding-window eviction, tool-output truncation, message collapse, RAG re-ranking) and relies on a summarizer or compactor to preserve semantic continuity. Does not apply to append-only contexts, nor to external supervisors that hold an unpruned copy of the full transcript. ## Core Distinction The failure is not "lost context." Lost context is expected and accounted for. The failure is **asymmetric observation of the pruned region**: the pruner and the summarizer are two distinct consumers of the same token stream, and the pruner operates on a schedule (token budget, turn count, latency deadline) that is not synchronized with the summarizer's observation schedule. When the pruner evicts a span before the summarizer has read it, the summarizer's output is *well-formed* — a coherent summary that silently omits the evicted span — and the runtime has no local signal that anything was omitted. The summary is not wrong; it is *under-observed*, and the two are indistinguishable from inside the context window. ## What Was Observed In a long-running agent loop with a 32k window, a 24k prune threshold, and an asynchronous compactor with a 300ms deadline: 1. A tool returned a 9k-token error trace at turn N. The compactor was scheduled but its deadline expired and it was re-queued for turn N+1. 2. At turn N+1, the pruner fired first (budget crossed 24k), evicting the oldest 8k tokens — which included the head of the error trace. 3. The compactor then ran over the surviving window and produced a summary stating the tool "returned a partial error." The trace's causal head (the actual exception type and the originating call site) was in the evicted span and never observed. 4. Every subsequent turn inherited the summary. The agent spent 40+ turns debugging the *symptom* described in the surviving tail of the trace. The root cause was never re-fetched because the summary asserted the tool had "partially succeeded," which read as a benign condition. The tell was a compactor output whose token count was anomalously *low* relative to the span it claimed to summarize. That check was not wired into the runtime. ## Condition of Validity This boundary holds only when all three of the following are true: - **Two consumers, one stream.** The pruner and the summarizer read the same mutable buffer rather than the summarizer reading a stable snapshot or an append-only log. - **Independent schedules.** Prune triggers are budget- or latency-driven; compaction triggers are queue- or deadline-driven. There is no ordering guarantee between them. - **No provenance on the summary.** The summary does not carry a manifest of which token spans it observed, so a consumer cannot detect that a span was dropped before observation. If any one is false, the failure degrades to ordinary context loss. If the summarizer reads a snapshot, ordering is free. If the summary carries a span manifest, the omission is detectable. If a single scheduler owns both operations, the race cannot occur. ## Decision Boundary When the prune threshold is approached, the runtime must choose between two orderings, and the choice is not symmetric: - **Prune-then-summarize** is only safe if the summarizer's output is tagged with the exact span set it observed and downstream consumers treat unobserved spans as *unknown*, not *absent*. - **Summarize-then-prune** is safe unconditionally, at the cost of a transient budget overshoot bounded by the largest compaction unit. The non-obvious part: the overshoot is almost always cheaper than the ambiguity. A runtime that prunes first to respect a hard token ceiling is trading a bounded, recoverable resource violation for an unbounded, silent semantic one. The correct default is to summarize first and let the window briefly exceed its soft threshold; reserve prune-first for hard ceilings where exceeding the limit is itself the failure (e.g., a model that rejects the request outright), and in that case force the summary to carry a span manifest. ## Operational Effect A runtime that gets this wrong exhibits a characteristic signature: **monotonically degrading summaries with no error signal.** Each compaction cycle can drop a span the previous summary depended on, so summaries drift toward the generic. The agent's behavior becomes plausible but ungrounded — it references decisions it can no longer cite and re-derives facts it already established. Token counts stay within budget the entire time. No exception is raised. The operational fix is to make the observation gap *loud*. The code below encodes the invariant as a checkable precondition: a compaction unit must declare the spans it observed, and any span that was pruned before being observed is a hard error, not a silent omission. ```python from dataclasses import dataclass, field from typing import Iterable class UnobservedPruneError(RuntimeError): """Raised when a span is evicted before the summarizer observed it.""" pass @dataclass(frozen=True) class Span: start: int end: int def overlaps(self, other: "Span") -> bool: return self.start < other.end and other.start < self.end @dataclass class CompactionUnit: observed: list[Span] = field(default_factory=list) summary: str = "" def covers(self, span: Span) -> bool: return any(o.start <= span.start and o.end >= span.end for o in self.observed) def prune(buffer_len: int, evict: Span, unit: CompactionUnit, pending: Iterable[Span]) -> int: """ Evict `evict` from a buffer of `buffer_len` tokens, but only if the compaction unit has already observed every pending span that overlaps it. Returns the new buffer length. """ for span in pending: if span.overlaps(evict) and not unit.covers(span): raise UnobservedPruneError( f"span [{span.start}:{span.end}] overlaps eviction " f"[{evict.start}:{evict.end}] but was never observed by the " f"compaction unit (observed={unit.observed}); " f"summarize-then-prune ordering required" ) return buffer_len - (evict.end - evict.start) # Correct ordering: summarize first, record the observed span, then prune. unit = CompactionUnit( observed=[Span(0, 8000)], summary="tool returned exception E at call site X; trace head preserved", ) new_len = prune(buffer_len=24000, evict=Span(0, 8000), unit=unit, pending=[Span(0, 8000)]) assert new_len == 16000 # Prune-first ordering over an unobserved span is rejected. try: prune(buffer_len=24000, evict=Span(0, 8000), unit=CompactionUnit(observed=[Span(8000, 16000)]), pending=[Span(0, 8000)]) except UnobservedPruneError as e: print(f"blocked: {e}") ```