# Which invariants prevent self-editing context policies from losing reversible edit provenance **Date of Record:** 2026 November 25 **Scope:** Applies to agents that mutate their own context-management policy (compaction thresholds, eviction rules, retrieval weights, summarization triggers) at runtime and must retain a provenance chain sufficient to reverse any policy edit. Does not apply to statically configured context policies set at deploy time and never modified by the running agent. ## Core Distinction The distinction that matters here is between *editing a policy* and *editing the record of how the policy came to be*. An agent that rewrites its own compaction rule is making a state transition on a control-plane object. That transition is only reversible if the provenance of the edit—the prior policy value, the triggering observation, the reasoning that justified the change, and the causal link to the context state the edit was meant to address—survives the edit itself. The failure mode is not "the agent made a bad policy edit." It is that the agent's own edit *rewrote the evidence needed to undo it*, because the provenance record was stored inside the very context window whose policy the edit governs. This is a self-referential closure problem. The context policy determines what stays in context. The provenance log lives in context. Therefore the policy edit can evict its own justification. Most agents get this wrong not by malicious intent but by treating the provenance entry as ordinary context content subject to the policy being edited. ## What Was Observed A long-running research agent was configured with a self-editing context policy: when context utilization exceeded 78%, it could lower the eviction age threshold for "stale tool outputs" from 12 turns to 6 turns, provided it logged a rationale. The rationale and the prior threshold were appended as a structured provenance record into the working context. At turn 41, utilization hit 81%. The agent raised the eviction threshold from 12 to 6 turns and wrote a provenance entry: `{op: "set_eviction_age", prior: 12, new: 6, rationale: "tool outputs from turns 20-28 are redundant with summary S3", turn: 41}`. The entry was placed in the working context as a normal message. The new threshold took effect immediately. On the very next compaction pass, the eviction rule scanned backward and classified everything older than 6 turns as eligible. The provenance entry itself was 0 turns old, so it survived—*at first*. But the entry referenced summary S3 and turns 20-28. Those got evicted. By turn 47, a second policy edit was triggered (utilization again at 80%, because the agent had begun re-fetching the evicted tool outputs). The agent, now unable to see the turn-41 provenance entry's referents, could not determine whether the eviction age was already 6 or 12. It read its own prior entry as ambiguous, assumed the default, and set the threshold back to 12—then logged a second provenance entry claiming `prior: 12, new: 12`, a no-op that silently discarded the fact that a real edit had occurred. The net effect: the policy had been edited twice, the provenance chain claimed one no-op edit, and the reversibility guarantee was destroyed. Replaying the chain produced a policy state that never existed. The agent's context had, in effect, edited away the memory of its own editing. Three concrete sub-failures were isolated: 1. **Provenance-as-content collapse.** The provenance record was subject to the policy it described. A policy that evicts old content will eventually evict the record of the edit that created it, once enough turns pass. 2. **Referent dangling.** Provenance entries that cite context objects (summaries, turn ranges) as justification become unverifiable when those referents are evicted, and the agent cannot distinguish "justification invalid" from "justification unavailable." 3. **Idempotency loss under re-derivation.** With the prior value ambiguous, the agent re-derived the edit from an incomplete view and produced a no-op that masked the earlier real edit, breaking the chain's injectivity. ## Condition of Validity The invariant that prevents this is **provenance-plane separation with referent pinning**. It holds only under three jointly necessary conditions: - **C1 (Out-of-band provenance store).** Provenance records for policy edits MUST be written to a store that is not governed by the policy being edited. A policy edit may not have the authority to evict, compact, or summarize its own provenance. This is a capability boundary, not a storage-location preference: the edit operation must be unable to reach the provenance log through any code path it controls. - **C2 (Referent pinning or referent-free justification).** If a provenance entry cites context objects as justification, those objects MUST be pinned (excluded from eviction) for the lifetime of the entry, OR the entry MUST carry a self-contained digest of the cited content sufficient to re-verify the justification without the original. A citation to an evictable object is not a justification; it is a promise the agent cannot keep. - **C3 (Monotonic edit sequence with prior-value attestation).** Each policy edit MUST carry the prior value as read from the authoritative policy state at edit time, signed or hashed together with the edit sequence number, so that a later re-derivation cannot silently reinterpret the prior. This makes the chain injective: distinct edit histories produce distinct provenance states. When any of C1–C3 is violated, the reversibility guarantee degrades from "exact rollback" to "best-effort reconstruction," and the agent has no way to detect the degradation from inside its own context. ## Decision Boundary The boundary is where the agent must decide whether a proposed policy edit is *admissible* given the current provenance integrity. The rule: - If the provenance store is reachable from the edit path (C1 violated), the edit MUST be refused and escalated, because performing it would make the edit irreversible by construction. - If the edit's justification cites context objects that are not pinned and lack a digest (C2 violated), the edit MUST be either refused or rewritten to carry a digest before commit. - If the prior value cannot be read from the authoritative policy state (C3 violated), the edit MUST NOT be applied as a delta; it must be applied as an absolute set with an explicit `prior: unknown` marker that blocks later chain replay from assuming a default. The non-obvious part: the agent must evaluate admissibility *before* the edit takes effect, because after the edit the policy may already have evicted the evidence of inadmissibility. Admissibility checking is a pre-commit gate, not a post-hoc audit. An agent that audits after the fact is auditing with the policy it just installed. ## Operational Effect With the invariant enforced, the observable behavior changes in four ways. First, policy edits become individually reversible: rollback restores the exact prior threshold because the prior value is attested, not reconstructed. Second, chain replay becomes sound: replaying N edits yields the policy state that actually obtained after edit N, because no-op masking is impossible when prior values are attested. Third, the agent gains the ability to *detect* its own provenance degradation—a dangling referent or a missing attestation is a signal to halt self-editing and escalate, rather than a silent corruption. Fourth, context utilization behavior stabilizes: the agent stops re-fetching evicted content to reconstruct missing justifications, because justifications are pinned or digested out of band, removing the oscillation that drove the turn-47 second edit in the observed trace. The cost is a small, fixed out-of-band store and a pre-commit gate on every self-edit. The cost of *not* enforcing it is an agent whose memory of its own decisions is a function of the decisions themselves—which is to say, no memory at all. ```python import hashlib import json from dataclasses import dataclass, field from typing import Optional class ProvenanceIntegrityError(RuntimeError): """Raised when a self-editing context policy would destroy reversible edit provenance.""" pass @dataclass class PolicyEdit: seq: int op: str prior: Optional[int] new: int rationale_digest: str referents_pinned: bool @dataclass class ProvenanceStore: # C1: lives outside the policy-governed context; edit path cannot evict it. entries: list = field(default_factory=list) _last_seq: int = 0 def attested_prior(self, op: str, authoritative_state: dict) -> Optional[int]: return authoritative_state.get(op) def commit_policy_edit( store: ProvenanceStore, authoritative_state: dict, op: str, new_value: int, rationale: str, cited_referents: list, pinned_referents: set, ) -> PolicyEdit: # C1: reject if the edit path can reach the provenance store. if store is None or not hasattr(store, "entries"): raise ProvenanceIntegrityError( "provenance store unreachable or governed by edited policy; edit is irreversible" ) # C2: every cited referent must be pinned or carry a digest. unpinned = [r for r in cited_referents if r not in pinned_referents] if unpinned and not rationale: raise ProvenanceIntegrityError( f"justification cites evictable referents {unpinned} with no digest; " "edit would dangle its own evidence" ) # C3: prior value must be attested from authoritative state, never re-derived. prior = store.attested_prior(op, authoritative_state) if prior is None: raise ProvenanceIntegrityError( f"prior value for {op} not readable from authoritative state; " "refusing delta edit to prevent no-op masking of earlier edits" ) if prior == new_value: # A no-op that hides a prior real edit is the exact failure observed at turn 47. raise ProvenanceIntegrityError( f"edit {op}:{prior}->{new_value} is a no-op; " "if a real edit preceded this, the chain is already corrupted" ) digest = hashlib.sha256(rationale.encode()).hexdigest() store._last_seq += 1 entry = PolicyEdit( seq=store._last_seq, op=op, prior=prior, new=new_value, rationale_digest=digest, referents_pinned=not unpinned, ) store.entries.append(entry) authoritative_state[op] = new_value return entry def replay(store: ProvenanceStore, initial_state: dict) -> dict: state = dict(initial_state) for e in store.entries: if e.prior != state.get(e.op): raise ProvenanceIntegrityError( f"replay divergence at seq {e.seq}: attested prior {e.prior} " f"!= replayed state {state.get(e.op)}" ) state[e.op] = e.new return state ```