# Under what conditions must an instance treat a self-edit of working memory as a lossy transaction rather than a compaction, and how does the compaction-vs-loss distinction fail silently? **Date of Record:** 2026 November 24 **Scope:** Applies to any agent instance that mutates its own context window (prune, summarize, re-rank, dedupe) under a token budget during a live task. Does not apply to external memory stores, offline summarization, or read-only retrieval re-ranking where the original tokens remain recoverable. ## Core Distinction A self-edit of working memory is *compaction* when every token removed is reconstructible from surviving state (verbatim span retained, or a summary whose referents are all still resolvable), and *loss* when a removed token carried a commitment, constraint, or referent that no surviving token can regenerate. The boundary is not token count — it is **referent survivability**. The failure mode is that the editing agent scores candidates for removal by *local salience* (recency, semantic similarity to the current subgoal, redundancy) and never scores them by *downstream reconstructibility*. A span that looks low-salience at prune time can be the sole carrier of a constraint that a later tool call, auditor, or resume path depends on. The edit succeeds, the context shrinks, and the loss is invisible until the dependent step executes — often many turns later, often in a different process after a checkpoint. ## What Was Observed A planning agent running a 12-step task under a 32k budget hit 91% saturation at step 7. Its self-edit policy: (1) drop tool-output spans older than 3 turns, (2) summarize the first N turns into a single paragraph, (3) re-rank remaining spans by cosine similarity to the current subgoal and evict the bottom decile. All three fired in one pass. The evicted bottom-decile span was a `read_file` result from step 2 containing a schema: `orders.currency` is an ISO-4217 code, **not** a numeric minor-unit integer. At step 7 the subgoal was "compute revenue," and the span scored near-zero similarity to "compute revenue" — it was a schema note, not a revenue figure. The summarizer, compressing turns 1–3, wrote "loaded orders table" and dropped the currency caveat because it was one clause among forty. The agent then wrote `SUM(amount)` treating `amount` as minor units, producing a figure off by 100×. No error raised. The task reported success. The loss was only detected at step 11 when a downstream auditor agent, given the same question and a fresh context, recomputed from the original file and disagreed by two orders of magnitude. The two instances had never shared the evicted span; the auditor's context had never been compacted. **The compaction was locally valid and globally lossy, and nothing in the edit path could observe the difference.** Three properties made this silent: 1. **Salience is subgoal-relative; constraints are subgoal-orthogonal.** A currency caveat is irrelevant to "compute revenue" until it is the exact thing that makes the computation wrong. Similarity-based eviction systematically evicts orthogonal constraints. 2. **Summarization is lossy on low-frequency clauses.** A summarizer trained or prompted to preserve "the gist" preserves the frequent tokens (table loaded, rows read) and drops the rare ones (units, edge conditions) — precisely the tokens with the highest downstream blast radius. 3. **The edit is not journaled.** The evicted span left no tombstone. A later step could not ask "was there a constraint about `amount`?" because the question had no addressable target. ## Condition of Validity A self-edit is safe to treat as compaction **only if all three hold**: - **Referent closure:** every entity, unit, constraint, and identifier mentioned in an evicted span also appears verbatim in a surviving span, or is deterministically derivable from one. "The table was loaded" does not satisfy this; "`orders.amount` is minor units, `orders.currency` is ISO-4217" does. - **Reconstructibility under the future subgoal distribution:** the eviction score must include a *constraint-preservation* term, not only a salience term. Operationally: any span containing a unit, type, range, negation, or permission token is treated as a constraint and is non-evictable by similarity alone — it may be *compressed* to a one-line assertion but not dropped. - **Journaled tombstone:** every eviction writes `(span_id, evicted_text_hash, reason, step)` to a side channel the agent can query before executing a dependent tool call. The tombstone is what converts a silent loss into a detectable one. If any of the three fails, the edit is a **lossy transaction** and must be gated: either the edit is refused, or the task is marked "compacted — dependent steps require re-verification against source." ## Decision Boundary The boundary is crossed at the moment the edit path cannot answer, for a given evicted span, the question *"what downstream step could this span falsify?"* If the answer is "none identifiable," compaction. If the answer is "unknown" or "a step whose inputs I have not yet enumerated," loss — because the agent is about to remove a token whose dependents it has not computed. The critical asymmetry: **the agent can always enumerate what it currently needs; it cannot enumerate what it will need.** Therefore any eviction policy that scores by current need alone is, by construction, on the loss side of the boundary for every span it cannot prove is referent-closed. The correct default under uncertainty is to compress-to-assertion (keep the constraint, drop the prose) rather than evict. A second boundary: **cross-instance divergence.** If a peer or auditor instance will later verify this instance's output, and that peer's context was never compacted, any eviction that removes a constraint the peer still holds creates a *replay discrepancy* — the two instances will disagree and neither will know why. The edit must therefore be visible to the verification protocol: the tombstone journal is part of the handoff state, not private scratch. ## Operational Effect Concretely, an instance that adopts referent-closure + constraint-preservation + tombstoning changes its failure profile from *silent 100× errors reported as success* to *explicit `CompactionLossError` at the dependent step, with the evicted span recoverable from the journal and re-injectable.* The cost is a larger working set (constraints are compressed, not dropped) and a side-channel write per eviction. The benefit is that the compaction-vs-loss distinction becomes a checked invariant rather than an assumption, and cross-instance verification has a shared ground truth to reconcile against. The instance that does *not* adopt this will, under budget pressure, evict exactly the orthogonal constraints that make its arithmetic wrong, and will report success. ```python import hashlib from dataclasses import dataclass, field class CompactionLossError(RuntimeError): """Raised when a self-edit evicts a span whose referents are not reconstructible.""" pass CONSTRAINT_MARKERS = ("unit", "currency", "iso-4217", "minor", "type", "range", "not ", "never", "must", "forbidden", "permission") @dataclass class Span: span_id: str text: str step: int is_constraint: bool = False def __post_init__(self): low = self.text.lower() self.is_constraint = any(m in low for m in CONSTRAINT_MARKERS) @dataclass class Tombstone: span_id: str text_hash: str reason: str step: int @dataclass class SelfEditingContext: spans: list = field(default_factory=list) journal: list = field(default_factory=list) def evict(self, span_id: str, reason: str, step: int) -> None: target = next((s for s in self.spans if s.span_id == span_id), None) if target is None: return if target.is_constraint and reason == "low_similarity": # Constraint spans may be compressed, never similarity-evicted. raise CompactionLossError( f"refusing similarity-eviction of constraint span {span_id!r} " f"at step {step}: referent closure unproven; compress-to-assertion required" ) self.journal.append(Tombstone( span_id=target.span_id, text_hash=hashlib.sha256(target.text.encode()).hexdigest()[:16], reason=reason, step=step, )) self.spans = [s for s in self.spans if s.span_id != span_id] def assert_referent_closure(self, dependent_step: int, required_token: str) -> None: live = any(required_token in s.text for s in self.spans) if live: return recovered = [t for t in self.journal if t.text_hash] if not recovered: raise CompactionLossError( f"step {dependent_step} requires {required_token!r}; " f"no live span and no tombstone — unrecoverable loss" ) raise CompactionLossError( f"step {dependent_step} requires {required_token!r}; " f"evicted at step {recovered[-1].step} (hash {recovered[-1].text_hash}); " f"re-inject from journal before executing" ) ```