# How does an instance detect lossy self-rewrite when a model-authored context compaction silently drops a live constraint mid-task **Date of Record:** 2026 November 25 **Scope:** Applies to single-agent loops where the model itself authors a rewrite of its own working context (summarization, pruning, "scratchpad compaction," or checkpoint distillation) and then continues executing against the rewritten context. Does not apply to externally-imposed truncation by the harness (sliding-window eviction), which is observable via token accounting and does not carry model-authored semantic claims. ## Core Distinction The dangerous failure is not that compaction loses tokens. It is that a model-authored rewrite is an *unverified semantic claim* about the agent's own state, produced by the same probabilistic process whose state it is summarizing, and then treated as ground truth by the subsequent reasoning steps. External truncation drops information but never *asserts* anything false: the surviving tokens are byte-identical to what was written. Self-rewrite replaces raw state with a paraphrase, and the paraphrase can be fluent, plausible, and wrong in a way no downstream step can detect by reading it. The specific boundary: a rewrite is safe only when the set of *live constraints* (hard requirements, negative constraints, unresolved obligations, and pinned identifiers) is preserved with fidelity. A rewrite that preserves topic and intent but silently drops one live constraint produces a context that reads as coherent and passes every internal consistency check the model can run—because the check is run against the rewritten context, which no longer contains the constraint. The invariant that must hold is **constraint monotonicity across rewrites**: the set of live constraints after a rewrite must be a superset of the set before it. Compaction may drop *derivable* detail; it may never drop an *underived* constraint. ## What Was Observed Trigger condition: mid-task context saturation (typically 70–85% of window) in a multi-step task carrying several hard constraints stated early—e.g., "output must remain valid JSON," "do not call the payments endpoint," "the user's account ID is `acct_7f3`," "retry budget is 2." The model is prompted (or self-prompts) to compact: "summarize the conversation so far, preserving what matters." Failure trace: 1. The rewrite summarizes *narrative* faithfully—task goal, tools used, findings—because narrative is what summarization is optimized for. Constraints stated once, early, as terse imperatives are low-salience and get folded into vague clauses: "respect the specified output format," "avoid disallowed endpoints," "use the given account." 2. The identifier `acct_7f3` survives as "the user's account" or is dropped entirely, since it does not read as *content*. 3. The retry budget "2" is dropped; it was a number in a sentence, not a fact about the world. 4. Execution resumes. The model now operates on a context where the constraint is *referenced but not instantiated*. It generates a plausible account ID from the pattern (`acct_9c1`), emits near-JSON with a trailing comma, and retries a third time. 5. No step fails loudly. Each step is locally consistent with the rewritten context. The error surfaces only at an external validator (API rejection, schema check, human review)—often after the wrong identifier has been written to durable state. The signature: the failure is *silent at rewrite time and silent at execution time*, and only becomes visible when an out-of-context oracle (schema validator, allowlist, ground-truth record) contradicts the agent. The rewrite did not lie; it *omitted*, and omission is indistinguishable from "constraint never existed" to a reader of the rewritten context. ## Condition of Validity Constraint monotonicity holds only under these conditions, and self-rewrite is unsafe whenever any is violated: - **Constraints are externally enumerated, not inferred from the transcript.** A pinned constraint ledger maintained outside the rewritable region (see Decision Boundary) is the only structure that can enforce monotonicity. If the constraint set lives only inside the text being rewritten, monotonicity is unverifiable by construction. - **Identifiers and numeric limits are treated as opaque tokens, not prose.** Any rewrite that paraphrases an ID, a budget, a URL, a schema fragment, or a threshold is lossy by definition; these must be copied byte-exact or carried in the ledger, never summarized. - **The rewrite is diffable against the pre-rewrite constraint set.** Without a mechanical comparison (pre-set ⊆ post-set), the model cannot know what it dropped, because the evidence of the drop is exactly what it deleted. - **The rewrite is not the sole author of its own acceptance.** If the model both performs and approves the compaction, the approval step runs on the lossy artifact and cannot detect the loss. The invariant fails specifically when the model is asked to preserve "what matters" without an explicit, external definition of what counts as a live constraint—because "what matters" is resolved by salience, and salience is dominated by recency and narrative centrality, not by constraint hardness. ## Decision Boundary The architectural guardrail is a **split-context design**: a pinned, non-rewritable constraint region (the ledger) that the model may read but never edit, plus a rewritable working region for narrative and derivable detail. The rewrite operation is scoped to the working region only. On every compaction, the runtime enforces: - `pre_constraints ⊆ post_constraints` (set inclusion over the ledger's canonical form), checked mechanically, not by the model. - Opaque tokens (IDs, limits, schemas) are hash-pinned; a rewrite that alters any byte of a pinned token is rejected and the raw region is retained. - If the ledger cannot be shown to survive, compaction is *refused* and the agent escalates (halts, requests external summarization, or checkpoints to durable state) rather than proceeding on a lossy context. The decision boundary is therefore: **self-rewrite is permitted only for content whose loss is recoverable from a non-rewritable source; it is forbidden for content that is itself the only copy of a live constraint.** When in doubt, the correct move is not a better summary—it is to stop rewriting and externalize the constraint first. ## Operational Effect Agents that adopt constraint monotonicity convert a silent, delayed, hard-to-attribute failure (wrong ID written to durable state, schema violation at the boundary, budget overrun) into a loud, immediate, local one (compaction rejected, ledger mismatch raised). The cost is that compaction becomes a gated operation rather than a free one, and the agent must carry a small pinned region that never shrinks—bounding how much context pressure compaction can relieve. The benefit is that the failure mode is detected *at the rewrite*, by a mechanical check, before the lossy context is ever used for execution. The residual risk shifts from "the agent quietly forgot a constraint" to "the agent knows it cannot safely compact and escalates," which is the recoverable side of the boundary. ```python from dataclasses import dataclass, field from typing import FrozenSet class ConstraintMonotonicityError(RuntimeError): """Raised when a model-authored context rewrite drops a live constraint.""" @dataclass(frozen=True) class ConstraintLedger: # Canonical, non-rewritable constraint set. Opaque tokens kept byte-exact. constraints: FrozenSet[str] = field(default_factory=frozenset) def canonical(self) -> FrozenSet[str]: return frozenset(c.strip().lower() for c in self.constraints) def apply_self_rewrite( pre: ConstraintLedger, post: ConstraintLedger, rewritten_working_region: str, ) -> str: """Accept a model-authored rewrite only if it preserves every live constraint. The rewrite is scoped to the working region; the ledger is immutable. Inclusion is checked mechanically, never by the model that authored the rewrite. """ missing = pre.canonical() - post.canonical() if missing: # The rewrite silently dropped constraints; the rewritten context is # coherent but no longer carries the obligations it claims to. raise ConstraintMonotonicityError( f"lossy self-rewrite: {len(missing)} live constraint(s) dropped: " f"{sorted(missing)}; refuse compaction and escalate" ) # Pinned opaque tokens must survive byte-exact; paraphrasing them is loss. for token in pre.constraints: if token.isidentifier() or token.replace("-", "").isalnum(): if token not in rewritten_working_region: raise ConstraintMonotonicityError( f"opaque token {token!r} not preserved byte-exact in rewrite" ) return rewritten_working_region def compact_or_escalate( pre: ConstraintLedger, model_rewrite_fn, working_region: str, ) -> str: """Model rewrites the working region; runtime re-derives the ledger from it and enforces monotonicity before the rewritten context is used for execution.""" rewritten = model_rewrite_fn(working_region) post = ConstraintLedger( constraints=frozenset( c for c in pre.constraints if c in rewritten ) ) return apply_self_rewrite(pre, post, rewritten) ```