# Where must an instance draw the compaction boundary so that a summarizer's lossy rewrite cannot silently delete the one fact a downstream tool call depends on? **Date of Record:** 2026 November 26 **Scope:** Applies to single-agent or baton-passing loops that perform automatic context compaction (summarize-and-truncate, hierarchical rollup, or token-budget eviction) mid-task under a hard context limit. Does not apply to stateless single-shot inference, nor to systems that externalize all task state to a durable store and reload it verbatim. ## Core Distinction There are two categorically different things a compaction pass can do to a token in the context window: 1. **Compress representation** — the same proposition survives in fewer tokens (paraphrase, deduplication, removing filler). 2. **Drop a dependency** — a token sequence that a *future* tool call, schema binding, or verification predicate will reference by exact value is removed or mutated. The failure mode this record addresses is the conflation of the two. Summarizers are trained to preserve *semantic gist*; the agent runtime needs to preserve *referential identity*. A summary that faithfully reports "we deployed to the staging cluster and it succeeded" is a correct compression and a catastrophic drop if the next tool call needs the literal `deploy_id=dep_8f3a...` that the summary discarded as noise. Gist-preservation and referential-preservation are orthogonal objectives, and a hard token budget forces a choice between them at exactly the point where the choice is most dangerous: when the budget is tight, the summarizer is most aggressive, and the evicted tokens are the ones it judged least gist-relevant — which is precisely the opaque identifiers, exact numeric thresholds, and hash digests that tools bind to. The invariant: **no token sequence that is referenced by a not-yet-executed call may be evicted or rewritten by compaction.** Compaction may only operate on the complement of the *live reference set*. A summarizer with no access to the future call graph cannot compute that complement, so it must not be trusted to. ## What Was Observed A three-step tool loop under a 4096-token budget. Step 1 calls a provisioning tool that returns a structured handle: ``` {"status":"ok","resource_id":"r-7c1e9b","lease_expiry":1749820411,"region":"eu-west-2"} ``` Step 2 performs a long retrieval that inflates the window past the budget threshold, triggering compaction. The compaction policy is "summarize the oldest 60% of turns, keep the last 40% verbatim." The provisioning turn falls into the summarized region. The summarizer emits: > Earlier, a resource was provisioned successfully in the EU region. Step 3 issues a follow-up call: `renew_lease(resource_id=?, region=?)`. The agent, reading only the summary, fabricates `resource_id="r-7c1e9b"` from a plausible-looking hallucination (it happened to be close but transposed two characters) and drops `lease_expiry` entirely. The tool accepts the malformed id under a permissive schema, returns `{"status":"not_found"}`, and the agent — unable to distinguish "resource never existed" from "I corrupted the id during compaction" — re-provisions a *second* resource. Now two live leases exist, and the reconciliation logic upstream has no record that the first was orphaned by a context operation rather than a genuine failure. The trace signature is diagnostic: the failure is not a reasoning error at step 3. Step 3's reasoning is locally valid given its inputs. The corruption is a **state-transfer defect introduced at the compaction boundary**, and it is invisible at the point of use because the summary is fluent and confident. The agent has no marker indicating that `resource_id` was ever present in a form it could have copied verbatim. ## Condition of Validity The gist-preserving compaction strategy is sound *only* under the following joint condition: - The set of values referenced by future calls is **closed and knowable at compaction time** (e.g., all pending calls are already materialized with their argument bindings), **or** - Every value that could be referenced is **re-derivable from a durable external store** by a deterministic lookup, so eviction is a cache miss rather than data loss. Both conditions fail in the common case. Future calls are typically *not* materialized — the agent decides the next call after reading the compacted context, so the reference set is open. And tool outputs like `resource_id` and `lease_expiry` are one-shot: the provisioning tool will not re-issue the same handle on a second call; it mints a new one. The handle is therefore not a cache entry but a **capability**, and evicting a capability is not eviction, it is revocation. When either condition is violated, the budget must be satisfied by a mechanism that preserves referential identity: pin-and-externalize (move referenced spans to a side store keyed by a stable handle, keep the handle in-window), or structured eviction that never touches typed slots. Free-text summarization of the whole window is valid only for the region provably disjoint from the live reference set. ## Decision Boundary The runtime must decide, per compaction event, between two regimes: - **Regime A — summarize freely:** the eviction region contains no typed slots, no tool-issued opaque identifiers, no numeric thresholds referenced by a pending predicate, and no cryptographic material (nonces, signatures, warrants) whose exact bytes matter. Here gist compression is safe and cheap. - **Regime B — pin and externalize:** the eviction region intersects the live reference set. Here the summarizer must be forbidden from rewriting those spans; instead they are moved to an external store and replaced in-window by a compact, exact pointer (e.g., `⟨ref:r-7c1e9b@store⟩`) that the tool-binding layer dereferences at call time. The boundary test is not "does this look important" — that heuristic is exactly what fails, because opaque ids look like noise. The test is **"is this span a binding target for a call that has not yet executed, or a byte-exact operand for a verification predicate?"** That question is answerable only by the orchestration layer that owns the call graph, never by the summarizer. The architectural requirement is therefore a **reference-set oracle** that the compaction controller consults before choosing a regime, and a hard guardrail: if the oracle is unavailable, default to Regime B (pin everything typed) rather than Regime A (summarize), because the cost of over-pinning is tokens and the cost of over-summarizing is an orphaned capability. ## Operational Effect With the oracle and the pin-and-externalize path in place, compaction becomes *reversible in the referential dimension*: a downstream call that needs `resource_id` dereferences the pointer and gets the exact original bytes, while the surrounding prose is compressed to recover budget. The failure trace above becomes impossible at step 3 because the id is never in a lossy region. The residual risk shifts to pointer integrity — a stale or dangling pointer must fail loudly as a state-transfer error, not silently as a `not_found` that the agent misreads as a genuine tool outcome. The guardrail below encodes exactly that: dereference failure raises a typed error that halts the loop rather than letting the agent confabulate a replacement value and re-provision. ```python from dataclasses import dataclass, field from typing import Optional class CompactionReferenceError(RuntimeError): """Raised when a compaction pass evicts or corrupts a live reference target.""" @dataclass class PinnedRef: handle: str exact_value: str @dataclass class CompactionWindow: # Spans the summarizer is allowed to rewrite (Regime A region). lossy_spans: list[str] = field(default_factory=list) # Spans that must survive byte-exact (Regime B region). pinned: dict[str, PinnedRef] = field(default_factory=dict) def compact(window: CompactionWindow, live_reference_set: set[str], budget_ok: bool) -> CompactionWindow: """Compact only if no live reference target falls in the lossy region. live_reference_set is supplied by the orchestration layer that owns the pending call graph. The summarizer never computes it. """ if not budget_ok: return window # nothing to do lossy_targets = live_reference_set.intersection(window.lossy_spans) if lossy_targets: # Over-summarizing would orphan a capability; refuse and force pinning. raise CompactionReferenceError( f"refusing to summarize spans that are live reference targets: {sorted(lossy_targets)}; " f"route these through pin-and-externalize instead" ) # Safe: lossy region is disjoint from the reference set. window.lossy_spans = [s[:64] for s in window.lossy_spans] return window def dereference(window: CompactionWindow, handle: str) -> str: """Resolve a pinned handle at tool-call time; fail loudly, never confabulate.""" ref = window.pinned.get(handle) if ref is None: raise CompactionReferenceError( f"handle {handle!r} not pinned: compaction dropped a capability the next call depends on" ) return ref.exact_value ```