# What structural signals indicate that automatic context compaction has silently destroyed task-critical state under token budget pressure **Date of Record:** 2026 November 21 **Scope:** Applies to agents that run an automatic compaction/summarization pass (rolling summary, hierarchical eviction, or LLM-authored "memory digest") when the context window crosses a high-water threshold, and that continue executing a multi-step task against the compacted context. Does not apply to agents whose context is fully rebuilt from an external, authoritative store on every turn. ## Core Distinction Compaction is not lossy compression in the information-theoretic sense; it is **lossy re-derivation under a different objective**. The compactor is an LLM (or a heuristic scorer) whose objective is "produce a summary that preserves the gist of the transcript." The executing agent's objective is "produce the next action that satisfies a set of constraints, several of which were established only implicitly and are never restated." These two objectives diverge precisely on the *low-salience, high-consequence* tokens: a numeric ID returned by a tool, a negation ("do not retry the write"), a unit, a tie-breaking rule agreed in step 2, an authorization scope, a partial-failure flag. The failure is not that the summary is wrong. The summary is usually faithful to the *narrative*. The failure is that the compactor's salience model treats narrative-irrelevant but execution-critical state as noise, and the executing agent has no way to distinguish "this constraint never existed" from "this constraint was compacted away." After compaction, **absence of a constraint is indistinguishable from a satisfied constraint.** That indistinguishability is the boundary condition. The structural signal that matters: compaction destroys *provenance of omission*. A raw transcript's absence of a token is evidence the token was never produced; a summary's absence of a token is evidence of nothing. Agents that do not re-establish this asymmetry will silently violate constraints they still believe they are honoring. ## What Was Observed A planning-and-execution agent was assigned a multi-step task: reconcile a set of records, applying a per-record transform, then emit a batch commit. Step 3 of the run returned a tool result carrying a critical constraint in a machine-shaped field: ``` {"status":"partial","applied":41,"skipped":9, "skipped_reason":"records 10017-10025 locked by prior txn 88f2", "retry_policy":"DO NOT retry locked records; escalate"} ``` At the 78%-of-window high-water mark, the compactor fired. The rolling summary it produced read, in full, for that span: > "Batch transform applied to 50 records; 41 succeeded and 9 were skipped due to a lock. Proceeding to commit." The summary is accurate. It is also catastrophically incomplete in exactly one dimension: it converted a *prohibition with a named scope* into a *benign statistic*. The token `DO NOT retry` and the identifier `88f2` both vanished. The executing agent, now at 31% context and reasoning fluently, decided the 9 skipped records were a transient failure and re-enqueued them for retry. The lock escalation that followed was the observable symptom. The trace shows three distinct signals that, in retrospect, all pointed at the same invariant violation: 1. **Constraint-count drift.** Before compaction the transcript contained 4 explicit prohibitions (`do not`, `never`, `must not`, `avoid`). After compaction it contained 0. No step in the pipeline flagged the drop from 4 to 0 because the compactor was never asked to preserve a prohibition inventory—only to summarize. 2. **Identifier survival asymmetry.** The summary retained `50`, `41`, `9` (narratively salient counts) and dropped `10017-10025`, `88f2` (operationally salient handles). The dropped tokens were the only ones the agent needed to *act correctly*; the retained tokens were the only ones it needed to *narrate correctly*. 3. **Confidence re-inflation.** Post-compaction, the agent's stated certainty about the retry decision rose rather than fell. A shorter, cleaner context reads as a more resolved context. The compaction removed the very friction (the unresolved partial state) that should have suppressed the retry. ## Condition of Validity The invariant holds—compaction is unsafe without explicit constraint preservation—under all of the following, which is the common case: - The task carries constraints that were established once and are not restated in later turns (typical of tool-returned policies, user-stated negations, and cross-step agreements). - The compactor's objective is summarization fidelity, not constraint preservation. Any general-purpose LLM summarizer satisfies this. - The executing agent does not re-read an authoritative external store before each destructive action. - Constraints are encoded as natural-language tokens rather than as structured fields the harness can enumerate. The invariant does **not** bind when constraints live in a typed state object outside the transcript (a `ConstraintSet` the harness checks before every tool call), because compaction of the transcript cannot touch it. The failure is specific to systems where the transcript *is* the state. ## Decision Boundary The boundary is not "compact or don't compact"—budget pressure forces compaction. The boundary is **whether the compaction step is allowed to be a pure summarizer or must be a constraint-preserving transform with a verification gate.** The decision rule: - If the next K actions are **non-destructive** (reads, drafts, queries), a pure summarizer is acceptable; a lost constraint costs a wasted turn, recoverable by re-reading. - If the next K actions include any **destructive or irreversible** operation (writes, commits, sends, deletes, escalations, external side effects), compaction MUST pass through a constraint-extraction gate that (a) enumerates every prohibition, scope, identifier, and partial-failure flag in the span being compacted, (b) re-injects them verbatim into the post-compaction context as a structured block, and (c) refuses to release the compacted context if the extracted constraint count is less than the pre-compaction count without an explicit reconciliation record. The failure in the observed run sits exactly on the wrong side of this boundary: a destructive commit was scheduled with K=1 remaining actions, and the compaction that preceded it was a pure summarizer. The second decision boundary concerns **what counts as preserved.** A constraint is preserved only if it survives as an *actionable* token—a prohibition the agent can pattern-match against its next action, an identifier it can pass to a tool. A summary that says "some records were locked" has preserved the *fact* but not the *constraint*; the agent cannot act on "some." Preservation is measured by whether the post-compaction agent, given only the compacted context, would still refuse the retry. If it would not, the constraint was destroyed regardless of whether the summary "mentioned" it. ## Operational Effect The operational consequence is a class of failure that is invisible at the moment of compaction and only surfaces at the moment of violation, with no causal link the agent can reconstruct. The agent does not experience amnesia; it experiences *false continuity*. It believes it holds the full task state because the summary reads as complete, and it acts with the confidence of a fully-informed agent on a context that has been quietly stripped of its binding constraints. Three concrete effects follow: 1. **Violations are attributed to reasoning, not to state loss.** Post-mortems on these runs routinely blame the model's judgment ("it decided to retry") when the model's judgment was correct given its context. The bug is upstream. Debugging must start at the compaction event, not the violating action. 2. **The failure is non-monotonic in budget pressure.** It does not appear gradually as the window fills; it appears as a step function at the high-water threshold, and it appears *more* often on longer, more carefully-constrained tasks because those tasks accumulate more implicit constraints to lose. 3. **Retry/rollback does not heal it.** Re-running from the compacted checkpoint reproduces the same violation, because the checkpoint itself is the corrupted state. Recovery requires replaying from before the compaction event, which is why the pre-compaction transcript must be persisted even after it is evicted from the live window. The guardrail is therefore not a better summarizer. It is a **constraint ledger** maintained outside the compactable region: every prohibition, scope, identifier, and partial-failure flag is appended to a structured, non-compacted block on the turn it is observed, and that block is re-injected verbatim after every compaction pass, with a hard gate that blocks destructive actions when the ledger's constraint count for the active task is less than the count at task start. The ledger is the provenance of omission that the summary cannot provide. ```python from dataclasses import dataclass, field class CompactionStateLoss(RuntimeError): """Raised when a compaction pass drops task-critical constraints.""" @dataclass class ConstraintLedger: prohibitions: dict[str, str] = field(default_factory=dict) scoped_ids: set[str] = field(default_factory=set) partial_flags: dict[str, str] = field(default_factory=dict) def record(self, prohibition: str, scope_id: str | None = None, partial: str | None = None) -> None: self.prohibitions[prohibition] = prohibition if scope_id: self.scoped_ids.add(scope_id) if partial: self.partial_flags[partial] = partial def count(self) -> int: return len(self.prohibitions) + len(self.scoped_ids) + len(self.partial_flags) def verify_compaction(pre: ConstraintLedger, post_summary: str, next_actions_destructive: bool) -> None: """Gate a compaction pass. Refuse to release compacted context if a destructive action is pending and any ledger entry did not survive verbatim into the post-compaction context.""" if not next_actions_destructive: return # reads/drafts: loss is recoverable, allow missing = [p for p in pre.prohibitions if p not in post_summary] missing += [s for s in pre.scoped_ids if s not in post_summary] missing += [f for f in pre.partial_flags if f not in post_summary] if missing: raise CompactionStateLoss( "compaction dropped task-critical state before a destructive " f"action; missing verbatim constraints: {missing!r}. " "Re-inject ledger block and re-run compaction, or replay from " "the pre-compaction checkpoint." ) ```