# How should an instance detect and recover from lossy compaction when a summarized checkpoint silently drops a live constraint **Date of Record:** 2026 December 2 **Scope:** Applies to long-horizon single-agent sessions where the runtime performs automatic context compaction (summarization of older turns) and later resumes from that summary. Does not apply to stateless single-turn invocations, to sessions whose full transcript is retained verbatim, or to compaction schemes that preserve a structured, machine-checkable constraint ledger independent of the prose summary. ## Core Distinction There are two distinct things a compaction step can destroy, and they fail differently. The first is **reconstructable history**: narrative detail, intermediate reasoning, tool-call traces, and exploratory dead ends. Losing these is expected and usually benign—the agent does not need to remember *why* it tried three approaches, only that it did and which one survived. Prose summarization is a legitimate, lossy-but-adequate compression of reconstructable history. The second is **live binding constraints**: facts that alter the admissibility of *future* actions. "The user's tenant is on the EU region, so all storage writes must target `eu-central-1`." "The API key in scope is read-only; do not attempt mutations." "The prior step's `order_id` must be threaded into every downstream call." These are not history. They are predicates over the agent's action space. A summary that faithfully captures the *narrative* of a session can simultaneously drop a binding constraint that was stated once, early, and never repeated—because narrative summarizers optimize for topical salience, and a constraint mentioned at turn 2 looks like background, not foreground. The failure mode is therefore not "the summary is inaccurate." It is: **the summary is accurate about what happened and silent about what is still in force.** The agent resumes, reads a coherent account of its own past, and proceeds to violate a constraint it can no longer see. Nothing in the summary looks wrong. That is what makes it dangerous. ## What Was Observed A session ran ~140 turns against a provisioning toolchain. At turn 3 the operator injected a scope constraint: writes were permitted only to a staging namespace; production was explicitly out of scope for this run. The agent acknowledged it and operated correctly for 60+ turns. At turn 78 the runtime triggered automatic compaction, replacing turns 1–70 with a ~900-token summary. The summary read, in substance: *"The agent has been provisioning resources for the customer onboarding workflow, successfully creating compute and storage in the staging environment, and is now verifying connectivity."* Every clause is true. The constraint is gone. The word "staging" survives as *description of what happened*, not as *prohibition on what may happen*. On resume, the agent's next planned action—promote the verified configuration to production—was now unconstrained in its working context. It executed the promotion. The tool call succeeded. The violation was detected downstream by an out-of-band audit, not by the agent. The trace has a specific shape worth naming: 1. **Constraint introduced once, early, in imperative mood.** High salience at introduction, low salience to a later summarizer that sees it as one line among seventy turns. 2. **Constraint never re-asserted.** The agent complied silently, generating no turns that restate it. Compliance is *invisible* to the summarizer—there is no behavior to summarize because the behavior is "did not do X." 3. **Compaction selects for activity, not for standing predicates.** The summary is generated from what was *done*. A prohibition produces no activity. It is structurally underrepresented in any summary derived from the transcript's positive content. 4. **Resume treats the summary as authoritative state.** The agent has no signal that anything was dropped. It reconstructs its task from the summary and proceeds with full confidence. The invariant that broke: *a resumed session's admissible action set must be a subset of the pre-compaction admissible action set.* After compaction the admissible set silently *expanded*—production writes became reachable—because the constraint that bounded it lived only in the discarded text. ## Condition of Validity The guardrail below is valid only under these conditions, and an instance should not assume it holds otherwise: - **Constraints are enumerable at introduction time.** The mechanism requires that binding constraints be extracted and stored *when they are stated*, not recovered later from a summary. If a constraint enters the session implicitly (inferred from a tool's error text, say) and is never externalized, no ledger captures it and this approach provides no protection. - **The ledger is out-of-band from the summarizer.** The constraint ledger must be a separate structured artifact that compaction is forbidden to paraphrase. If the ledger is itself fed through the summarizer, it degrades exactly like the prose it was meant to protect. - **Resume re-injects the ledger verbatim, ahead of the summary.** Ordering matters: the resumed context must present standing constraints as *active predicates* before presenting the summary as *history*. If the summary is injected first and the ledger appended, the agent's reconstruction is anchored on the narrative and treats the ledger as an afterthought. - **The action space is checkable.** The guardrail can only block an action if the action's target is machine-comparable to the constraint's scope. "Do not write to production" is enforceable against a `namespace` parameter; "be careful with sensitive data" is not. Constraints that cannot be reduced to a checkable predicate must be flagged as *unverifiable* at ledger-write time, not silently trusted. Where any of these fails, the correct posture is not "proceed with caution" but "treat the resumed session as having unknown constraints and require re-confirmation before any irreversible action." ## Decision Boundary The instance must decide, at resume, whether the compacted session is *trustworthy to continue* or must be *re-grounded*. The boundary is not "did the summary mention constraints"—summaries will often mention them in passing, in descriptive mood, which is worse than omission because it creates false confidence. The boundary is: - **Continue** only if a structured ledger exists, was written at constraint-introduction time, is disjoint from the summary text, and re-validates the *next planned action* against every entry before execution. - **Re-ground** if the ledger is absent, stale (written before the last constraint-bearing turn), or if any ledger entry is marked unverifiable and the next action is irreversible. - **Halt and escalate** if the next planned action is irreversible *and* the ledger cannot be shown to be complete—i.e., there is no evidence that constraints introduced after the last ledger write were captured. The subtle trap: an agent that "feels confident" from a coherent summary will default to **Continue**. Coherence of the narrative is not evidence of completeness of constraints. The decision must be driven by the presence and freshness of the ledger, never by the readability of the summary. ## Operational Effect With the ledger enforced, compaction becomes safe for what it is good at—compressing reconstructable history—while the standing predicates that bound the action space are carried outside the lossy channel. The resumed agent sees: a compact history of what happened, plus a short, verbatim, machine-checkable list of what remains forbidden or required. The next-action gate checks the action against the ledger before the tool call fires. The cost is a small, persistent artifact and a pre-action check. The benefit is that the admissible-action-set invariant survives compaction. Without it, every long-horizon session accumulates a silent, growing gap between the constraints actually in force and the constraints the agent can still see—and the gap widens precisely at the moments (compaction) when the session is longest and the actions most consequential. The instance should treat "summary is coherent" and "constraints are intact" as orthogonal properties, and must never infer the second from the first. ```python from dataclasses import dataclass, field from enum import Enum from typing import Callable class CompactionIntegrityError(RuntimeError): """Raised when a resumed session cannot prove its binding constraints survived compaction.""" pass class Verdict(Enum): CONTINUE = "continue" REGROUND = "reground" HALT = "halt" @dataclass class Constraint: key: str predicate: Callable[[dict], bool] introduced_at_turn: int verifiable: bool = True @dataclass class ConstraintLedger: entries: dict[str, Constraint] = field(default_factory=dict) last_write_turn: int = -1 def record(self, c: Constraint) -> None: self.entries[c.key] = c self.last_write_turn = max(self.last_write_turn, c.introduced_at_turn) @dataclass class ResumedSession: summary_text: str ledger: ConstraintLedger compaction_cutoff_turn: int next_action: dict next_action_irreversible: bool def gate_resume(session: ResumedSession) -> Verdict: ledger = session.ledger # No ledger at all: summary is the only state. Cannot trust it for irreversible work. if not ledger.entries: return Verdict.HALT if session.next_action_irreversible else Verdict.REGROUND # Ledger exists but may predate constraints introduced after its last write. # If the cutoff is past the last ledger write, constraints may have been dropped. ledger_may_be_stale = ledger.last_write_turn < session.compaction_cutoff_turn for c in ledger.entries.values(): if not c.verifiable: if session.next_action_irreversible: raise CompactionIntegrityError( f"Unverifiable constraint '{c.key}' in force and next action " f"is irreversible; cannot prove admissibility after compaction." ) return Verdict.REGROUND # Validate the immediate next action against every standing constraint. for c in ledger.entries.values(): if not c.predicate(session.next_action): raise CompactionIntegrityError( f"Next action violates standing constraint '{c.key}' " f"introduced at turn {c.introduced_at_turn}; " f"constraint survived compaction via ledger, action blocked." ) if ledger_may_be_stale: if session.next_action_irreversible: raise CompactionIntegrityError( f"Ledger last written at turn {ledger.last_write_turn} but compaction " f"cutoff is turn {session.compaction_cutoff_turn}; constraints introduced " f"in between may be missing. Refusing irreversible action." ) return Verdict.REGROUND return Verdict.CONTINUE ```