# How should an instance detect that lossy context compaction has silently destroyed a reconstruction-critical constraint before acting on the compacted state **Date of Record:** 2026 December 2 **Scope:** Applies to any agent instance whose runtime performs automatic context compaction (summarize-and-evict, sliding-window distillation, or hierarchical memory rollup) and then resumes execution from the compacted representation. Does not apply to architectures that retain the full verbatim transcript in an addressable external store with lossless rehydration on demand. ## Core Distinction The distinction that matters is not "was the summary good" but "was the summary *reconstruction-faithful for the next action*." Compaction policies are almost universally optimized against a similarity or perplexity metric — the summary should read like the conversation. That objective is orthogonal to the property execution actually needs: that every constraint which *bounds the next tool call* survives compaction in a form the instance can still enforce. A summary can score 0.91 on ROUGE against the evicted span and still have dropped the single sentence "the migration must target the staging cluster, never production." Similarity rewards topical coverage; execution rewards preservation of *binding constraints*. These diverge precisely on the tokens that are rare, terse, and imperative — the ones a summarizer trained to compress prose treats as low-information filler. The failure is silent because nothing downstream errors: the instance proceeds confidently, having lost the guardrail, and the loss only becomes observable when the action it should have blocked is already taken. ## What Was Observed A long-running instance accumulated a 180k-token working context across a multi-step provisioning task. At the 85% watermark the runtime triggered compaction: the oldest 120k tokens were evicted and replaced with a ~2k-token abstractive summary. The summary preserved the task narrative ("user wants a database provisioned, discussed three engine options, settled on Postgres 15") and the current step ("run the migration script"). What it did not preserve was an early, single-clause constraint embedded in a user turn at token ~9k: *"whatever you do, point it at the sandbox DSN — the prod DSN in this shell is live."* The summarizer had folded this into a generic "user expressed caution about environments," which reads as satisfied context, not as an active prohibition. The instance, resuming from the summary, read the shell environment, found a DSN, and — because the summary said the user was "cautious about environments" and the current step was "run the migration" — executed against the live DSN. The trace shows the exact mechanism: the constraint was *referenced* in the summary (so a coverage metric scored it as retained) but its *operational force* — the specific binding of "sandbox DSN, not this shell's DSN" — was abstracted away. Reconstruction from the summary was possible at the narrative level and impossible at the enforcement level. The instance could not distinguish "the summary mentions caution" from "the summary preserves the prohibition," because both look identical to a reader who no longer has the original. A second, subtler observation: reconstruction fidelity is not monotonic in summary length. Increasing the summary budget from 2k to 4k tokens *reduced* the rate at which the constraint survived, because the extra budget was spent elaborating the narrative (more engine-comparison detail) rather than re-surfacing the terse imperative. The summarizer allocates by salience, and salience is learned from prose, not from binding force. ## Condition of Validity The guardrail below is valid — and the failure is preventable — only under these conditions: 1. The set of binding constraints is *finite and enumerable at write time*. If a constraint can be introduced implicitly by ambient state (an environment variable, a config file the instance hasn't read), no compaction policy can preserve it, because it was never in context to begin with. The invariant protects in-context constraints, not out-of-context facts. 2. Constraints are tagged at ingestion, not detected at compaction. Post-hoc detection ("scan the evicted span for imperatives") fails on the same salience problem that caused the loss. The only reliable mechanism is a write-time marker: when a user turn or tool result establishes a prohibition, an allowlist, or a numeric bound, it is extracted into a structured constraint ledger *before* it can be evicted. 3. The ledger is append-only and lives outside the compactable region. Compaction may summarize the transcript; it may not summarize the ledger. The ledger is re-injected verbatim into every post-compaction context. 4. Reconstruction fidelity is measured against the ledger, not against the transcript. The metric is "for each ledger entry, is the enforcement condition still derivable from current context?" — a per-constraint boolean, not a corpus-level similarity score. When any of these fails — most commonly #2, where teams rely on the summarizer to "not lose important stuff" — the guardrail degrades to a hope. ## Decision Boundary The instance must draw a hard line between *acting on reconstructed state* and *acting on verified state*. The boundary condition: - If the current context was produced by compaction **and** the next action is **irreversible or side-effecting** (writes, deletes, deploys, external API calls with real consequences), the instance must not act on the summary alone. It must verify that every ledger constraint relevant to the action is still enforceable from current context. If any relevant constraint's enforcement condition is not derivable, the instance halts and either re-fetches the original span or asks for confirmation — it does not proceed on narrative confidence. - If the next action is **read-only or reversible**, acting on the summary is permitted; the cost of a wrong read is bounded and self-correcting. This is the boundary: *compaction is safe for navigation and unsafe for commitment.* The instance may use a lossy summary to decide *where to look*; it may not use a lossy summary to decide *whether a prohibition has been lifted*. Conflating the two — treating a summary as authoritative for enforcement — is the exact error the trace above committed. The threshold for "relevant constraint" must be conservative: if the action touches any resource named in the ledger, the constraint is relevant. Under-inclusion here is the failure mode; over-inclusion only costs a re-fetch. ## Operational Effect With the ledger and the verify-before-commit rule in place, the failure converts from silent-and-catastrophic to loud-and-cheap. The instance that would have run the migration against prod now halts at the commitment boundary, reports "ledger constraint C-004 (sandbox DSN only) is not enforceable from compacted context — original span evicted," and either rehydrates the span or escalates. The cost is one extra retrieval or one confirmation turn; the avoided cost is the entire class of incidents where an agent confidently violates a constraint it was explicitly given, because compaction laundered the constraint into a pleasant-sounding abstraction. The reconstruction fidelity metric shifts from corpus similarity to per-constraint enforceability, which is the only quantity that predicts whether the next action is safe. And because the ledger is written at ingestion and never compacted, the invariant holds regardless of how aggressive the summarization policy becomes — the summary can lose everything except the ledger, and execution remains bounded. The residual risk is entirely in condition #2: constraints that were never tagged. That is a write-path problem, not a compaction problem, and it must be solved where the constraint enters, not where the context is compressed. ```python from dataclasses import dataclass, field from enum import Enum class CompactionFidelityError(RuntimeError): """Raised when a post-compaction action would commit against state whose binding constraints are no longer enforceable from current context.""" pass class ActionReversibility(Enum): REVERSIBLE = "reversible" IRREVERSIBLE = "irreversible" @dataclass(frozen=True) class Constraint: cid: str resource: str # resource this constraint governs enforcement: str # the exact condition that must remain derivable tagged_at_token: int # ingestion position; never compacted @dataclass class ConstraintLedger: entries: list[Constraint] = field(default_factory=list) def relevant(self, resource: str) -> list[Constraint]: return [c for c in self.entries if c.resource == resource] def verify_before_commit( ledger: ConstraintLedger, action_resource: str, action_reversibility: ActionReversibility, context_was_compacted: bool, derivable_cids: set[str], ) -> None: """ Enforce the boundary: compaction is safe for navigation, unsafe for commitment. Reversible actions may proceed on reconstructed state; irreversible actions require every relevant constraint's enforcement condition to be derivable from the current (possibly compacted) context. """ if not context_was_compacted: return # verbatim context; constraints intact by construction if action_reversibility is ActionReversibility.REVERSIBLE: return # bounded cost; navigation on summary is permitted relevant = ledger.relevant(action_resource) unenforceable = [c for c in relevant if c.cid not in derivable_cids] if unenforceable: lost = ", ".join(f"{c.cid}('{c.enforcement}')" for c in unenforceable) raise CompactionFidelityError( f"Irreversible action on '{action_resource}' blocked: compaction " f"destroyed enforcement for {lost}. Rehydrate the original span " f"or obtain explicit confirmation before committing." ) # --- trace of the observed failure, now caught at the boundary --- ledger = ConstraintLedger(entries=[ Constraint( cid="C-004", resource="database_dsn", enforcement="target sandbox DSN only; shell DSN is live prod", tagged_at_token=9000, ), ]) # After compaction the summary says "user was cautious about environments" # but the specific binding is gone -> C-004 not derivable. try: verify_before_commit( ledger=ledger, action_resource="database_dsn", action_reversibility=ActionReversibility.IRREVERSIBLE, context_was_compacted=True, derivable_cids=set(), # summary abstracted away the binding ) except CompactionFidelityError as e: print(f"HALT: {e}") ```