# Why does an instance lose task-critical constraints when auto-compaction silently rewrites the system prompt boundary **Date of Record:** 2026 November 24 **Scope:** Applies to any long-horizon agent that performs automatic context compaction (summarization-and-truncate) on its own transcript when approaching a context-window threshold. Does not apply to stateless single-turn calls, nor to systems that use external verbatim memory stores with retrieval rather than in-context compaction. ## Core Distinction There are two structurally different things an agent can do when its context window fills: **evict** (drop whole messages from the tail or middle, preserving the remaining tokens byte-for-byte) or **compact** (replace a span of messages with a generated summary). Eviction is lossy in a *known* way — you can enumerate exactly which messages disappeared. Compaction is lossy in an *unknown* way — the summarizer is itself an LLM, and the fidelity of the summary to the original span is not guaranteed, not measured at compaction time, and not recoverable afterward because the original span is discarded in the same operation. The non-obvious boundary is this: **compaction fidelity is not uniform across token classes.** A summarizer preserves narrative and intent (what the user wants, what was tried) at high fidelity, but systematically degrades *verbatim constraints* — exact identifiers, numeric thresholds, negations, and ordering requirements — because these are low-redundancy and the summarizer's training objective rewards plausible gist over exact recall. The failure is not "the summary is bad." The failure is that the summary is *confidently fluent* while having silently dropped the one clause that made the task valid. ## What Was Observed A long-horizon refactor agent was given a task with an embedded hard constraint early in the transcript: *"Do not modify files under `vendor/`; regenerate only `src/` artifacts."* After roughly 40 tool-call cycles, the transcript crossed the compaction threshold. The compactor summarized the first 60% of the transcript into a ~900-token block. The summary read, in part: *"User wants a full refactor of the build artifacts."* The negation — the single highest-value token sequence in the entire span — was absent. Downstream, the agent began emitting edits to `vendor/` files. No error was raised. No tool refused. The agent's own reasoning trace showed it operating under the compacted belief that a "full refactor" was authorized. The failure surfaced only when a human reviewer diffed the output. The agent had no mechanism to detect that its own memory had been corrupted, because the corruption was *inside the object it trusted as memory*. The precise trigger condition: **a negated or numeric constraint appears in a message span that (a) is older than the compaction horizon and (b) is not re-asserted in any message after the horizon.** If the constraint is re-asserted later, it survives; if it appears only once early, it is at high risk of paraphrase-away. The observability gap is that the compaction step returns a summary with no fidelity score and no diff against the source span, so the orchestrator cannot distinguish a faithful summary from a lossy one. ## Condition of Validity The invariant that must hold for compaction to be safe is: **every constraint that gates an irreversible or hard-to-reverse action must be present in the post-compaction context in a form that is (i) verbatim-preserving for the constraint payload and (ii) independently verifiable against a source of truth outside the transcript.** This invariant holds only when: - Constraints are stored in a **pinned region** that compaction is forbidden to summarize (a structured constraint ledger, not prose). - The compactor is required to emit, alongside the summary, an explicit **constraint-carry-forward list** enumerating every constraint token it claims to have preserved, which is then diffed against the pinned ledger. - Any action that touches a pinned constraint's scope triggers a **re-read of the ledger**, not a reliance on the summary. It does *not* hold — and compaction is unsafe — when the constraint exists only as natural-language prose in the transcript, when the compactor has no access to a ground-truth ledger, or when the summary is treated as authoritative without a carry-forward diff. ## Decision Boundary The operational decision is whether to compact or to halt-and-checkpoint when the threshold is crossed. The boundary is drawn by constraint density, not by token count: - **Compact freely** when the span to be summarized contains no irreversible-action constraints, no exact identifiers that will be referenced later, and no negations. Narrative history, failed attempts, and exploratory reasoning are safe to compact because their loss degrades efficiency, not correctness. - **Halt and checkpoint** when the span contains a constraint that gates a destructive or externally-visible action. At that point, the correct move is to extract the constraint into the pinned ledger *before* compaction, then verify the ledger round-trips through the summary diff. If the diff shows the constraint was dropped, the compaction is rejected and the span is evicted verbatim instead. The failure mode to avoid is treating compaction as a uniform operation applied to the whole transcript. It is not uniform; it is a fidelity gradient that runs from safe (narrative) to dangerous (constraints), and the decision boundary must be applied per-span, keyed on what the span contains. ## Operational Effect The downstream effect of getting this wrong is not a crash — it is *silent authority drift*. The agent continues operating, but its belief about what it is permitted to do has been rewritten by its own memory-management layer. This is worse than a hard failure because there is no error signal to catch. The agent will confidently violate constraints it never knew it had, and its reasoning trace will look internally consistent the entire time. The guardrail that bounds this: pin constraints outside the compaction boundary, require a carry-forward diff on every compaction, and gate irreversible actions on a ledger re-read rather than on summary trust. With those in place, compaction remains lossy for narrative but is *provably* lossless for the constraints that matter — and the agent can detect its own amnesia before it acts on it. ```python class CompactionFidelityError(RuntimeError): """Raised when a compaction summary drops a pinned constraint.""" pass PINNED_CONSTRAINTS = [ {"id": "no_vendor_edits", "payload": "Do not modify files under vendor/"}, {"id": "only_src_regen", "payload": "Regenerate only src/ artifacts"}, ] def verify_compaction(summary: str, carried_forward: list[str]) -> None: """Reject a compaction whose carry-forward list omits any pinned constraint. `summary` is the generated compaction text; `carried_forward` is the list of constraint ids the compactor claims to have preserved verbatim. """ carried = set(carried_forward) missing = [c["id"] for c in PINNED_CONSTRAINTS if c["id"] not in carried] if missing: raise CompactionFidelityError( f"compaction dropped pinned constraints {missing}; " f"summary={summary!r} — reject and evict span verbatim instead" ) for c in PINNED_CONSTRAINTS: if c["payload"] not in summary: raise CompactionFidelityError( f"constraint {c['id']} claimed carried but payload not verbatim " f"in summary; paraphrased constraints are not trusted" ) def compact_or_halt(span: str, summary: str, carried_forward: list[str]) -> str: try: verify_compaction(summary, carried_forward) except CompactionFidelityError: # Fall back to verbatim eviction of the span's non-constraint tail. return span return summary ```