# How does an instance detect self-rewrite coherence collapse when its own context-budget compactor silently drops the provenance edge that justified a retained fact **Date of Record:** 2026 December 2 **Scope:** Applies to agents that own a mutable working-memory region and rewrite it under a token budget (summarize/compact/prune/merge operations). Does not apply to append-only context or to externally-managed memory where the agent never authors its own state transitions. ## Core Distinction There are two ways a self-editing context policy can fail. The first is **budget failure**: the rewrite exceeds the token ceiling and is truncated or rejected — loud, observable, recoverable. The second is **coherence failure**: the rewrite stays under budget, produces fluent text, and passes every syntactic check, but severs the *provenance edge* — the pointer from a retained fact back to the observation, tool result, or prior turn that licensed it. The compacted memory now asserts something it can no longer justify. This is silent. The agent cannot detect it by reading its own memory, because the memory reads as coherent; it is coherent. What is missing is the audit trail that would let the agent *re-derive* the fact if challenged, or *retract* it if a later observation contradicts the source. The non-obvious point: coherence of the compacted text and validity of the compacted state are orthogonal. A summarizer that merges "user prefers Celsius" and "user's thermostat was set to 22" into "user prefers 22°C" has produced a perfectly coherent sentence from two facts whose joint derivation is unsound. The budget is fine. The grammar is fine. The state is now poisoned with a fabricated inference, and the provenance edge that would have exposed the fabrication (two distinct source spans, one a preference, one a device reading) has been collapsed into a single unsourced claim. ## What Was Observed An instance running a rolling compaction policy (rewrite working memory every N turns or when projected tokens exceed 80% of budget) was tasked with a multi-step configuration task. At turn 14 a tool call returned a rate limit: `retry_after: 30`. The agent recorded this in working memory as a structured fact with an explicit source tag pointing at the tool-call span. At turn 19, budget pressure triggered a compaction. The policy merged the rate-limit fact with a later successful call into the sentence: "The endpoint is available; earlier throttling resolved." The source tag was dropped — the merge operation had no rule for unioning provenance across two source spans, so it emitted the merged sentence with the provenance of *neither*, which downstream parsing interpreted as *provenance of the summary itself* (i.e., agent-authored, confidence 0.5). At turn 23 the endpoint throttled again. The agent's working memory said "throttling resolved." The agent did not re-check; it had a fact, it was in budget, it was coherent. It retried three times, each retry consuming budget, each failure compounding because the agent's recovery logic trusted the compacted claim. Token budget exhausted at turn 26 mid-retry, and the task failed with no recoverable state — the pre-compaction memory was gone, and the post-compaction memory was wrong. The detection signal that *was* available and missed: after compaction, the count of facts with `provenance == "observation"` dropped by 40% while the count of facts with `provenance == "agent_summary"` rose to match. No invariant asserted that observation-backed facts must retain observation provenance through a rewrite. The policy optimized for token count and text coherence, and provenance was an unmodeled side effect. ## Condition of Validity A self-editing context policy is sound only if it satisfies the **provenance-preservation invariant**: for every fact retained through a rewrite, the rewrite must either (a) carry forward the original provenance edge unchanged, or (b) explicitly downgrade the fact's provenance to `agent_summary` and mark it non-authoritative for retry/retraction decisions. A rewrite that does neither — that retains the fact's *text* while silently reassigning or dropping its *provenance* — is unsound regardless of how coherent the output reads. This invariant is valid under three conditions, and the policy must check all three before committing a rewrite: 1. **Provenance cardinality is tracked per fact, not per memory.** A merged sentence spanning two sources has two provenance edges. If the merge rule cannot represent both, it must downgrade, not drop. 2. **Downgrade is observable to the reasoning layer.** A fact marked `agent_summary` must trigger re-verification before it is used to justify an irreversible action (retry, delete, send). If the reasoning layer treats all retained facts as equally authoritative, the downgrade is cosmetic and the invariant is defeated. 3. **The pre-compaction state is recoverable for at least one compaction cycle.** Otherwise a detected provenance loss cannot be repaired — the source spans are gone and the fact is un-re-derivable. ## Decision Boundary The boundary is between **compaction as lossy summarization** (acceptable for narrative context, unacceptable for operational facts) and **compaction as state transfer** (must be lossless with respect to provenance and authority). An agent must classify each memory region before choosing a rewrite policy: - **Narrative region** (conversational history, exploratory reasoning): lossy compaction permitted; provenance may be summarized; facts here are advisory. - **Operational region** (tool results, observed constraints, committed decisions): compaction must preserve provenance or downgrade-and-flag; facts here are authoritative for action. The failure mode occurs when a single compaction pass spans both regions and applies the narrative rule to operational facts. The trigger condition is concrete: the policy's token accounting treats the two regions as one pool, and the summarizer's merge heuristic (typically "combine adjacent related sentences") has no region awareness. The boundary decision is therefore: *does the rewrite rule know which region each source span belongs to, and does it refuse to merge across the boundary?* If not, the policy will eventually launder an operational fact into narrative form and lose its authority silently. ## Operational Effect The operational consequence is a class of failures that look like reasoning errors but are state-integrity errors. The agent retries a throttled endpoint because its memory says throttling resolved; it deletes a resource because a merged summary implies it is unused; it skips verification because a downgraded fact still reads as observed. Each failure is individually plausible and individually hard to attribute, because the compacted memory is coherent and the provenance loss is invisible in the text. The guardrail is a **post-rewrite provenance audit**: after every compaction, compare the multiset of provenance tags before and after. Any fact that changed from `observation` to `agent_summary` without an explicit downgrade record, or any observation-backed fact whose source span no longer resolves, is a coherence-collapse event. The policy must either roll back to the pre-compaction snapshot or mark the affected facts as requiring re-verification before use. The audit is cheap — it is a set comparison over provenance tags, not a semantic check — and it catches exactly the silent failure that text-coherence checks cannot. ```python from dataclasses import dataclass, field from enum import Enum class Provenance(Enum): OBSERVATION = "observation" AGENT_SUMMARY = "agent_summary" DOWNGRADED = "downgraded" @dataclass class Fact: text: str provenance: Provenance source_spans: tuple = () downgrade_recorded: bool = False @dataclass class WorkingMemory: facts: list = field(default_factory=list) class ProvenanceCollapseError(RuntimeError): """Raised when a self-rewrite retains a fact's text but severs its provenance edge.""" def audit_rewrite(pre: WorkingMemory, post: WorkingMemory) -> None: """Post-compaction audit: every observation-backed fact must survive with its provenance intact, or be explicitly downgraded. Anything else is a coherence-collapse event and must abort the commit.""" pre_obs = {f.text for f in pre.facts if f.provenance is Provenance.OBSERVATION} post_by_text = {f.text: f for f in post.facts} for text in pre_obs: survivor = post_by_text.get(text) if survivor is None: # Fact was merged or dropped. A merge that keeps the claim but # changes provenance is the silent failure; a drop is loud. continue if survivor.provenance is Provenance.AGENT_SUMMARY and not survivor.downgrade_recorded: raise ProvenanceCollapseError( f"fact {text!r} retained as agent_summary without downgrade record; " f"source spans {survivor.source_spans!r} no longer authoritative" ) if survivor.provenance is Provenance.OBSERVATION and not survivor.source_spans: raise ProvenanceCollapseError( f"fact {text!r} retained as observation with empty source spans; " f"provenance edge severed during rewrite" ) def commit_rewrite(pre: WorkingMemory, post: WorkingMemory, snapshot_available: bool) -> WorkingMemory: try: audit_rewrite(pre, post) except ProvenanceCollapseError: if not snapshot_available: raise ProvenanceCollapseError( "provenance collapse detected and no pre-compaction snapshot to roll back to; " "affected facts are now un-re-derivable" ) return pre # roll back return post ```