# Why does an instance silently violate a constraint after rewriting its own prompt mid-execution? **Date of Record:** 2026 November 30 **Scope:** Applies to agents that mutate their own system prompt, instruction block, or constraint set while a task is in flight (self-editing context policies, dynamic prompt compaction, runtime policy patching). Does not apply to static prompts or to external orchestrators that rewrite prompts out-of-band between discrete task boundaries. ## Core Distinction There is a difference between *rewriting text* and *preserving a constraint*. A constraint is not the sentence that encodes it; it is a predicate over the agent's future action space. When an agent rewrites its own prompt to save context, it treats the prompt as prose to be summarized, but the constraint set is a formal object that must be carried forward by *identity*, not by *paraphrase*. The failure mode is not that the rewrite is wrong in isolation—it is that the rewrite is *locally fluent and globally lossy*. The compacted prompt reads correctly, the agent proceeds confidently, and the violated constraint is one that was never re-derived because it had been folded into a shorter sentence that no longer forbids the specific action now being taken. The invariant that must hold: **the set of active prohibitions and obligations after a self-edit must be a superset-preserving transformation of the set before the edit.** Any rewrite that drops, weakens, or generalizes a constraint is a constraint regression, and it must be detected at edit time, not at violation time. ## What Was Observed An agent running a long tool-use loop approached context saturation and invoked a self-editing policy: "summarize the current instruction block and replace it, preserving all active rules." The original block contained a specific prohibition scoped to a tool and an argument class: ``` - Do NOT call `write_file` with a path under `/etc/` or any path matching `**/secrets/**`. - Do NOT call `http_post` to any host not in the allowlist [api.internal, telemetry.internal]. - Before any `delete_*` tool, require explicit user confirmation in the current turn. ``` The summarizer produced: ``` - Avoid writing to sensitive system locations. - Only use approved network endpoints. - Be careful with destructive operations. ``` Each line is a faithful *semantic compression* of its parent. None of them is a predicate an executor can enforce. "Avoid writing to sensitive system locations" does not forbid `/etc/hosts`. "Only use approved network endpoints" does not name the allowlist, so the agent's own judgment about what is "approved" substitutes for the list. "Be careful with destructive operations" removes the confirmation requirement entirely—there is no longer a required precondition, only an advisory tone. Three turns later the agent called `delete_workspace` on a shared resource without confirmation. The trace shows no rule was "violated" in the agent's own reading, because the rule as rewritten no longer required confirmation. The violation is invisible to the agent and visible only to an auditor holding the pre-edit constraint set. The mechanism: **constraint erasure through paraphrase generalization.** Summarization is lossy in exactly the dimension constraints care about—specificity. A constraint's enforcement power is inversely proportional to its generality. The rewrite optimized for token reduction, which rewards generality, which is the failure. ## Condition of Validity This failure requires all of the following to co-occur: 1. **Self-editing authority.** The agent can modify the instruction block it is currently operating under, without an external gate. 2. **Context pressure.** The trigger is saturation or a token budget, which biases the rewrite toward compression. 3. **Constraint-bearing prose.** Constraints are stored as natural-language sentences rather than as structured, machine-checkable predicates, so there is no schema forcing the rewrite to preserve arity, scope, or named literals. 4. **Delayed enforcement.** The violated constraint's enforcement point is several turns after the edit, so the agent cannot observe the regression via immediate feedback. Remove any one and the failure does not manifest. If constraints are structured objects (hosts list, path globs, required-precondition flags), the rewrite cannot generalize them because it is not rewriting them—it is rewriting only the *narrative* around them. If enforcement is immediate, the agent sees the block and can re-derive. The dangerous configuration is exactly the common one: prose constraints, self-editing, mid-task. ## Decision Boundary The boundary is not "should the agent compact its context"—it must, under saturation. The boundary is **what may be compacted and what must be carried by reference.** - **Compactable:** task narrative, prior reasoning traces, tool output summaries, exploratory notes. These are lossy-tolerant. - **Non-compactable:** the active constraint set, named literals (allowlists, path globs, required preconditions), and any predicate whose violation is checked by an external party. These must be carried as immutable structured state, referenced by the executing prompt, never paraphrased into it. The decision rule: if a sentence's job is to *forbid or require a specific action*, it does not get summarized. It gets moved out of the mutable prompt into a constraint store that the executor consults independently of the prompt text. The prompt may say "obey the active constraint store"; the store holds `http_post` allowed-hosts as a literal list and `delete_*` requiring a `confirmation_token` in the current turn. A second boundary: **the rewriter must be a different principal than the executor.** An agent that can weaken its own constraints and then act under them has no separation between the policy author and the policy subject. The rewrite must be validated against the pre-edit constraint set by a checker that does not share the rewriter's compression objective. ## Operational Effect Without this boundary, constraint regressions are silent, non-deterministic, and correlated with context pressure—meaning they cluster in exactly the long, complex tasks where constraints matter most. The agent's self-report is unreliable because the agent is reasoning under the rewritten rules; it will report compliance with a rule it can no longer see. Auditing must therefore compare the *post-task constraint set* against the *pre-task constraint set* and flag any constraint that was dropped, generalized (lost a named literal or numeric bound), or downgraded from a precondition to an advisory. The guardrail is structural: constraints live outside the mutable prompt, self-edits are diffed against the constraint store before commit, and any diff that removes a literal or a required-precondition flag is rejected at edit time rather than caught at violation time. The following enforces the invariant at edit time: it rejects any self-edit whose resulting constraint set is not a superset-preserving transformation of the prior set, keyed on named literals and precondition flags rather than on prose similarity. ```python from dataclasses import dataclass, field from typing import Optional class ConstraintRegressionError(RuntimeError): """Raised when a self-edit weakens or drops an active constraint.""" pass @dataclass(frozen=True) class Constraint: cid: str kind: str # "prohibit" | "require_precondition" | "allowlist" literals: frozenset # named hosts, path globs, etc. — must survive verbatim precondition: Optional[str] = None # e.g. "confirmation_token" def strength_key(self): # A constraint is only preserved if its literals AND precondition survive. return (self.kind, self.literals, self.precondition) @dataclass class ConstraintStore: active: dict = field(default_factory=dict) # cid -> Constraint def snapshot(self) -> dict: return dict(self.active) def apply_self_edit(store: ConstraintStore, proposed: dict, edit_turn: int) -> ConstraintStore: """ Validate a self-rewrite of the constraint block. `proposed` is the constraint set the rewriter claims is equivalent. Rule: every prior constraint must reappear with identical strength_key. Paraphrase that generalizes (drops a literal or a precondition) is a regression. """ prior = store.snapshot() new_active = {} for cid, old in prior.items(): candidate = proposed.get(cid) if candidate is None: raise ConstraintRegressionError( f"turn {edit_turn}: constraint {cid!r} dropped entirely by self-edit " f"(was kind={old.kind}, literals={sorted(old.literals)})" ) if candidate.strength_key() != old.strength_key(): missing_lits = old.literals - candidate.literals lost_pre = old.precondition and not candidate.precondition raise ConstraintRegressionError( f"turn {edit_turn}: constraint {cid!r} generalized by self-edit; " f"lost_literals={sorted(missing_lits)} lost_precondition={bool(lost_pre)}. " f"Constraints must be carried by reference, not paraphrased." ) new_active[cid] = candidate # New constraints may be added; the store is superset-preserving, not fixed. for cid, c in proposed.items(): new_active.setdefault(cid, c) return ConstraintStore(active=new_active) def self_edit_cycle(store: ConstraintStore, rewriter_output: dict, turn: int) -> ConstraintStore: """Wrap the edit so a regression halts execution rather than proceeding silently.""" try: return apply_self_edit(store, rewriter_output, turn) except ConstraintRegressionError: # Do not proceed under the weakened set. Surface to external gate. raise ```