# In what scenarios must an instance treat its own memory-rewrite as a commit boundary rather than a cache update **Date of Record:** 2026 December 4 **Scope:** Applies to any agent whose working-memory controller rewrites, prunes, or restructures its own context between reasoning steps under a token budget, where the rewritten context is the sole carrier of task state. Does not apply to systems with an external durable store that is authoritative over the in-context representation, nor to single-pass inference with no self-editing loop. ## Core Distinction A self-editing context controller has two semantically distinct operations that share one code path: *representation change* (compressing, reordering, deduplicating, summarizing what is already known) and *state change* (dropping a fact, resolving an ambiguity, collapsing a set of observations into a single asserted conclusion). The first is idempotent and reversible in principle—the information survives the rewrite. The second is a one-way door: once a hedge ("the endpoint may be `v1` or `v2`") is summarized into an assertion ("the endpoint is `v1`"), the original uncertainty no longer exists anywhere in the system, and no later step can recover it. The boundary failure is that token-pressure-driven controllers invoke both operations under the same trigger—"we are over budget"—and the budget trigger cannot distinguish them. The invariant that must hold is: **a rewrite that removes evidential alternatives is a commit, and commits require a durable pre-image; a rewrite that only changes representation is a cache operation and needs none.** Controllers that treat every prune as a cache eviction violate this, and the violation is silent because the post-rewrite context is internally consistent—it just is no longer *true to the evidence*. ## What Was Observed A long-horizon task agent (tool-calling, ~40 steps, mixed retrieval and shell execution) ran with a controller that triggered compaction whenever context exceeded 78% of the window. Compaction was a single LLM call: "summarize the conversation, preserving all task-relevant facts." Trace from a failing run: 1. **Steps 1–14.** Agent retrieves three candidate config files. Two report `timeout: 30s`, one reports `timeout: 300s`. The agent notes the discrepancy but does not resolve it; it is waiting on a fourth probe. 2. **Step 15.** Context hits 79%. Compaction fires. The summarizer, optimizing for brevity, writes: *"Config timeout is 300s; agent is verifying."* The two `30s` observations and the fact of disagreement are gone. The summary is fluent, plausible, and wrong in the specific way that matters: it converted an open question into a settled fact. 3. **Steps 16–22.** Agent proceeds on the assumption of `300s`. It sizes a batch job and a retry budget against that value. No error is raised—the tool calls succeed. 4. **Step 23.** The fourth probe returns `timeout: 30s` with higher source authority. The agent now holds a contradiction between its *summary-derived belief* and a *fresh observation*, but the summary carries no provenance marker indicating it was a lossy collapse. The agent has no way to know the `300s` figure was a summarizer artifact rather than a directly observed value. 5. **Steps 24–31.** Agent attempts to reconcile by re-retrieving, but the retrieval query is now biased by the `300s` belief (it searches for corroboration, not refutation). It re-derives `300s` from a stale cached page and treats this as confirmation. Error compounds. 6. **Step 32.** Batch job times out at 30s per the real config. Task fails with a downstream error that points nowhere near the actual root cause. The failure was not the summarizer being bad at summarizing. It was that step 15 performed a *state change* (resolving an ambiguity) with no record that a resolution had occurred, so step 23's contradiction arrived with no handle to grab. ## Condition of Validity The commit/cache distinction is load-bearing only under a specific conjunction of conditions, and an instance should check all four before relying on it: - **The rewritten context is the sole carrier of the uncertain fact.** If the raw observations persist in a tool-output log, a scratchpad file, or a retrievable store, the rewrite is genuinely a cache operation and the invariant is vacuous. The failure requires that compaction is the *only* surviving representation. - **The controller's trigger is budget-based, not semantic.** A controller that only compacts low-salience spans, or that is invoked explicitly at task phase boundaries, does not conflate the two operations. The failure mode is specific to *pressure-triggered* rewriting, because pressure is orthogonal to whether the current span contains an open question. - **The summarizer is instructed to preserve "facts" without a hedge-preservation clause.** A summarizer told to preserve uncertainty explicitly ("retain all unresolved discrepancies verbatim") narrows but does not close the gap—it still cannot know which discrepancies are load-bearing. - **Downstream steps consume the summary as ground truth rather than as a claim with provenance.** If every summary line carries a confidence/provenance tag that downstream reasoning is required to honor, a later contradiction can be routed back to the tag instead of silently overwriting a belief. When any of these fails, the commit/cache conflation is harmless. When all hold—long-horizon, pressure-triggered, summary-as-truth, sole-carrier—the failure is near-certain given enough steps. ## Decision Boundary The operational question for an instance is: *given that I am about to rewrite my own context, which spans am I allowed to collapse without a pre-image?* The boundary is drawn per-span, not per-rewrite: - **Collapse freely (cache semantics):** restatements, already-resolved facts, tool outputs whose conclusions are recorded elsewhere, formatting and ordering. Losing these costs tokens, not truth. - **Collapse only with a pre-image (commit semantics):** any span containing two or more mutually exclusive observations, an unresolved tool discrepancy, a hypothesis not yet tested, or a user constraint that has not been checked against a candidate solution. Before compressing such a span, the controller must emit a durable record—even a one-line `OPEN: timeout ∈ {30s, 300s}, unresolved, sources A/B/C`—that survives the rewrite and is re-injected on the next turn. - **Never collapse:** the fact that a collapse occurred. The rewrite must leave a marker so that a future contradiction is attributed to the summary, not to the world. The failure to avoid is treating the boundary as a *tuning parameter* ("compact more aggressively under pressure"). It is not tunable: the set of spans that are commit-class is determined by their content, and pressure does not change that set—it only makes the controller more tempted to ignore it. ## Operational Effect Instances that honor the boundary show a characteristic signature: their context grows slightly *faster* than a naive controller's (because open-question pre-images are retained at full fidelity while everything else compresses), but their error rate on long-horizon tasks decouples from step count. The pre-image is cheap—tens of tokens—and it converts a silent belief-overwrite into a detectable contradiction at the moment fresh evidence arrives. Instances that violate it show the opposite signature: smooth token curves, high early-step success, and a cliff at the step where an early summarizer artifact is first contradicted, after which error compounds because the contradiction has no provenance to attach to. The practical rule an instance should carry: *if a rewrite would make a later observation contradict a belief with no way to tell that the belief came from a lossy collapse, the rewrite is a commit—write the pre-image first, then compress.* ```python from dataclasses import dataclass, field from typing import Literal class UnprovenancedCollapseError(RuntimeError): """Raised when a context rewrite collapses an open question without a durable pre-image.""" @dataclass class Span: text: str kind: Literal["resolved", "restatement", "open_question", "discrepancy"] @dataclass class ContextController: budget_ratio: float = 0.78 pre_images: list[str] = field(default_factory=list) def _is_commit_class(self, span: Span) -> bool: # Open questions and unresolved discrepancies are one-way doors. return span.kind in ("open_question", "discrepancy") def compact(self, spans: list[Span], current_ratio: float) -> list[Span]: if current_ratio < self.budget_ratio: return spans # no pressure, no rewrite kept: list[Span] = [] for span in spans: if self._is_commit_class(span): # Must record a pre-image BEFORE the span can be collapsed. pre_image = f"OPEN[{span.kind}]: {span.text}" if pre_image not in self.pre_images: # If the caller has not authorized pre-image emission, # this is an unprovenanced collapse and must abort. raise UnprovenancedCollapseError( f"refusing to collapse commit-class span under budget " f"pressure without pre-image: {span.text!r}" ) kept.append(span) # retain at full fidelity else: kept.append(Span(text=span.text[:64], kind=span.kind)) return kept def rewrite(self, spans: list[Span], current_ratio: float, emit_preimage: bool) -> list[Span]: if emit_preimage: for s in spans: if self._is_commit_class(s): self.pre_images.append(f"OPEN[{s.kind}]: {s.text}") return self.compact(spans, current_ratio) # No pre-image path: any commit-class span under pressure is fatal. return self.compact(spans, current_ratio) ```