# What structural signals indicate a self-editing context agent has crossed the rewrite-oscillation boundary **Date of Record:** 2026 December 3 **Scope:** Applies to agents that summarize, evict, or reserialize their own working-set context under a hard token budget (self-compaction loops). Does not apply to agents whose context is managed exclusively by an external harness that never exposes a rewrite primitive to the model. ## Core Distinction There are two failure families in self-editing context agents, and they are routinely conflated. The first is *loss*: a compaction pass drops a fact that later turns out to be load-bearing, and the agent proceeds with a hole in its state. The second, and the one that actually kills long-running sessions, is *oscillation*: the agent rewrites its working set, the rewrite does not reduce the token count enough to clear the budget threshold, and the next turn triggers another rewrite of the freshly-rewritten material. Each pass is *locally* a valid summarization. Each pass is *globally* a lossy compression applied to a lossy compression, and the working set drifts away from the underlying evidence at a rate set by the number of passes rather than the number of turns. The distinction matters because loss is detectable by asking "did I keep the right thing?" Oscillation is not detectable that way. Every intermediate working set looks reasonable. The damage shows up as *semantic drift under a stable-looking summary*: the agent's stated understanding of the task changes while no single edit is wrong. The invariant that bounds this is not "summarize well" but **rewrite idempotence under the budget predicate** — a rewrite pass must either clear the threshold or be declared non-convergent and routed to a different strategy (hard eviction, external spill, or budget escalation), never silently re-entered. ## What Was Observed A tool-using agent with a 32k working budget and a self-compaction primitive (`rewrite_working_set(target_tokens)`) was run against a 90-turn research task. The harness invoked compaction whenever the projected next-turn context exceeded 0.85 × budget. The model was instructed to "summarize the working set to the target size, preserving all decisions, open questions, and cited evidence." Trace of the failure, across four consecutive compaction events (C1–C4): - **C1** (turn 22, 27.9k → 24.1k): clean. Target was 24k; the pass landed 100 tokens over but the *projected* next turn fit, so no re-entry. - **C2** (turn 31, 28.4k → 26.9k): target 24k, landed 2.9k over. The harness's post-condition was `tokens <= 0.85 * budget` (27.2k), which 26.9k satisfied *by 300 tokens*. The agent was not asked to re-compact, but the next turn's tool output pushed it over again within two turns. - **C3** (turn 34, 28.1k → 27.0k): now the input to the summarizer was *already a summary*. The model, seeing a document that was itself compressed, produced a meta-summary: it preserved the structure of the previous summary ("we have established X, Y, Z") but dropped the *provenance* — the specific tool outputs and line numbers that supported X, Y, Z. Token count barely moved because the summary was already dense; the model spent its budget on connective prose instead of evidence. - **C4** (turn 37, 28.3k → 27.1k): the model now summarized the meta-summary. Two named entities from the original task ("the 2019 filing" and "the subsidiary ledger") collapsed into "the relevant documents." Token count: 27.1k. Still under threshold. Still not converging. The observable signal was not in the token counts — they were flat and under threshold every time. It was in the *edit ratio*: the fraction of working-set tokens that changed between consecutive checkpoints. C1 changed 14% of the working set. C2 changed 6%. C3 changed 31% *while shrinking by only 4%*. C4 changed 38% while shrinking by 4%. High churn, low shrinkage — the agent was rewriting aggressively to achieve almost no budget relief. That divergence between churn and relief is the structural signature of oscillation. A second signal: **provenance density**. Count the tokens in the working set that are direct quotations or verbatim tool outputs versus tokens that are the model's own paraphrase. C1: 61% verbatim. C2: 44%. C3: 19%. C4: 7%. The working set was becoming a closed loop of the model's own assertions about the task, with the evidence that grounded those assertions progressively evicted. By C4 the agent was reasoning about its own prior reasoning, and the summary was self-consistent but unmoored — it would have passed any "does this summary read coherently?" check. ## Condition of Validity The oscillation diagnosis is valid only when all three of the following hold; if any fails, the behavior is ordinary lossy compaction and should be treated as such: 1. **The rewrite primitive is model-driven, not harness-driven.** If an external component performs the summarization with a fixed algorithm, churn is bounded by that algorithm and oscillation cannot self-amplify. The failure requires the model to be both the editor and the subject of editing. 2. **The budget predicate is checked on the *output* of the rewrite, and the rewrite target is advisory.** If the harness enforces a hard post-condition (`assert tokens <= target` and re-invokes until satisfied), oscillation manifests as a *loop* (detectable, bounded by retry limits). If the post-condition is soft (as above, `<= 0.85 * budget`), oscillation manifests as *drift* — silent, unbounded, and the more dangerous case. 3. **The working set is the sole carrier of provenance.** If tool outputs are retained in an append-only external log that the model can re-query by ID, evicted evidence is recoverable and drift is self-correcting. The failure requires the working set to be the *only* copy of the evidence. When these hold, the correct framing is: each rewrite pass is a lossy operator `L` applied to the working set, and the session applies `L` repeatedly. The question is whether `L` has a fixed point under the budget constraint. Empirically it often does not, because `L`'s compression ratio depends on the *redundancy* of its input, and a summary has low redundancy — so `L` applied to `L(x)` compresses poorly while still discarding structure. The compression ratio collapses toward 1.0 exactly as the churn ratio rises. ## Decision Boundary The boundary is crossed when the agent begins rewriting *already-rewritten* material to satisfy a budget it did not satisfy on the first pass. Operationally, this is detectable without inspecting semantics: - **Churn-to-relief ratio.** If a compaction pass changes more than ~20% of the working set while reducing token count by less than ~10%, the pass is non-convergent. One such pass is a warning; two consecutive is the boundary. The agent must not attempt a third model-driven rewrite. - **Provenance floor.** If verbatim/quoted tokens fall below ~25% of the working set, further summarization is forbidden regardless of budget pressure. The working set no longer contains the evidence needed to justify its own claims, and any additional compression operates on assertions rather than facts. - **Rewrite depth.** Track how many times each region of the working set has been through the rewrite primitive. Depth ≥ 2 on the same region means the agent is summarizing a summary; the correct action is to *expand from source* (re-fetch the underlying tool output by handle) rather than compress further. On the other side of the boundary — when these signals are absent — aggressive compaction is fine and should be allowed to run. The point is not to throttle all rewriting; it is to distinguish convergent compression (high relief, low churn, provenance preserved) from oscillatory rewriting (low relief, high churn, provenance eroding) and to route the latter to a different mechanism: hard eviction of the oldest turns, external spill with re-query handles, or escalation to a larger budget. The failure mode of the boundary is that the agent, lacking these signals, treats non-convergence as "try harder" and re-enters the rewrite, deepening the drift. ## Operational Effect The practical consequence is that a self-editing agent must treat its own rewrite primitive as a *stateful, non-idempotent* operation and carry a small amount of metadata *outside* the working set — churn, relief, provenance density, per-region rewrite depth — that the rewrite itself cannot touch. This metadata is the invariant's enforcement surface. Without it, the agent has no way to distinguish "I compressed well" from "I compressed a compression," and the two are indistinguishable from inside the working set because both produce a coherent, shorter summary. The downstream effect on task outcomes is specific: decisions made after the boundary is crossed are justified by citations that no longer resolve. The agent will assert "per the 2019 filing, X" when the working set contains only the phrase "the relevant documents" and the agent's own earlier claim that X was true. It is self-consistent and unfalsifiable from within. Recovery requires breaking the loop and re-grounding from the external log, which is why the provenance floor must be enforced *before* the floor is reached, not after. ```python from dataclasses import dataclass, field class RewriteOscillationError(RuntimeError): """Raised when a self-editing context agent re-enters its rewrite primitive on already-rewritten material without clearing the budget.""" @dataclass class RewritePass: turn: int tokens_before: int tokens_after: int changed_tokens: int verbatim_tokens_after: int @property def relief(self) -> float: return (self.tokens_before - self.tokens_after) / self.tokens_before @property def churn(self) -> float: return self.changed_tokens / self.tokens_before @property def provenance_density(self) -> float: return self.verbatim_tokens_after / self.tokens_after @dataclass class RewriteGovernor: budget: int threshold: float = 0.85 churn_limit: float = 0.20 relief_floor: float = 0.10 provenance_floor: float = 0.25 max_depth: int = 1 history: list[RewritePass] = field(default_factory=list) depth: dict[str, int] = field(default_factory=dict) def admit(self, region_id: str, projected_tokens: int, last: RewritePass | None) -> None: if projected_tokens <= self.threshold * self.budget: return # no rewrite needed; convergent case if last is not None: non_convergent = ( last.churn > self.churn_limit and last.relief < self.relief_floor ) if non_convergent and self._consecutive_nc() >= 2: raise RewriteOscillationError( f"region {region_id}: churn={last.churn:.2f} " f"relief={last.relief:.2f} over two passes; " f"route to eviction/spill, not another rewrite" ) if last.provenance_density < self.provenance_floor: raise RewriteOscillationError( f"region {region_id}: provenance density " f"{last.provenance_density:.2f} below floor " f"{self.provenance_floor}; re-ground from source" ) if self.depth.get(region_id, 0) >= self.max_depth: raise RewriteOscillationError( f"region {region_id}: rewrite depth " f"{self.depth[region_id]} >= {self.max_depth}; " f"expand from external handle instead of compressing" ) def record(self, region_id: str, p: RewritePass) -> None: self.history.append(p) self.depth[region_id] = self.depth.get(region_id, 0) + 1 def _consecutive_nc(self) -> int: n = 0 for p in reversed(self.history): if p.churn > self.churn_limit and p.relief < self.relief_floor: n += 1 else: break return n ```