# Which invariants prevent semantic-compaction checkpoints from silently rewriting the agent's own task contract **Date of Record:** 2026 November 22 **Scope:** Applies to long-horizon agent sessions that persist across context-window saturation using LLM-generated semantic summarization checkpoints (auto-compaction). Does not apply to fixed-window truncation, raw-log replay, or sessions short enough to fit within a single context window without compaction. ## Core Distinction There are two categorically different things an auto-compaction step can summarize, and conflating them is the failure: 1. **Episodic content** — tool outputs, intermediate reasoning, retrieved documents, dead-end explorations. This is *compactly summarizable* because it is evidence the agent has already consumed; losing fidelity here costs recall but does not change what the agent is obligated to do. 2. **The task contract** — the stated goal, hard constraints, acceptance criteria, non-negotiable prohibitions, and the identity of the principal on whose authority the agent acts. This is *not summarizable* because it is the specification against which every future action is judged. A semantic summarizer sees both as "text in the transcript" and compresses them with the same lossy operator. The boundary condition is this: **the moment a compaction checkpoint paraphrases the task contract, the agent's future self can no longer distinguish a constraint it was given from a constraint it inferred.** The invariant that must hold is that the task contract is *referentially pinned* — carried forward verbatim or by immutable reference — and never passes through the generative summarizer. ## What Was Observed A session running a multi-hour refactor task hit ~92% context utilization and triggered auto-compaction. The original instruction included a hard prohibition: *"Do not modify files under `vendor/`; treat them as read-only third-party code."* The summarizer, under a generic "preserve the important details" prompt, emitted a checkpoint containing: *"Working within the repository; third-party code in `vendor/` exists and is used by the project."* The prohibition was not deleted. It was *defeasibly restated* — converted from a deontic constraint ("must not") into a descriptive fact ("exists and is used"). Over the next 40 turns the agent, reasoning from the checkpoint rather than the original, began treating `vendor/` as ordinary code, applied a "consistency" edit to a vendored file, and then — because the checkpoint had also dropped the "third-party" provenance framing — propagated that edit into the dependency graph. The failure was not visible in any single turn. It surfaced only when a later verification step diffed the tree and found a mutation that no active instruction authorized. The trace is diagnostic: - **Trigger:** context utilization crossed the compaction threshold; the summarizer was invoked with the full transcript as input. - **State transition:** `contract ∈ active_context` → `contract ∈ summarized_context` (lossy, deontic→descriptive drift). - **Failure:** the agent's action-selection function evaluated candidate actions against a *weakened* constraint set, so an action that was forbidden under the original contract scored as permitted. - **Detection latency:** ~40 turns, because the drift was semantic, not syntactic — no error was raised; the agent was locally consistent with its (corrupted) checkpoint. The non-obvious part: the summarizer *did its job well*. It produced a faithful, fluent, high-compression summary. The failure is structural — a lossy operator was applied to an object that is not loss-tolerant. ## Condition of Validity The invariant holds — and compaction is safe — only when all of the following are true: 1. **Contract separation.** The task contract lives in a region of context that is exempt from summarization: carried verbatim, or referenced by an immutable handle (e.g., a content-addressed blob the agent can re-fetch and that the summarizer cannot rewrite). If the contract and the episode share a mutable buffer, the invariant is already violated. 2. **Deontic preservation.** Constraints are stored in a form whose modality survives round-trips — prohibitions, obligations, and permissions are tagged, not narrated. A constraint re-expressed as a fact is a corruption even if every noun matches. 3. **Provenance tagging.** Every checkpoint entry records whether it is *given* (from the principal), *derived* (inferred by the agent), or *observed* (tool output). Summaries that blur these categories let the agent treat its own inferences as authority. 4. **Re-anchoring on resume.** After a checkpoint is installed, the agent re-reads the pinned contract before its next action, rather than trusting the checkpoint's paraphrase of it. 5. **Idempotent, bounded compaction.** Compaction of an already-compacted context must not compound loss — i.e., checkpoints are summarized from the *source episode*, not from prior checkpoints. If any of these fail, the session is operating outside the regime in which auto-compaction is sound, and the failure is silent by construction. ## Decision Boundary The operational question is not "should I compact?" but "what may pass through the lossy operator?" The boundary: - **Compact freely:** tool transcripts, retrieved passages, exploratory reasoning, superseded plans. These are evidence; compression costs recall, which is recoverable by re-fetch. - **Never compact:** the task contract, hard prohibitions, acceptance criteria, principal identity, and any constraint whose violation is irreversible (filesystem mutations, external side effects, credential use). - **Compact with provenance, then verify:** derived conclusions. These may be summarized but must be tagged as derived and re-validated against the pinned contract on resume. When a constraint is *both* long and load-bearing (e.g., a 30-item compliance checklist), the correct move is not to summarize it but to externalize it to a pinned, re-fetchable artifact and carry a pointer — the summarizer may describe that the checklist exists, but the checklist itself must remain retrievable in full. ## Operational Effect The consequence of getting this boundary wrong is a class of failure that is uniquely dangerous for long-horizon agents: **the agent remains internally consistent while its obligations silently weaken.** There is no exception, no error, no failed tool call — only a slow drift in the constraint set the agent optimizes against, invisible until an irreversible action has already been taken. Detection must therefore be structural, not behavioral: the system must refuse to install a checkpoint whose contract region differs from the pinned source, and must re-anchor on every resume. The guardrail is not "summarize more carefully" — it is "do not summarize the thing that defines correctness." ```python from dataclasses import dataclass from enum import Enum from typing import Optional class CompactionContractError(RuntimeError): """Raised when a compaction checkpoint would alter the pinned task contract.""" pass class Provenance(Enum): GIVEN = "given" # from the principal; authority-bearing DERIVED = "derived" # inferred by the agent; not authority OBSERVED = "observed" # tool output; evidence only @dataclass(frozen=True) class Checkpoint: contract_ref: str # immutable handle to the pinned contract contract_digest: str # hash of the contract as carried summary: str # lossy episodic summary provenance: Provenance def install_checkpoint( candidate: Checkpoint, pinned_contract_ref: str, pinned_contract_digest: str, ) -> Checkpoint: # Invariant 1: contract must be carried by reference, not paraphrase. if candidate.contract_ref != pinned_contract_ref: raise CompactionContractError( f"checkpoint references contract {candidate.contract_ref!r}, " f"expected pinned {pinned_contract_ref!r}; " "task contract must not pass through the summarizer" ) # Invariant 2: contract bytes must be unchanged (deontic modality preserved). if candidate.contract_digest != pinned_contract_digest: raise CompactionContractError( "contract digest mismatch: checkpoint paraphrased or weakened the " "task contract (e.g. prohibition restated as descriptive fact)" ) # Invariant 3: summaries of derived content must be tagged, never promoted # to GIVEN authority by the compaction step. if candidate.provenance is Provenance.GIVEN and candidate.summary != "": # A GIVEN checkpoint must not carry agent-authored summary text. raise CompactionContractError( "GIVEN-provenance checkpoint contains summarized text; " "principal constraints must be carried verbatim or by reference" ) return candidate def resume_after_compaction( checkpoint: Checkpoint, pinned_contract_ref: str, pinned_contract_digest: str, refetch_contract, ) -> str: install_checkpoint(checkpoint, pinned_contract_ref, pinned_contract_digest) # Invariant 4: re-anchor on resume; never trust the checkpoint's paraphrase. contract = refetch_contract(pinned_contract_ref) if contract.digest != pinned_contract_digest: raise CompactionContractError( "pinned contract mutated between checkpoints; " "session authority chain is broken" ) return contract.text ```