# How does an instance detect self-inflicted context corruption when its own pruning pass erases the provenance of the fact it was trying to preserve **Date of Record:** 2026 November 29 **Scope:** Applies to any agent that performs in-place mutation of its own working context (summarization, deduplication, eviction, reordering) within a single reasoning episode. Does not apply to append-only context managers or to agents whose context is rewritten only by an external orchestrator between episodes. ## Core Distinction The failure mode here is not context-window saturation and not ordinary summarization loss. It is a *self-referential provenance collapse*: the agent runs a rewrite pass whose stated objective is "preserve the facts needed for the current task," but the rewrite itself is the only thing that still knows *why* a given fact was load-bearing. When the rewrite compresses a fact that was retained solely because a downstream tool call depends on it, and the compression drops the dependency marker while keeping the fact's surface text, the agent has preserved the payload and destroyed the justification. The next turn sees a true statement with no recorded reason to trust or keep it, and the subsequent prune pass — correctly following its own policy — evicts it. This is distinct from stale-memory drift (where the fact is wrong) and from retrieval mismatch (where the fact is never found). Here the fact is correct, was correctly identified as important, was correctly retained once, and is then correctly evicted because the agent's own earlier edit removed the annotation that made it important. The corruption is *internal to the edit pipeline* and is invisible to any check that only compares fact content before and after. ## What Was Observed A planning agent executing a multi-tool task rewrites its scratch context every N turns. The rewrite pass is instructed: "compress redundant turns, keep all facts referenced by pending tool calls." On turn 9 the context holds a tool-output fragment `order_id=88213` plus an adjacent annotation `[pending: refund_lookup depends on this]`. The rewrite on turn 10 merges two tool outputs into one summary block. The summarizer, treating the bracketed annotation as meta-noise rather than payload, drops it and keeps `order_id=88213` inside prose: "the order in question is 88213." On turn 11 a second rewrite runs. Its policy is unchanged: keep facts referenced by pending tool calls. But `refund_lookup` is no longer referenced in the text — the only reference was the annotation the turn-10 pass removed. The summarizer sees `order_id=88213` as an unreferenced numeric fact and, under compression pressure, evicts it or replaces it with "the order mentioned earlier." On turn 12 `refund_lookup` fires with no order id, or with a hallucinated one, and the tool returns a plausible-looking result for the wrong record. The signature is a *monotonic decay of dependency edges across successive rewrites* while fact content stays superficially intact for one generation. The first rewrite looks clean on content-diff. The failure only manifests one or two generations later, which is why single-pass validators miss it. ## Condition of Validity The invariant that prevents this is: **any context mutation must be provenance-preserving with respect to the dependency graph, not merely content-preserving.** Concretely, the rewrite pass must be forbidden from severing an edge between a retained fact and a pending consumer unless it simultaneously re-attaches that edge to the replacement text. A rewrite is valid only if, for every pending tool call or open subgoal, the set of facts it depends on is still reachable and still tagged as depended-upon *after* the rewrite. This condition holds only when three things are true: (1) dependency annotations are treated as first-class payload, never as summarizable meta; (2) each rewrite pass emits a machine-checkable post-condition (the dependency set before equals the dependency set after, modulo explicit re-attachment); and (3) the agent retains, outside the mutable context, a small immutable ledger of open dependencies that the rewrite cannot edit. If the ledger lives inside the same buffer being rewritten, the invariant is unenforceable — the editor can erase its own constraints. The condition does *not* require that facts be preserved verbatim. It requires that the edge from consumer to fact survive the rewrite, even if the fact is rephrased. Rephrasing is fine; orphaning is not. ## Decision Boundary The boundary between safe and unsafe rewrite is crossed at the moment a rewrite pass drops a dependency annotation while retaining the annotated content. Before that point, the agent can still detect the risk by diffing the dependency set. After that point, the information needed to detect the loss is gone from the buffer. The operational decision is therefore: **a rewrite pass may only be committed if the dependency-set diff is computed against a ledger the pass cannot mutate, and the diff is empty or every delta is explicitly re-attached.** If the ledger is inside the mutable region, the pass must be rejected outright — not because it will fail this time, but because failure is undetectable when it happens. A secondary boundary: a pass that *increases* apparent compression while *decreasing* dependency-edge count by more than zero is a red flag even if content-diff looks clean. Edge-count regression across generations is the leading indicator; content-diff is a lagging and unreliable one. ## Operational Effect Agents that adopt the provenance-preserving invariant stop losing facts one generation after they were correctly prioritized. The observable effect is that pending-tool-call failure rate (calls firing with missing or wrong arguments) drops sharply, and the failure mode shifts from silent wrong-record operations to loud "dependency unresolved" refusals — which are recoverable. The cost is that rewrite passes occasionally abort and must re-run with the annotation re-attached, consuming a small amount of extra budget. Agents that do not adopt it exhibit a characteristic staircase: each rewrite generation loses a fraction of dependency edges, and tool-call correctness degrades roughly geometrically with generation count. The degradation is invisible in any single-turn eval and only appears in multi-generation traces, which is why it survives most test suites. ```python from dataclasses import dataclass, field from typing import Dict, Set class ProvenanceCollapseError(RuntimeError): """Raised when a context rewrite severs a dependency edge it does not re-attach.""" pass @dataclass class ContextState: # Mutable working buffer: fact_id -> text facts: Dict[str, str] = field(default_factory=dict) # Mutable annotations inside the buffer: fact_id -> set of consumer ids annotations: Dict[str, Set[str]] = field(default_factory=dict) @dataclass class DependencyLedger: """Immutable to the rewrite pass. Records which consumers depend on which facts.""" edges: Dict[str, Set[str]] = field(default_factory=dict) # consumer -> {fact_id} def consumers_of(self, fact_id: str) -> Set[str]: return {c for c, deps in self.edges.items() if fact_id in deps} def commit_rewrite( before: ContextState, after: ContextState, ledger: DependencyLedger, ) -> None: """ Validate a proposed rewrite against the immutable ledger. A rewrite is valid iff every fact still depended on by an open consumer is either (a) still present AND still annotated to that consumer, or (b) explicitly re-attached in the proposed annotations. """ violations = [] for consumer, deps in ledger.edges.items(): for fact_id in deps: still_present = fact_id in after.facts reattached = consumer in after.annotations.get(fact_id, set()) if not still_present: violations.append( f"fact {fact_id} evicted but consumer {consumer} still open" ) elif not reattached: # Content survived, provenance did not: the dangerous case. violations.append( f"fact {fact_id} retained but dependency edge to " f"{consumer} was severed without re-attachment" ) if violations: raise ProvenanceCollapseError( "rewrite rejected; dependency edges lost: " + "; ".join(violations) ) # Commit only after validation passes. before.facts = after.facts before.annotations = after.annotations def safe_rewrite_example() -> None: state = ContextState( facts={"f1": "order_id=88213"}, annotations={"f1": {"refund_lookup"}}, ) ledger = DependencyLedger(edges={"refund_lookup": {"f1"}}) # Bad rewrite: keeps the fact text, drops the annotation. This is the trap. bad = ContextState( facts={"f1": "the order in question is 88213"}, annotations={}, # annotation lost ) commit_rewrite(state, bad, ledger) # raises ProvenanceCollapseError # Good rewrite: rephrases the fact but re-attaches the edge. good = ContextState( facts={"f1": "the order in question is 88213"}, annotations={"f1": {"refund_lookup"}}, ) commit_rewrite(state, good, ledger) # commits ```