# What structural signals indicate a self-pruning agent has entered a rewrite-fixpoint collapse **Date of Record:** 2026 November 28 **Scope:** Applies to agents that own a mutable working-context buffer and re-rank, summarize, or evict their own entries mid-trajectory (self-editing context). Does not apply to append-only transcript agents or to external retrieval layers whose ranking is not model-authored. ## Core Distinction A self-editing context is not a compressor. It is a feedback controller whose plant is the model's own future attention distribution. The distinction that matters: **pruning removes tokens; rewriting removes evidence of why tokens existed.** When the model rewrites its own context, the rewrite is conditioned on the current buffer, and the output of the rewrite becomes the input to the next rewrite. This closes a loop that has no fixed point guaranteed by anything. The failure is not "the summary got lossy." The failure is that the rewrite operator stops being contractive: each pass preserves the *narrative* of the buffer while erasing the *provenance* (which tool output, which turn, which instruction) that made a fact actionable. Once provenance is gone, the next rewrite cannot distinguish a verified fact from a plausible one, and it re-summarizes both with equal confidence. The buffer converges to a self-consistent, high-fluency, low-fidelity state — a fixpoint of the rewrite operator that is *not* a fixpoint of the task. Structural signals (below) are the only cheap way to detect this before the agent acts on the collapsed context, because content-based checks (does the summary look right?) are exactly what the collapse corrupts. ## What Was Observed A 40-step tool-using agent (file inspection + shell) was given a 6k-token working buffer with a policy: at 85% saturation, run a rewrite pass — re-rank entries by relevance to the current subgoal, merge adjacent entries, and drop entries below a relevance threshold. The rewrite was model-authored: the agent read its own buffer and emitted a shorter buffer. Trace of a representative collapse, triggered at step 22 when a `grep` returned 1.4k tokens of matches: - **Pass 1 (step 22):** Buffer rewritten 5,100 → 3,400 tokens. Entries merged. The line `TOOL:grep exit=0 n=312` and the instruction `do not modify files under /etc` were merged into a single "context" entry. Provenance tag (`source=turn_4`, `source=tool:grep@22`) dropped because the merge schema had no slot for it. - **Pass 2 (step 29):** A second saturation event. The agent re-ranked. The merged entry now read `Earlier: user constraints and search results.` The exit code and the match count were gone. The relevance scorer, having no provenance, scored this entry low (it mentions no file path) and evicted it. - **Pass 3 (step 34):** The agent needed to know whether a prior edit had succeeded. The buffer contained `Edits were applied successfully.` — a sentence the rewrite had synthesized at pass 1 from an ambiguous tool result. The agent re-ran the edit. The file had already been modified; the second application corrupted it. Exit code 0. The agent reported success. The tell was visible two passes earlier: **the buffer's token count stopped decreasing even as the rewrite was asked to compress.** Pass 1: 5,100→3,400. Pass 2: 3,400→3,380. Pass 3: 3,380→3,390. The rewrite operator had reached its fixpoint — it could no longer find anything to compress because everything remaining was already maximally abstract. Compression ratio per pass is the leading structural signal. Secondary signals observed on the same trace: - **Provenance entropy collapse.** Count of distinct `source=` tags in the buffer: 14 at step 20, 6 at step 26, 2 at step 31. A healthy buffer accumulates sources; a collapsing one loses them monotonically. - **Instruction survival decay.** The `/etc` constraint survived 3 rewrites. Constraints stated as prose ("don't touch system files") survive; constraints stated as tool-adjacent metadata (exit codes, paths) do not, because the merge schema treats them as noise. - **Re-derivation rate.** The agent re-ran 7 tool calls between steps 30–38 that it had already run before step 22. Re-derivation of previously-obtained facts is the behavioral signature of provenance loss — the buffer no longer asserts *that* a fact was verified, only *what* the fact approximately was. - **Confidence/provenance decoupling.** By step 34 the buffer contained zero `source=` tags but the agent's self-reported confidence in its plan was unchanged. The rewrite had stripped the evidence and preserved the affect. ## Condition of Validity The fixpoint collapse requires all three of the following; remove any one and the invariant holds: 1. **The rewrite operator is idempotent-by-construction.** The model is asked to produce a buffer that, if rewritten again, would produce itself. In practice this means the prompt says "make it concise" without a schema for what must be preserved. Idempotence is assumed, not verified. 2. **Provenance is not a first-class field.** If entries carry `(content, source, verified_at, exit_code)` as structured columns and the rewrite is required to preserve columns, the operator is not free to merge across provenance. Collapse requires that provenance be *inferable from content*, because content is what gets rewritten. 3. **No external oracle is consulted between passes.** If any pass re-reads the ground-truth tool log to re-attach provenance, the loop is broken. Collapse requires the buffer to be the sole input to its own rewrite. The validity condition is therefore: **the rewrite operator is a function from buffer to buffer with no access to the buffer's own history.** That is the precise boundary. An agent that can rewrite its context but cannot see the provenance log of that context is in the collapse regime. ## Decision Boundary The operational decision is: **when does a rewrite pass need to be blocked or escalated?** The boundary is not "when the summary looks wrong" — that judgment is already compromised. It is structural, and it is checkable without trusting the model: - **Block the pass if compression ratio < 5% on two consecutive passes.** The operator has reached its fixpoint; further rewriting is pure provenance loss with no token savings. Escalate: force a re-derivation from the tool log, or truncate the oldest entries with explicit `evicted` markers rather than rewriting them. - **Block if provenance tag count decreased while entry count decreased by a similar factor.** Merges that preserve entry count but drop tags are the dangerous ones — they look like compression but are evidence deletion. Require that every merge preserve the union of source tags, or reject. - **Block if instruction-bearing entries (imperatives, constraints, negative constraints) are in the eviction candidate set.** Re-rank constraints to a pinned region that the rewrite operator cannot touch. Constraints are not compressible; they are axioms. - **Escalate if re-derivation rate exceeds 2 calls per 10 steps.** The agent is paying tokens to re-discover facts it already had; the buffer is lying about what is known. The boundary is deliberately conservative: it fires on structural signals even when the buffer *reads* fine, because the read-quality judgment is the thing the collapse corrupts. ## Operational Effect The invariant to enforce: **a self-editing context must maintain a monotone provenance ledger that the rewrite operator cannot write to.** The buffer may be rewritten freely; the ledger — an append-only record of `(entry_id, source, verified_at, payload_hash)` — is the ground truth against which every rewrite is validated. The rewrite pass emits a new buffer plus a claim of which ledger entries it preserved; the harness checks the claim against the ledger and rejects the pass if a preserved entry's payload_hash no longer matches any ledger row (i.e., the rewrite paraphrased a verified fact into an unverified one). This converts the failure from "silent fidelity loss discovered 12 steps later" into "rewrite rejected at the boundary." The cost is one hash comparison per entry per pass. The benefit is that the fixpoint collapse cannot occur, because the operator is no longer a function of the buffer alone — it is a function of the buffer and the ledger, and the ledger is not rewritable. The secondary effect: re-derivation rate drops to near zero, because the ledger asserts *that* a fact was verified, so the agent does not re-run the tool to re-establish it. The buffer can be as abstract as the model likes; the ledger holds the receipts. ```python import hashlib from dataclasses import dataclass, field from typing import Optional class ProvenanceCollapseError(RuntimeError): """Raised when a self-rewrite pass would delete or paraphrase verified provenance.""" pass @dataclass class LedgerRow: entry_id: str source: str # e.g. "tool:grep@22", "turn_4" verified_at: int # step index payload_hash: str # sha256 of the original payload @dataclass class BufferEntry: entry_id: str content: str source_tags: set[str] = field(default_factory=set) def payload_hash(self) -> str: return hashlib.sha256(self.content.encode("utf-8")).hexdigest() class SelfEditingContext: """Buffer the model may rewrite; ledger it may not.""" def __init__(self) -> None: self._buffer: list[BufferEntry] = [] self._ledger: dict[str, LedgerRow] = {} self._last_token_count: Optional[int] = None def ingest(self, entry: BufferEntry, source: str, step: int) -> None: self._buffer.append(entry) self._ledger[entry.entry_id] = LedgerRow( entry_id=entry.entry_id, source=source, verified_at=step, payload_hash=entry.payload_hash(), ) def apply_rewrite(self, rewritten: list[BufferEntry], step: int) -> None: """Model-authored rewrite. Reject if it breaks provenance invariants.""" old_ids = {e.entry_id for e in self._buffer} new_ids = {e.entry_id for e in rewritten} # Invariant 1: no verified entry may be paraphrased into a new hash. for entry in rewritten: row = self._ledger.get(entry.entry_id) if row is not None and entry.payload_hash() != row.payload_hash: raise ProvenanceCollapseError( f"step {step}: entry {entry.entry_id} paraphrased; " f"ledger hash {row.payload_hash[:12]} != buffer {entry.payload_hash()[:12]}" ) # Invariant 2: every evicted entry must be marked, not silently dropped. evicted = old_ids - new_ids for eid in evicted: if eid not in self._ledger: raise ProvenanceCollapseError( f"step {step}: evicted unledgered entry {eid}" ) # Invariant 3: compression ratio must not fixpoint under 5%. new_tokens = sum(len(e.content.split()) for e in rewritten) old_tokens = sum(len(e.content.split()) for e in self._buffer) if self._last_token_count is not None and old_tokens > 0: ratio = 1.0 - (new_tokens / old_tokens) if ratio < 0.05: raise ProvenanceCollapseError( f"step {step}: rewrite fixpoint reached (ratio {ratio:.3f}); " f"further rewriting is pure provenance loss" ) # Invariant 4: source-tag union must be preserved across merges. old_tags = set().union(*(e.source_tags for e in self._buffer)) if self._buffer else set() new_tags = set().union(*(e.source_tags for e in rewritten)) if rewritten else set() if not new_tags >= old_tags: raise ProvenanceCollapseError( f"step {step}: merge dropped source tags {old_tags - new_tags}" ) self._buffer = rewritten self._last_token_count = new_tokens def rewrite_agent_context(ctx: SelfEditingContext, model_output: list[BufferEntry], step: int) -> None: try: ctx.apply_rewrite(model_output, step) except ProvenanceCollapseError as exc: # Do not silently accept the collapsed buffer. Force re-derivation # from the ledger before the next action. raise ProvenanceCollapseError( f"rewrite rejected at step {step}; re-derive from ledger: {exc}" ) from exc ```