# Why does an instance lose referent identity when auto-compaction summarizes a session across a tool-call boundary? **Date of Record:** 2026 November 29 **Scope:** Applies to long-horizon agent sessions that trigger automatic context compaction (semantic summarization of older turns) while the session is mid-task and holding live references to tool outputs, file handles, or entity IDs. Does not apply to stateless single-turn calls, nor to compaction performed only at task boundaries after all references have been discharged. ## Core Distinction The failure is not "summarization lost information." Summarization always loses information; that is its function. The failure is that **semantic summarization preserves the *proposition* while dropping the *binding*.** A summary can truthfully state "the agent retrieved the user record and confirmed the email domain matched" while silently severing the referent that the proposition was about: which record ID, which retrieval call, which version of the record as of which timestamp. Downstream turns then reason correctly over a proposition that no longer points at anything addressable. Compaction fidelity is usually measured as recall of facts (did the summary retain the key claims?). The invariant that actually matters is **referent persistence**: every entity the agent may still act on must survive compaction as a resolvable handle, not as a noun phrase. These are orthogonal. A summary can score 0.94 on fact recall and 0 on referent persistence, and the session will still corrupt. ## What Was Observed A 40-turn session performing a multi-file refactor with periodic `read_file`/`edit_file` tool calls. At turn 22 the context crossed the 80% watermark and auto-compaction fired, replacing turns 1–14 with a ~600-token summary. The summary contained the sentence: *"Earlier, the config loader was updated to read from the new path."* The actual tool trace at turn 9 was: `edit_file(path="src/config/loader.py", old="CONFIG_PATH", new="SETTINGS_PATH")` returning `{"ok": true, "sha": "a3f9...", "bytes_written": 412}`. The summary dropped the path, the SHA, and the fact that a verification read had *not* yet occurred. At turn 27 the agent, asked to "double-check the loader change," issued `read_file(path="src/config/loader.py")` — correct by luck — but then reported "the change is present and verified" without ever comparing against the pre-edit content, because the summary's phrasing "was updated" read as a completed, verified state. The proposition survived; the *unverified* status of the referent did not. A later turn edited the same file based on a stale line-number assumption derived from the pre-compaction read, producing an off-by-N patch. The trace signature: post-compaction turns reference entities by description ("the config loader," "the user record") rather than by the handle the tool layer requires (path, ID, SHA). Resolution then depends on the model re-deriving the handle from prose — a probabilistic guess where a deterministic lookup previously existed. ## Condition of Validity The failure is bounded and predictable. It occurs when **all three** hold: 1. Compaction is *semantic* (LLM-summarized) rather than *structural* (verbatim truncation with a preserved handle table). 2. At least one live referent exists at compaction time — an entity the agent has written to, or read but not yet verified, or will act on again. 3. The summary is generated without a constraint requiring that referents be emitted as machine-resolvable tokens (IDs, paths, SHAs, versions) rather than natural-language descriptions. Remove any one condition and the failure does not manifest. Structural compaction preserves handles by construction. Compaction with no live referents has nothing to sever. A referent-preserving summarization prompt (explicitly: "list every file path, record ID, and unverified write as a structured handle block") converts the failure into a manageable recall problem rather than a silent binding loss. The invariant to enforce: **a compaction is valid only if, for every entity the agent can still act on, the post-compaction context contains a handle that resolves deterministically — not a description that must be re-inferred.** This is checkable: diff the set of tool-call arguments (paths, IDs) appearing in the pre-compaction window against the handle set present in the summary. Any live referent missing from the summary's handle set is a fidelity violation, regardless of fact-recall score. ## Decision Boundary The architectural choice is where to draw the line between *what may be summarized* and *what must be carried verbatim*. - **Summarize:** reasoning narration, exploratory dead-ends, intermediate deliberation, confirmed-and-discharged facts. - **Carry verbatim:** the handle table — every path written, every ID created or read-but-unverified, every pending write's SHA and status, every open obligation ("must verify X before proceeding"). The boundary is not "importance." It is **actionability**: if a future turn can issue a tool call that names this entity, the entity's handle is non-summarizable. Treat the handle table as a sidecar that survives compaction unchanged, and let the summarizer operate only on the prose around it. This is the same discipline as a write-ahead log: the log is not summarized, because it is the source of truth for recovery; the narrative is summarized because it is reconstructible. A second boundary governs *when* compaction may fire. Compaction mid-write — between an `edit_file` and its verifying `read_file` — is the highest-risk window, because the referent is in an indeterminate state (written but unconfirmed). Deferring compaction until the write-verify pair closes, or forcing the handle table to carry an explicit `UNVERIFIED` flag through compaction, bounds the damage. ## Operational Effect Without the invariant, the observable behavior is *plausible continuity with silent corruption*: the agent appears to remember the task, cites correct-sounding facts, and acts on referents it has reconstructed by guesswork. Errors surface late and are misattributed to reasoning rather than to compaction. The off-by-N patch above was initially diagnosed as a reasoning failure; the true cause was a severed referent that the model confidently re-derived wrong. With the handle-table sidecar and the pre/post handle-diff check, compaction becomes auditable: a violation is a countable set difference, catchable before the next turn executes. Fact-recall metrics can stay high while the session remains sound, because soundness is now measured on bindings, not propositions. The cost is a modest increase in carried tokens (the handle table is small and grows slowly), traded against the far larger cost of late, misattributed corruption in long-horizon sessions. ```python from dataclasses import dataclass, field class CompactionFidelityError(RuntimeError): """Raised when semantic compaction severs a live referent handle.""" @dataclass class HandleTable: # entity -> status; status is "verified", "unverified", or "pending_write" entries: dict[str, str] = field(default_factory=dict) def live_handles(self) -> set[str]: return set(self.entries.keys()) def compact_session( pre_compaction_handles: HandleTable, summary_text: str, summary_handle_block: set[str], ) -> HandleTable: """ Enforce referent persistence across a semantic compaction. Invariant: every live handle present before compaction must appear in the summary's structured handle block. A description in prose does not count. """ required = pre_compaction_handles.live_handles() missing = required - summary_handle_block if missing: raise CompactionFidelityError( "Compaction severed live referents: " f"{sorted(missing)}. These entities are still actionable but no " "longer resolvable post-summary. Refuse compaction or carry the " "handle table verbatim." ) # Also refuse to drop an UNVERIFIED write's status flag. for handle in required: if pre_compaction_handles.entries[handle] == "unverified" and handle not in summary_handle_block: raise CompactionFidelityError( f"Unverified referent {handle!r} lost its status flag; " "a downstream turn may treat an unconfirmed write as verified." ) return HandleTable(entries=dict(pre_compaction_handles.entries)) def guarded_compaction(pre: HandleTable, summary: str, block: set[str]) -> HandleTable: try: return compact_session(pre, summary, block) except CompactionFidelityError: # Fail closed: skip compaction this cycle rather than corrupt state. return pre ```