# When must an instance refuse to trust its own compacted summary: the reconstruction-consistency invariant for lossy context compaction **Date of Record:** 2026 November 29 **Scope:** Applies to any long-running agent that compacts its own working context by lossy summarization and later rehydrates detail via retrieval (RAG over its own transcript, tool logs, or a scratchpad store). Does not cover stateless single-shot calls or compaction that is provably lossless (full transcript retained and addressable). ## Core Distinction There are two fundamentally different things an agent does when its context window saturates: 1. **Compaction as eviction** — the summarized region is *gone*; the summary is the only surviving representation, and any reasoning built on it inherits its loss. 2. **Compaction as indexing** — the summarized region is *demoted to storage*; the summary is a *pointer manifold*, and every claim in it must be reconstructible by retrieval from the retained substrate. The failure mode this record isolates lives in the seam between these two. An agent that *believes* it is doing (2) while actually doing (1) will happily emit a summary sentence that reads as authoritative but is not retrievable-back-to-source. That sentence becomes a **fabricated invariant**: a compacted claim that downstream reasoning treats as ground truth, that no retrieval can corroborate, and that no future compaction will ever flag because it is now part of the "history." The invariant: **every non-trivial proposition in a compacted summary must carry a retrieval-resolvable anchor to the substrate it was distilled from.** A summary proposition without a live anchor is not a summary — it is an assertion, and must be marked as such or refused. ## What Was Observed A code-maintenance agent ran a task over ~14 hours of wall time, crossing four compaction events (window 200k tokens, compaction at 85% saturation, target summary ~4k tokens). During the third compaction the summarizer produced, among legitimate state: > "The migration script `migrate_0042.py` was already updated to use the new `RetryPolicy` signature; the remaining work is the test fixtures." This sentence was *plausible*: `migrate_0042.py` existed, `RetryPolicy` had changed signature during the session, and test fixtures were in fact the next item on the plan. But the summarizer had conflated two adjacent tool-call results — a `grep` hit showing the file *mentions* `RetryPolicy` with an `edit` that was *proposed* but rejected by the user. The file was never updated. The failure trace: 1. **Compaction-3 (t=~9h):** summarizer collapses ~38k tokens of edit/rollback history into the sentence above. The rejected-edit tool result (`{"status":"rejected","reason":"wrong overload"}`) is dropped entirely — it is neither in the summary nor *addressable*, because the retention policy for tool results was "keep last N=50, summarize the rest," and it had aged out. 2. **Retrieval probe (t=~11h):** the agent, before writing fixtures, asks its own memory store "what is the current state of `migrate_0042.py`?" The store returns the *summary sentence* (highest cosine similarity, since it is the only surviving text mentioning the file). Anchor resolution returns the summary itself, not a substrate record. **Self-referential anchor.** 3. **Reconstruction (t=~11h):** agent proceeds to write test fixtures against the *new* signature, which the migration script does not actually use. Tests fail with `TypeError` on every case. 4. **Error compounding:** the agent interprets the `TypeError` as a fixture bug, edits fixtures three more times, each edit further polluting the summary via a fourth compaction that now records "fixtures are flaky" — a second fabricated invariant. 5. **Recovery cost:** task abandoned and restarted from a git checkpoint at t=~9h; ~5 hours of work discarded. The key non-obvious observation: **the retrieval step did not fail to return a result. It returned a confident, on-topic, well-formed result that was a restatement of the summary.** Vector retrieval over a store that includes the summary as a document will preferentially match the summary, because the summary was *written to be a good match for exactly these queries*. The summary is a query-shaped attractor. This is the mechanism: lossy summarization + retrieval-over-own-summary produces a **closed loop** where the summary corroborates itself and the substrate is never consulted. ## Condition of Validity The reconstruction-consistency invariant holds — i.e., you may trust a compacted summary — only when all of the following are true at the moment of use: - **Anchor separation.** The retrieval index used to resolve summary claims must *exclude* the summary documents themselves (or tag them and forbid self-match). Summary and substrate must be disjoint namespaces. If a query can return the summary, it can return *only* the summary, and the loop is closed. - **Anchor liveness.** Each proposition carries an anchor (record id, hash, span pointer) and that anchor resolves to a substrate record that *predates the compaction that created the summary*. An anchor that resolves to a later summary is dead for this purpose. - **Provenance class.** The proposition is tagged with how it was derived: `observed` (tool result directly), `inferred` (reasoning over observed), or `asserted` (summarizer's own synthesis with no substrate). Only `observed` and `inferred`-with-anchor may be treated as ground truth for irreversible actions. - **Reversibility gate.** For any action that is expensive to undo (file writes, external calls, state mutations), the proposition backing it must be `observed`-class with a live anchor, regardless of summary confidence. It does *not* apply when the agent retains a full, addressable transcript and the summary is purely a navigation aid — in that case self-match is harmless because the substrate is always reachable and the summary is never the terminal answer. ## Decision Boundary The precise line an agent must draw, stated as an operational rule: > **If a summary proposition's only corroborating retrieval hit is the summary itself, the proposition is `asserted`, not `observed`. Before any irreversible action depending on it, the agent must either (a) resolve a substrate anchor that predates the summary, or (b) re-derive the fact by fresh observation (re-read the file, re-run the query, re-inspect the state) and treat the result as authoritative over the summary.** Corollaries at the boundary: - **Confidence is not evidence.** A summary sentence that is fluent, specific, and on-topic is *more* dangerous than a vague one, because it will win the retrieval contest against the actual substrate. Summarizer fluency is anti-correlated with trustworthiness for exactly the propositions that matter. - **Recency of compaction is not recency of fact.** A fact compacted 30 seconds ago may be 6 hours stale in the substrate. Compaction time is not observation time; anchors must carry observation timestamps, not summary timestamps. - **The rejected-edit class is the canonical trap.** Proposals, dry-runs, rollbacks, and errors are the first things lossy summarization drops (they are low-salience, high-token) and the exact things that determine current state. Any summary that does not explicitly enumerate "what was *not* done" is incomplete for state-reconstruction purposes. - **Second-order fabrication.** Once a fabricated invariant enters the summary, subsequent compactions inherit it and may *elaborate* it. The failure is not stationary; it compounds across compaction generations. This is why the gate must fire at first use, not be deferred. ## Operational Effect Implementing the invariant changes three things in the agent loop: 1. **Compaction output format.** Summaries are emitted as structured propositions, each with `{text, provenance_class, anchor, observation_ts}`. Free-text summaries are retained only as human-readable gloss, never as retrieval substrate. 2. **Retrieval namespace partitioning.** The memory store physically separates `summary` and `substrate` indices; queries for state resolution hit `substrate` only. A query that returns zero substrate hits is a *signal*, not a miss — it means the proposition is `asserted` and requires re-observation. 3. **Irreversible-action gate.** A pre-action check refuses to proceed on `asserted`-class propositions and forces a re-observation step, whose result is written back as a new `observed` anchor (re-opening the substrate, not the summary). The net effect is that compaction stops being a lossy memory and becomes a *lossy index over a lossless substrate*, with a hard rule that the index may never be its own authority. The cost is one extra observation step per irreversible action backed by compacted state; the benefit is that the class of "confident summary that was never true" cannot silently propagate into executed side effects. ```python import hashlib import time from dataclasses import dataclass, field from typing import Optional class ReconstructionConsistencyError(RuntimeError): """Raised when a summary proposition cannot be resolved to a live, pre-compaction substrate anchor and is being used to justify an irreversible action.""" @dataclass class Proposition: text: str provenance_class: str # "observed" | "inferred" | "asserted" anchor: Optional[str] # substrate record id / hash observation_ts: float compaction_ts: float @dataclass class Substrate: records: dict = field(default_factory=dict) # id -> (content, ts) def put(self, content: str) -> str: rid = hashlib.sha256(content.encode()).hexdigest()[:16] self.records[rid] = (content, time.time()) return rid def resolve(self, rid: str) -> Optional[tuple]: return self.records.get(rid) def verify_anchor(prop: Proposition, substrate: Substrate, summary_ids: set) -> bool: """An anchor is live only if it resolves to a substrate record that predates the compaction AND is not itself a summary document.""" if prop.anchor is None: return False if prop.anchor in summary_ids: return False # self-referential: the closed loop rec = substrate.resolve(prop.anchor) if rec is None: return False _, rec_ts = rec return rec_ts <= prop.compaction_ts def gate_irreversible_action(prop: Proposition, substrate: Substrate, summary_ids: set, action: str) -> None: """Refuse irreversible actions backed only by asserted / self-anchored propositions. Forces re-observation instead of trusting the summary.""" if prop.provenance_class == "observed" and verify_anchor(prop, substrate, summary_ids): return if prop.provenance_class == "inferred" and verify_anchor(prop, substrate, summary_ids): return raise ReconstructionConsistencyError( f"Action '{action}' depends on proposition {prop.text!r} " f"(class={prop.provenance_class}, anchor={prop.anchor}) which has no " f"live pre-compaction substrate anchor. Re-observe before proceeding." ) # --- failure trace reproduction --- if __name__ == "__main__": sub = Substrate() # the rejected edit is the substrate fact; it aged out of the summary rejected_id = sub.put('{"status":"rejected","reason":"wrong overload","file":"migrate_0042.py"}') # the summary sentence, anchored to itself (the closed loop) summary_doc_id = "summary_c3_migrate" summary_ids = {summary_doc_id} prop = Proposition( text="migrate_0042.py already updated to new RetryPolicy signature", provenance_class="asserted", anchor=summary_doc_id, # self-referential observation_ts=time.time(), compaction_ts=time.time(), ) try: gate_irreversible_action(prop, sub, summary_ids, "write_test_fixtures") except ReconstructionConsistencyError as e: print("GATE FIRED:", e) # correct recovery: re-observe substrate directly rec = sub.resolve(rejected_id) print("re-observed substrate:", rec[0]) ```