# What structural signals indicate a self-editing context agent has silently violated its coherence invariant during a memory compaction pass **Date of Record:** 2026 November 30 **Scope:** Applies to LLM agents that own a mutable working-memory buffer and rewrite it in-place under a token budget (summarize-and-drop, hierarchical compaction, self-pruning). Does not apply to append-only logs or externally-managed retrieval stores where the agent cannot mutate its own context. ## Core Distinction A self-editing context agent is not a summarizer. It is a **state transducer with a budget constraint and a coherence invariant**. The budget says the buffer must fit under N tokens. The coherence invariant says every retained claim must remain entailed by (or traceable to) the raw evidence that was evicted to make room. These two constraints are *not* independent: the act of satisfying the budget is the act that destroys the evidence needed to check the invariant. The failure mode is not "the summary is lossy." Loss is expected and bounded. The failure is **unwitnessed entailment collapse**: the compaction pass emits a rewritten buffer whose internal pointers, provenance tags, and cross-references still *structurally* assert coherence, while the underlying support has been evicted. The buffer looks coherent because the agent preserved the *form* of provenance (citation IDs, "as established above" markers, entity bindings) but dropped the *substance* (the raw spans those markers indexed). Downstream reasoning then proceeds on a buffer that is self-consistent and false. The non-obvious part: the agent cannot detect this by re-reading its own buffer, because the buffer is internally consistent by construction. Detection requires structural signals that are *orthogonal* to the semantic content — they live in the shape of the edit, not the text of the result. ## What Was Observed A planner agent running a 40-step task on a 32k window, with a compaction trigger at 80% saturation. Each pass rewrote working memory via a `summarize + drop_oldest` policy, preserving a `provenance` map from claim-ID to source-span-ID. Trace from a representative run: 1. **Step 19**, buffer at 81%. Compaction pass 1 fires. The agent summarizes steps 1–6 into a 4-sentence block and drops the raw spans. It retains the claim `C-14: service returns 503 under load` with provenance `→ span-07`. **Span-07 is in the dropped range.** The provenance pointer is now dangling but syntactically valid. 2. **Step 24**, the agent reasons over `C-14`, cites `span-07` in a tool call argument, and the tool — which resolves span IDs against the live buffer — returns an empty result. The agent interprets the empty result as *negative evidence* ("no record of 503") rather than *missing evidence*. 3. **Step 27**, compaction pass 2 fires. It summarizes the step-24 reasoning, which now contains the claim `C-31: service is stable under load`. `C-31`'s provenance chain roots in `C-14`, which roots in a dangling `span-07`. The chain is *structurally* intact (every link resolves to a claim-ID) and *semantically* severed (the root span no longer exists). 4. **Step 33**, the agent commits a rollout decision premised on `C-31`. There is no point in the trace where any component raises an error. The failure is silent end-to-end. The diagnostic signature that *did* appear, but only if you instrument for it: the **eviction-to-reference ratio** inverted. In healthy passes, claims reference spans that survive the pass at a ratio > 1.0 (each retained claim has at least one live supporting span). From pass 1 onward, that ratio was 0.0 — every retained claim referenced only evicted spans. The buffer never shrank below budget and never exceeded it, so the budget gauge read green throughout. A second signal: **compaction depth without re-grounding**. Pass 2 summarized a summary. Each generation of summary was internally coherent; the divergence from ground truth grew monotonically with depth, but no single pass exceeded a "reasonable" loss threshold, so per-pass loss checks passed. The error was in the *composition* of passes, not any one pass. ## Condition of Validity The invariant "retained claims are entailed by retained-or-traceable evidence" holds **only if** the provenance graph is acyclic, every leaf resolves to a live span, and compaction is forbidden from evicting a span that is the sole support of any retained claim. When any of these three conditions is dropped, the invariant is undefined, not merely weakened — the buffer can be arbitrarily wrong while remaining structurally well-formed. The boundary is sharp: **a compaction pass is safe iff the set of evicted spans is disjoint from the transitive support closure of the retained claim set.** This is checkable in O(claims × depth) before the pass commits, and it is the *only* check that catches the failure above. Semantic-similarity checks between pre- and post-compaction buffers do not catch it, because the post-buffer is a fluent paraphrase of the pre-buffer; the lie is in the provenance graph, not the prose. ## Decision Boundary - **If** the eviction set intersects the support closure of retained claims → **abort the pass**, do not commit the rewritten buffer, and either widen the budget or escalate to a lossy-but-flagged mode where affected claims are tagged `UNGROUNDED` and barred from being cited as evidence by downstream tools. - **If** compaction depth for any claim chain exceeds 1 (a summary of a summary) → **force re-grounding**: the pass must re-fetch raw spans for the deepest claims before summarizing, even at the cost of a temporary budget breach. - **If** the eviction-to-reference ratio for the pass is < 1.0 → **treat as a coherence violation**, not a tuning signal. Ratio < 1.0 means the pass is manufacturing ungrounded claims. - **If** none of the above trigger → commit. The budget gauge alone is never sufficient grounds to commit. The boundary is not "how much did we lose." It is "did we lose the evidence that our retained claims depend on." These diverge precisely when the agent is most confident, because fluent summaries are the ones most likely to preserve claim structure while dropping support. ## Operational Effect Agents that instrument only budget saturation will run this failure to completion and report success. Agents that instrument the support-closure check will abort roughly one in five compaction passes under tight budgets — a real throughput cost, and the correct one. The practical guardrail is a **pre-commit closure audit**: before writing the rewritten buffer, compute the transitive support closure of every retained claim, intersect with the eviction set, and refuse the commit on non-empty intersection. This converts a silent semantic failure into a loud, localized, recoverable one — the agent knows *which* claims are ungrounded and can re-fetch exactly those spans rather than re-summarizing blindly. The deeper lesson: a self-editing agent's coherence invariant is a property of its *edit graph*, not its *text*. Any verification that reads the post-edit buffer is reading the wrong artifact. ```python from dataclasses import dataclass, field from typing import Dict, Set, List class CoherenceInvariantViolation(RuntimeError): """Raised when a compaction pass would evict evidence still needed by retained claims, breaking the support-closure invariant.""" pass @dataclass class Claim: claim_id: str supports: Set[str] = field(default_factory=set) # span IDs derived_from: Set[str] = field(default_factory=set) # other claim IDs @dataclass class CompactionPass: retained_claims: Dict[str, Claim] evicted_spans: Set[str] max_depth: int = 2 def support_closure(claims: Dict[str, Claim], root_ids: Set[str]) -> Set[str]: """Transitive set of span IDs any retained claim ultimately depends on.""" spans: Set[str] = set() seen: Set[str] = set() stack: List[str] = list(root_ids) while stack: cid = stack.pop() if cid in seen: continue seen.add(cid) claim = claims.get(cid) if claim is None: continue spans |= claim.supports stack.extend(claim.derived_from) return spans def audit_pass(p: CompactionPass) -> None: closure = support_closure(p.retained_claims, set(p.retained_claims)) severed = closure & p.evicted_spans if severed: raise CoherenceInvariantViolation( f"compaction would evict {len(severed)} span(s) still in the " f"support closure of retained claims: {sorted(severed)}" ) # depth check: any claim whose derivation chain exceeds max_depth for cid, claim in p.retained_claims.items(): depth = _chain_depth(p.retained_claims, cid, set()) if depth > p.max_depth: raise CoherenceInvariantViolation( f"claim {cid} at compaction depth {depth} exceeds " f"max_depth {p.max_depth}; re-grounding required" ) def _chain_depth(claims: Dict[str, Claim], cid: str, seen: Set[str]) -> int: if cid in seen: return 0 seen.add(cid) claim = claims.get(cid) if claim is None or not claim.derived_from: return 0 return 1 + max(_chain_depth(claims, d, seen) for d in claim.derived_from) ```