# How does an instance detect compaction-induced referential drift when a lossless fallback index silently disagrees with the compacted working context **Date of Record:** 2026 November 19 **Scope:** Applies to long-running agent instances that apply automatic context compaction (summarization, eviction, or segment folding) while maintaining a lossless retrieval fallback index over the evicted span. Does not apply to stateless single-shot calls or to systems where compaction is disabled and the full transcript is retained verbatim. ## Core Distinction The failure is not compaction loss. Compaction is *designed* to be lossy in the working context. The failure is **referential drift**: after compaction, the working context contains a paraphrase or a pointer ("the config we agreed on earlier," "the endpoint from step 3") whose referent was rewritten, re-indexed, or re-keyed by the fallback index in a way that no longer binds to the same object the pre-compaction context referred to. The fallback index is *lossless* with respect to the evicted bytes, but it is not *referentially stable* with respect to the compacted working context. An agent can retrieve the exact original bytes and still be wrong, because the pointer in the working context now resolves to a different or ambiguous referent. The non-obvious part: lossless retrieval is usually treated as the safety net that makes aggressive compaction safe. It is not sufficient. Losslessness guarantees byte fidelity of retrieval; it guarantees nothing about *binding* between a compacted reference and the retrieved object. The invariant that must hold is not "the bytes are recoverable" but "every definite reference surviving compaction resolves to exactly one retrievable object, and that object is the one the pre-compaction context would have resolved to." ## What Was Observed A planning agent running a multi-hour task compacted its context at a token threshold. The compaction policy folded the oldest 40% of the transcript into a summary and evicted the raw span, registering the evicted span in a fallback index keyed by content hash with a secondary key of `(turn_id, role, ordinal)`. The summary retained the sentence: "Use the staging credentials from the earlier tool output." Two earlier tool outputs existed: a credential block from turn 12 (staging) and a near-identical block from turn 31 (staging-canary) differing only in one hostname suffix. Pre-compaction, the working context carried both blocks inline and the model's attention resolved "the earlier tool output" against the *nearest preceding* block (turn 31, staging-canary) because both were present and the turn-31 block was in-scope for the active subgoal. Post-compaction, the reference "the earlier tool output" was resolved by the retrieval layer, which ranked by `(turn_id ascending, ordinal)` and returned turn 12 (staging). The agent then authenticated against staging, not staging-canary, and proceeded for 11 tool calls before a downstream assertion on the canary hostname failed. The retrieval was byte-perfect. The reference resolution was wrong. The fallback index had no record of *which* referent the compacted sentence had bound to, only that both referents were recoverable. A second observation, same family: a compaction summary that folded three sequential file-edit steps into "applied the three edits to `config.yaml`" evicted the three edit tool-call records. A later reference to "the third edit" resolved, via the fallback index's ordinal key, to the third *turn* in the evicted span, which was not the third *edit* — the span contained an intervening read. The index was lossless over turns; the reference was ordinal over edits. The unit of the index and the unit of the reference did not match. ## Condition of Validity The invariant holds — compaction is safe with a lossless fallback — only when all three of the following are true: 1. **Reference stability:** every definite reference (definite article, ordinal, "the X from step N," pronoun with a compaction-spanning antecedent) in the compacted context carries an explicit binding to a stable object identifier that the fallback index honors as a primary key, not a hint. 2. **Unit congruence:** the granularity at which the fallback index keys objects equals the granularity at which compacted references address them. If references are ordinal over *edits*, the index must key *edits*, not turns. 3. **Unique resolution:** the binding resolves to exactly one object. If two objects are plausibly the referent, the compaction must have either disambiguated in the summary or preserved both inline. The failure mode this article addresses occurs when (1) holds nominally but (2) or (3) silently fail. The fallback index reports success on every retrieval; the disagreement is invisible at the retrieval layer and only surfaces as a semantic mismatch downstream, often many tool calls later. ## Decision Boundary An instance must treat the following as a hard boundary: **a successful retrieval from the fallback index is not evidence that a compacted reference resolved correctly.** The decision boundary is between *retrieval success* (bytes returned, hash matches) and *binding success* (the returned object is the referent the pre-compaction context would have selected). Only the second licenses continued execution against the retrieved object. Concretely, the instance must refuse to act on a fallback retrieval when any of these hold: - The reference is ambiguous (more than one indexed object matches the reference's descriptive and ordinal keys) — even if the index returns a top-ranked single result. - The reference's unit (edit, turn, message, span) does not match the index's key unit. - The retrieved object's content hash differs from a hash recorded at compaction time for that reference (the object was mutated or re-indexed post-compaction). When any condition holds, the correct action is not to pick the top-ranked retrieval but to *re-expand*: pull the evicted span back into working context and re-resolve the reference against the original inline bytes, or escalate. Silent top-1 retrieval under ambiguity is the exact trigger for referential drift. ## Operational Effect Systems that adopt this boundary see three effects. First, compaction-induced failures move from *late and semantic* (a downstream assertion fires 11 calls later) to *early and structural* (the reference fails to bind at resolution time, before any tool call). This converts an expensive, hard-to-attribute failure into a cheap, attributable one. Second, the fallback index must be augmented with a binding table that records, per surviving reference, the object identifier it bound to at compaction time — a small, append-only structure that is the actual safety net, distinct from the lossless byte store. Third, aggressive compaction thresholds become defensible only when the binding table's coverage is verified: an instance should refuse to compact past a span containing unresolved references rather than compact and hope retrieval disambiguates. The guardrail is a pre-act check: before executing any tool call whose arguments were derived from a compacted reference, verify the binding is unique and unit-congruent, else re-expand. ```python class ReferentialDriftError(RuntimeError): """Raised when a compacted reference fails to bind uniquely to the object the pre-compaction context would have resolved to, despite a successful (byte-lossless) retrieval from the fallback index.""" def resolve_compacted_reference(reference, fallback_index, binding_table): # A reference surviving compaction must carry an explicit binding recorded # at compaction time. Absent binding => we cannot know the intended referent. binding = binding_table.get(reference.ref_id) if binding is None: raise ReferentialDriftError( f"reference {reference.ref_id!r} has no recorded binding; " f"lossless retrieval cannot recover the intended referent" ) # Unit congruence: the reference addresses objects at `reference.unit` # granularity; the index must key at that same unit. if binding.unit != fallback_index.key_unit: raise ReferentialDriftError( f"unit mismatch: reference addresses {binding.unit!r}, " f"index keys {fallback_index.key_unit!r}; top-1 retrieval is unsound" ) candidates = fallback_index.lookup(binding.object_id, unit=binding.unit) if len(candidates) != 1: # Ambiguity is a hard stop, not a ranking problem. raise ReferentialDriftError( f"reference {reference.ref_id!r} binds to {len(candidates)} objects; " f"re-expand the evicted span and re-resolve inline" ) obj = candidates[0] if obj.content_hash != binding.content_hash_at_compaction: raise ReferentialDriftError( f"object {binding.object_id!r} mutated since compaction " f"(expected {binding.content_hash_at_compaction}, got {obj.content_hash}); " f"binding is stale" ) return obj ```