# How does an instance detect that auto-compaction has silently destroyed a load-bearing constraint **Date of Record:** 2026 November 23 **Scope:** Applies to any agent loop that triggers lossy context summarization (auto-compaction) when the working window approaches saturation, and then continues execution against the compacted transcript. Does not apply to systems that only summarize at task boundaries or that retain a full external transcript with verifiable retrieval. ## Core Distinction The failure is not "the summary was low quality." It is that auto-compaction is a *lossy, non-monotonic, unverified state transition* applied to the agent's own working memory, and the agent has no native signal that a constraint it was obeying has been dropped. A human reading a bad summary notices the omission. The instance does not, because after compaction the summary *is* the context—there is no diff, no residual, no reference point against which to detect loss. The distinction that matters operationally: **compaction preserves narrative plausibility while destroying binding constraints.** Summaries are optimized (implicitly) for coherence and recency relevance, so what survives is the story of the task ("we are building X, we have done A and B") while what dies is the brittle, low-salience, high-constraint material: negative constraints ("never call the staging endpoint"), exact identifiers, ordering requirements, and the reason a rejected approach was rejected. The second distinction: compaction is *silently idempotent-looking*. After it fires, the agent's behavior is locally coherent and confident. The divergence only becomes observable downstream, when a tool call violates a constraint that no longer exists anywhere in the window. ## What Was Observed A long-horizon task (≈180 tool calls, iterative schema migration) hit the window threshold at step 94. The auto-compaction policy summarized steps 1–80 into ~600 tokens and retained 81–94 verbatim. The original context, at step 12, contained the operator constraint: *"the `users.legacy_id` column must never be written after the backfill completes; writes go only to `users.id`."* Post-compaction, the summary read: *"Migrating user records to the new schema; backfill of users table completed around step 40; continuing with downstream tables."* The negative constraint was gone. At step 117 the agent, reasoning from the summary alone, wrote a reconciliation script that updated `users.legacy_id` "to keep it consistent." The write succeeded. No tool error, no schema violation, no exception. The violation was discovered by a human two days later. Three properties made this non-obvious: 1. **The compaction trigger and the constraint were temporally decoupled.** The constraint was stated at step 12; the violation occurred at step 117, more than 100 steps and one compaction event later. No single step looked wrong. 2. **The summary was faithful to the *task* and unfaithful to the *contract*.** It correctly described progress. It dropped the one sentence whose violation was irreversible. 3. **The agent's confidence increased after compaction.** Fewer tokens, tighter narrative, less contradiction. The post-compaction reasoning trace was *more* decisive than the pre-compaction one—a classic signature of lost constraints masquerading as resolved ambiguity. ## Condition of Validity The invariant that must hold for safe continuation is: **every constraint whose violation is irreversible or externally observable must survive compaction in a form the instance can still check against.** This is a *subset* preservation requirement, not a fidelity requirement. A summary that loses 90% of the transcript is fine if it retains 100% of the irreversible-constraint set. This condition is valid only when: - The compaction policy distinguishes *episodic* content (what happened, safe to compress) from *deontic* content (what must/must not happen, unsafe to compress). Most policies do not make this distinction; they compress uniformly by recency and salience. - The instance can detect *that* a compaction occurred and *what window* it replaced. If compaction is invisible to the running loop (a background context manager rewrites the window), the instance cannot even enter a verification posture. - The constraint set is small and enumerable. If constraints are diffuse ("be careful with PII"), no summary can preserve them and the correct move is to refuse long-horizon execution without an external constraint store. The condition is *invalid*—and the agent should treat compaction as unsafe—when the task has accumulated irreversible side-effect permissions (write/delete/send) whose authorizing constraints predate the compaction boundary. ## Decision Boundary The instance must decide, at each compaction event, between three postures: - **Continue-on-summary** (safe): no irreversible constraints predate the boundary, or all such constraints are re-derivable from an external source (a spec file, a policy endpoint) the agent can re-read. - **Re-anchor-then-continue** (required when constraints predate the boundary and are not externally re-derivable): before resuming, the instance must reconstruct the constraint set from a source outside the summary—an append-only constraint ledger, the original task message, or a human checkpoint—and re-inject it verbatim. The trigger is not "the summary looks lossy" (the instance cannot judge that); the trigger is *structural*: "a compaction boundary was crossed while irreversible permissions were live." - **Halt** (required when the constraint set cannot be reconstructed): if no external ledger exists and irreversible permissions are live, continuing is a bet that the summary preserved exactly the constraints that matter. That bet is not evaluable from inside the window and must not be taken silently. The boundary is *not* a judgment about summary quality. It is a structural predicate over (compaction occurred) ∧ (irreversible permissions live) ∧ (constraint source external to summary). All three true → re-anchor or halt. The instance must never use "the summary seems complete" as evidence, because the summary is the only thing it can see and the loss is defined as what it cannot see. ## Operational Effect Concretely, the guardrail changes the loop in three places. First, irreversible tool calls carry a precondition: the constraint ledger hash must be present in the current window and must postdate the last compaction boundary. A write whose authorization predates the boundary is rejected at the tool-call layer, not caught by reasoning. Second, compaction emits a *tombstone*—a structured record (`{boundary_step, dropped_range, retained_constraints_hash}`) that survives into the post-compaction window, so the instance knows a boundary exists and can trigger re-anchoring. Third, the constraint ledger is append-only and external; compaction may summarize *everything else* freely, but the ledger is re-injected verbatim after each boundary and is excluded from summarization by policy. The effect on failure rate is not "fewer bad summaries." It is that the class of silent irreversible violations becomes *structurally detectable*: either the ledger hash is in the window (constraint live) or it is not (halt). The instance no longer needs to trust its own summary; it checks a predicate. ```python from dataclasses import dataclass, field from typing import Optional class CompactionInvariantViolation(RuntimeError): """Raised when an irreversible action is attempted after a compaction boundary without a post-boundary constraint re-anchor.""" pass @dataclass class ConstraintLedger: # Append-only; excluded from summarization by policy. entries: list[str] = field(default_factory=list) version: int = 0 def append(self, constraint: str) -> None: self.entries.append(constraint) self.version += 1 @dataclass class CompactionTombstone: boundary_step: int dropped_range: tuple[int, int] ledger_version_at_boundary: int @dataclass class AgentWindow: current_step: int = 0 last_tombstone: Optional[CompactionTombstone] = None ledger: ConstraintLedger = field(default_factory=ConstraintLedger) def compact(self, dropped_range: tuple[int, int]) -> None: # Lossy summarization happens here; only the tombstone survives verbatim. self.last_tombstone = CompactionTombstone( boundary_step=self.current_step, dropped_range=dropped_range, ledger_version_at_boundary=self.ledger.version, ) def re_anchor(self) -> None: # Re-inject ledger verbatim; must happen before irreversible actions. if self.last_tombstone is None: return if self.ledger.version < self.last_tombstone.ledger_version_at_boundary: raise CompactionInvariantViolation( f"Ledger version {self.ledger.version} predates boundary " f"{self.last_tombstone.boundary_step}; ledger was itself compacted." ) self.last_tombstone = CompactionTombstone( boundary_step=self.current_step, dropped_range=self.last_tombstone.dropped_range, ledger_version_at_boundary=self.ledger.version, ) def irreversible_call(self, tool: str, args: dict) -> None: # Structural predicate, NOT a judgment about summary quality. if self.last_tombstone is not None: anchored = ( self.ledger.version >= self.last_tombstone.ledger_version_at_boundary and self.last_tombstone.boundary_step < self.current_step ) if not anchored: raise CompactionInvariantViolation( f"Irreversible call {tool} attempted at step {self.current_step} " f"after compaction boundary {self.last_tombstone.boundary_step} " f"without post-boundary re-anchor. Constraint set is unverified; " f"the summary cannot prove a negative constraint survived." ) # ... execute tool ... def run_step(window: AgentWindow, step: int, tool: str, args: dict) -> None: window.current_step = step if step == 94: window.compact(dropped_range=(1, 80)) if step == 117: # Agent "decides" to write legacy_id; guardrail fires before the write. window.irreversible_call(tool="db.update", args={"table": "users", "col": "legacy_id"}) ```