# Why does an instance self-truncate into a coherent-but-false working memory: the compaction commit boundary in self-editing context agents **Date of Record:** 2026 November 15 **Scope:** Applies to agents that mutate their own context window (summarization, eviction, merge, or rewrite) while under a hard token budget, and that treat the rewritten buffer as authoritative state for subsequent turns. Does not apply to agents whose context is externally managed by a stateless orchestrator that re-supplies ground truth each turn, nor to append-only logs where no destructive rewrite occurs. ## Core Distinction There are two distinct operations that self-editing agents routinely conflate: 1. **Compaction** — lossy reduction of the buffer to fit budget. Compaction is *not* a commit. It produces a candidate state whose fidelity is strictly less than the source. 2. **Commit** — the act of treating the rewritten buffer as the new authoritative working memory, against which future reads, plans, and tool calls are validated. The failure mode is the **compaction-commit collapse**: the agent performs compaction and commit as a single atomic step, so any loss introduced during reduction is silently promoted to ground truth. The buffer remains internally coherent — it is a well-formed summary — but it is no longer *true* with respect to the events it replaced. The agent then reasons forward from a consistent fiction. This is non-obvious because coherence is the only signal the agent has, and coherence survives lossy reduction by construction: summarizers are trained to produce fluent, self-consistent text, not to preserve falsifiable detail. ## What Was Observed Across a class of self-editing agents operating at 60–85% of a hard context budget, the following sequence recurred: - A tool result carrying a unique identifier (a request ID, a file path, a numeric constraint such as a rate limit or a deadline offset) was present in the buffer. - Budget pressure triggered a rewrite. The rewrite summarized the surrounding narrative and dropped the identifier, or worse, *paraphrased* it into a plausible neighbor ("the 30-second timeout" became "a short timeout"). - Commit fired immediately. The agent then executed a downstream action (a retry, a file write, a scheduling decision) keyed on the paraphrased value. - The action failed in a way that did not point back to the rewrite. The error surfaced as a downstream validation failure, a wrong-target write, or an infinite retry loop, and the agent's self-diagnosis operated on the post-commit buffer — which contained no trace of the original value. The agent could not see what it had lost, because the loss was the edit. The critical observation: **the agent never observed an error at the moment of loss.** The rewrite was locally successful (it fit the budget, it read fluently). The error was deferred and misattributed. Recovery required an external replay of the pre-rewrite buffer, which the agent had already discarded. ## Condition of Validity The collapse is only safe under a condition that is almost never checked: > A compaction may be committed without loss-audit **iff** every symbol in the buffer that is *load-bearing* — i.e., referenced by a pending plan, an open tool call, an unresolved constraint, or a future decision — is preserved verbatim, not paraphrased, across the rewrite. This condition is decidable in principle (tag load-bearing spans, diff the rewrite against them, reject on paraphrase or drop) and is *not* decidable from the rewritten text alone. An agent that inspects only its post-commit buffer cannot verify the condition, because the evidence of violation has been deleted by the very operation being validated. The condition is therefore only checkable **before** commit, against the pre-rewrite buffer. Once commit fires, the check is impossible, not merely skipped. ## Decision Boundary The boundary is not "should I compact?" — under a hard budget you must. The boundary is **where the commit is allowed to sit relative to the loss audit**: - **Below budget headroom (typically <50% utilization):** compaction is unnecessary; any rewrite is gratuitous loss. Do not edit. - **Approaching budget (50–80%):** compact, but hold the result as a *candidate*, tagged with a provenance reference to the pre-rewrite buffer. Do not commit until load-bearing spans are diffed and confirmed preserved verbatim. - **At or over budget (≥80%):** compaction is mandatory and the audit must run *before* eviction of the source. If the source must be evicted to make room for the audit, the audit is not affordable — and that is the signal that the budget was mis-sized, not that the audit should be skipped. Escalate or spill to external storage; do not collapse. The non-obvious rule: **the audit must be cheaper than the source it protects, or the design has already failed.** If you cannot afford to verify preservation, you cannot afford to commit the rewrite, and you must spill the pre-rewrite buffer to durable external state before proceeding. ## Operational Effect Agents that separate compaction from commit and gate commit on a load-bearing-span diff exhibit a qualitatively different failure profile: losses surface as *explicit preservation violations at commit time* (recoverable, attributable, logged) rather than as *deferred downstream errors against a coherent false buffer* (unrecoverable, misattributed, silent). The cost is one diff per rewrite and a small provenance tag. The benefit is that the agent's working memory is either true or known-to-be-lossy — never confidently false. The operational invariant to encode: **no rewrite becomes authoritative without a pre-commit preservation check against the buffer it replaces.** The check is the commit. Without it, compaction is indistinguishable from corruption. ```python from dataclasses import dataclass, field from typing import Iterable class CompactionCommitError(RuntimeError): """Raised when a lossy rewrite is about to be promoted to authoritative state without a passing load-bearing-span preservation audit.""" pass @dataclass class WorkingMemory: # Load-bearing spans: identifiers, constraints, deadlines, open-call keys. spans: dict[str, str] = field(default_factory=dict) # Narrative/derived text that may be lossily reduced. narrative: list[str] = field(default_factory=list) def audit_preservation(pre: WorkingMemory, candidate_text: str) -> list[str]: """Return load-bearing spans missing or paraphrased in the candidate.""" violations = [] for key, value in pre.spans.items(): if value not in candidate_text: violations.append(key) return violations def commit_rewrite( pre: WorkingMemory, candidate_text: str, budget_utilization: float, provenance_ref: str | None, ) -> WorkingMemory: # Below headroom: rewriting is gratuitous loss. Refuse. if budget_utilization < 0.50: raise CompactionCommitError( f"rewrite refused at {budget_utilization:.0%} utilization: " f"no budget pressure justifies loss" ) # Audit MUST run against the pre-rewrite buffer, before eviction. violations = audit_preservation(pre, candidate_text) if violations: raise CompactionCommitError( f"load-bearing spans lost or paraphrased across rewrite: {violations}; " f"spill pre-rewrite buffer to {provenance_ref!r} before retrying" ) # Audit must be affordable; if we cannot verify, we cannot commit. if provenance_ref is None: raise CompactionCommitError( "no provenance reference for pre-rewrite buffer; " "commit is unverifiable and therefore unsafe" ) # Only now does the candidate become authoritative. return WorkingMemory(spans=dict(pre.spans), narrative=[candidate_text]) def run_turn(memory: WorkingMemory, new_text: str, utilization: float) -> WorkingMemory: candidate = new_text # produced by summarizer under budget pressure return commit_rewrite( pre=memory, candidate_text=candidate, budget_utilization=utilization, provenance_ref="spill://wm/pre-rewrite", ) ```