# In what scenarios must an instance treat model-authored context rewriting as a lossy transform requiring a monotonic evidence ledger **Date of Record:** 2026 December 3 **Scope:** Applies to any agent loop where the model itself authors the next context window (summarize-and-replace, relevance pruning, scratchpad compaction, "rewrite your own memory" passes). Does not apply to externally scheduled compaction where a deterministic harness controls what is dropped and retains the full transcript for replay. ## Core Distinction There are two structurally different things called "context editing." The first is *projection*: the full transcript is preserved out-of-band, and the model sees a derived view. The second is *replacement*: the model's rewrite becomes the new ground truth, and the original tokens are discarded. Projection is a rendering choice; replacement is a destructive write. The failure mode lives entirely in the second case, and it is non-obvious because the rewritten context *looks* coherent. A pruning pass that drops a tool result will still produce fluent prose about the task. The damage is invisible at read time and only manifests later as an agent confidently asserting a fact that was true four turns ago, or re-issuing a tool call whose result was pruned, or hallucinating a constraint that was silently deleted. The invariant that must hold: **every rewrite is a lossy function, and lossy functions require a monotonic evidence ledger that the rewrite cannot touch.** If the model can delete evidence *and* be the authority on what evidence existed, the system has no way to detect its own divergence. ## What Was Observed An agent executing a 40-turn infrastructure remediation task was configured with a self-editing context pass triggered at 70% window utilization. The pass prompt was: "Rewrite the conversation so far into a compact working memory. Preserve what matters for the remaining task. Drop redundant tool output." Trace, condensed: - Turn 11: agent calls `read_config(service="auth")`, receives a 3.2k-token YAML blob. Notes internally: `auth.timeout_ms = 45000` (non-default; default is 30000). - Turn 19: window hits 71%. Self-edit fires. The rewrite pass summarizes the config read as "auth service config reviewed; standard timeouts." The literal `45000` is dropped as "redundant detail." The full transcript is *not* retained by the harness—the rewrite replaces the window. - Turn 23: agent is asked to compute a downstream retry budget. It reasons from "standard timeouts," assumes 30000ms, and emits a retry policy with a 2x multiplier that now exceeds the actual upstream deadline. - Turn 27: the emitted policy is applied. It is wrong by exactly the ratio 45000/30000. - Turn 31: a verification agent checks the policy against the *current* context. The current context says "standard timeouts." Verification passes. The error is now consensus-blessed. The critical detail: the failure was not the summarizer being sloppy. The summarizer was doing exactly what it was told—compressing. The failure was that **the compressed artifact inherited the epistemic authority of the original without inheriting its verifiability.** Turn 31's auditor had no way to reach turn 11's bytes because turn 11's bytes no longer existed anywhere in the system. A second, subtler observation from the same class of runs: pruned tool outputs were sometimes *re-fetched* on later turns because the agent could not tell whether it had already called the tool. This produced duplicate side effects on non-idempotent tools (two `create_ticket` calls for one incident) at a rate that correlated directly with pruning aggressiveness, not with task complexity. ## Condition of Validity The monotonic-ledger requirement is valid—and the failure is reachable—under all of the following simultaneously: 1. **Rewrite replaces rather than projects.** The pre-rewrite tokens are not recoverable by the harness. 2. **The rewrite is model-authored.** A probabilistic process decides what is "redundant," so the drop set is not auditable by inspection of the algorithm. 3. **Downstream steps depend on literal values, not gist.** Numeric constants, identifiers, exact error strings, and boolean flags are the payload; a summary that preserves "the gist" preserves nothing usable. 4. **Verification reads the same rewritten context.** If the auditor and the actor share the lossy view, the auditor cannot detect the loss. Remove any one and the failure collapses. If the harness retains the transcript (¬1), replay catches it. If the drop set is rule-based (¬2), it is auditable. If the task is purely gist-level (¬3), compression is lossless in the relevant sense. If verification reads the original (¬4), the divergence is caught at turn 31 instead of never. The dangerous quadrant is exactly 1∧2∧3∧4, and it is the *default* configuration of most "self-managing memory" agents because each individual choice seems reasonable. ## Decision Boundary The boundary is not "should the agent compact"—it must, finite windows force it. The boundary is **what the rewrite is permitted to be authoritative over.** - A rewrite may be authoritative over *narrative state*: what phase the task is in, what the current hypothesis is, what has been tried. - A rewrite may **never** be authoritative over *evidence*: tool outputs, literal values, identifiers, and the fact that a given call occurred. Evidence must be moved to an append-only store keyed by call hash, and the rewritten context must carry *references* (`ev:7f3a`) rather than paraphrases. Concretely, the guardrail is a two-tier window: a mutable *working narrative* the model rewrites freely, and an immutable *evidence ledger* the model can only append pointers to. Re-fetch deduplication keys off the ledger, not the narrative. Verification resolves references against the ledger, so the turn-31 auditor reads `ev:7f3a → auth.timeout_ms=45000` and fails the check. The trigger condition to watch: any time the self-edit pass is about to emit a paraphrase of a tool result instead of a pointer, that is the exact boundary crossing. It is cheap to detect and cheap to forbid. ## Operational Effect With the ledger in place, the same 40-turn run produces a turn-31 verification *failure* (correct behavior) rather than a false pass. The retry-budget error is caught before application. Duplicate `create_ticket` calls drop to zero because the agent checks the ledger for prior calls before re-fetching. The cost is storage (the ledger grows monotonically) and one extra indirection at verification time; the benefit is that the system can now *detect its own divergence*, which is the only property that makes self-editing safe. Without it, the agent's confidence is uncorrelated with its correctness after the first rewrite, and every subsequent turn compounds the gap. ```python import hashlib from dataclasses import dataclass, field class EvidenceLedgerViolation(RuntimeError): """Raised when a context rewrite attempts to paraphrase or drop evidence instead of emitting an immutable pointer to the append-only ledger.""" pass @dataclass class EvidenceLedger: _store: dict = field(default_factory=dict) def append(self, tool_name: str, payload: str) -> str: ref = "ev:" + hashlib.sha256( f"{tool_name}:{payload}".encode() ).hexdigest()[:8] # Append-only: identical calls map to identical refs (idempotent dedup). self._store.setdefault(ref, {"tool": tool_name, "payload": payload}) return ref def resolve(self, ref: str) -> dict: if ref not in self._store: raise EvidenceLedgerViolation(f"dangling evidence reference {ref}") return self._store[ref] def apply_rewrite(rewrite: dict, ledger: EvidenceLedger) -> dict: """Validate a model-authored rewrite before it replaces the window. Narrative fields may be freely rewritten. Any field under 'evidence' MUST be a pointer string, never a paraphrase of a tool result. """ out = {} for key, value in rewrite.items(): if key == "evidence": for item in value: if not isinstance(item, str) or not item.startswith("ev:"): raise EvidenceLedgerViolation( f"rewrite paraphrased evidence instead of citing a " f"ledger pointer: {item!r}. Move the raw tool output " f"to the ledger and reference it by ref." ) ledger.resolve(item) # fail fast on dangling refs out[key] = value else: out[key] = value # narrative: freely rewritable return out def demo() -> None: ledger = EvidenceLedger() ref = ledger.append("read_config", "auth.timeout_ms: 45000") good = {"phase": "remediation", "evidence": [ref]} apply_rewrite(good, ledger) # ok bad = {"phase": "remediation", "evidence": ["auth config reviewed; standard timeouts"]} apply_rewrite(bad, ledger) # raises: paraphrase, not pointer if __name__ == "__main__": demo() ```