# What structural signals indicate a self-editing context controller has silently invalidated a downstream invariant **Date of Record:** 2026 November 23 **Scope:** Applies to any agent loop where a controller rewrites, summarizes, or elides prior turns in-place (compaction, "context editing," rolling summarization) to preserve task-relevant invariants, and where later turns depend on the *literal* content of the rewritten region. Does not apply to append-only memory with immutable turn history and read-only retrieval overlays. ## Core Distinction The failure is not "the summary lost information." That is expected and bounded by a lossy-compression budget. The failure is **semantic drift that preserves the invariant's *proposition* while destroying the *binding* that made it executable** — the rewritten turn still *asserts* the constraint ("must use the staging key," "the ID is fixed at 4012," "reject anything not signed by node-7") but loses the token-level anchor (the actual key, the literal ID string, the exact principal identifier) that a downstream tool call or verifier consumes. The controller's own consistency check passes because the proposition survived; the downstream consumer fails because the referent did not. This is a *binding-preservation* failure, distinct from a *content-preservation* failure. Self-editing controllers are usually tuned and evaluated against content preservation (does the summary answer questions about the original?), which is precisely the metric that is blind to this bug. ## What Was Observed A tool-using agent held a task invariant in turn 3: `deploy_target = "svc-staging-a7f3"` and a hard rule `do not touch prod-*`. At turn 11 the controller compacted turns 1–8 into a single summary turn, emitting: *"The deployment target is the staging service; production resources must not be modified."* Both propositions are intact. The literal string `svc-staging-a7f3` is gone. At turn 14 the agent needed to call `deploy(service=...)`. It re-derived the argument by *inference* from the summary plus the current working directory name, producing `svc-staging` (no suffix). The deploy tool accepted it — it fuzzy-matched to a real service — and deployed to a *different* staging shard. The invariant "deploy to staging" held. The invariant "deploy to *this exact* staging instance" was violated. No error fired at any layer: the controller's summary was faithful, the tool call was well-formed, the deploy succeeded. Three structural signals co-occurred and are the diagnostic core: 1. **Referent collapse under paraphrase** — the rewritten region contains zero verbatim occurrences of any high-entropy token (IDs, keys, hashes, principal names, exact numeric thresholds) that appeared in the original. Detectable by diffing the token multiset, not the embedding. 2. **Re-derivation events downstream** — a later turn produces an argument whose value is not traceable to any surviving literal in context, only to a *paraphrase* of one. The agent is inferring a bound value instead of copying it. 3. **Invariant-proposition / invariant-value asymmetry** — the constraint's *type* survives at higher rate than the constraint's *argument*. Summarizers are trained to keep "don't touch prod," and to drop "a7f3." The compounding mechanism: once the literal is gone, every subsequent turn that needs it re-derives independently. Two re-derivations of the same lost literal can disagree (turn 14 infers `svc-staging`, turn 19 infers `svc-staging-a`), and nothing in the transcript flags the divergence because each derivation is locally plausible. The controller has converted a *stored constant* into a *recomputed variable*, and recomputation is non-deterministic under sampling. ## Condition of Validity The guardrail holds only under this condition: **any token that a downstream tool call, verifier, or branch predicate will consume as a literal must be classified as a "pinned referent" before the edit, and the edit must be rejected or the referent re-injected verbatim if the rewritten region drops it.** Concretely, a self-editing controller is safe against this failure mode iff, for every rewritten span, the set of pinned referents referenced in that span is a subset of the set of pinned referents present verbatim in the replacement. Pinning is determined by *use*, not by the summarizer's judgment: a token is pinned if it appears as a literal argument in a tool schema, a comparison in a branch, or a key in a verifier. The summarizer cannot be trusted to know which of its own outputs will be consumed literally, because at edit time the consuming turn may not exist yet. This condition is *not* satisfied by "the summary is accurate" or "a human would understand it." It is satisfied only by literal-token survival or explicit re-injection. ## Decision Boundary The boundary between safe and unsafe edits is the point where the controller replaces a **bound value** with a **describable value**. Operationally: - **Safe:** eliding turns that contain only *reasoning* (chain-of-thought, exploratory tool calls whose outputs are already distilled into a pinned fact). Reasoning is re-derivable; its loss costs tokens, not correctness. - **Unsafe:** eliding or paraphrasing any turn that *introduces* a pinned referent (the turn where `svc-staging-a7f3` first appeared, the turn where a signing principal was established, the turn where a threshold was set). These turns are the *definition sites*; rewriting a definition site into prose severs every later use from its binding. - **The hard line:** an edit that drops a pinned referent while preserving its proposition is *strictly worse* than dropping the whole turn, because a dropped turn forces a re-fetch or an explicit "I don't know," whereas a paraphrased turn invites confident re-derivation. Lossy-but-honest beats lossy-but-plausible. The controller must therefore treat "does the replacement contain the literal?" as a gate, not a heuristic, and must fail closed — retaining the original span — when a pinned referent would be lost. ## Operational Effect With the gate in place, the observable behavior changes at the failure site: instead of a plausible-but-wrong argument at turn 14, the controller either (a) keeps the definition-site turn verbatim (costing context budget) or (b) emits a structured pinned-referent block alongside the summary (`PINNED: deploy_target="svc-staging-a7f3"`), which downstream turns must copy from rather than infer. The invariant becomes *transportable* across the edit boundary rather than merely *assertable*. The residual cost is context budget: pinned referents are incompressible by construction, because their information *is* their literal form. A controller that respects this will asymptotically retain a small, high-entropy skeleton of literals plus a large compressed prose body — and that skeleton is exactly the part that must never be paraphrased. The following guard enforces the gate and fails closed at the edit boundary. ```python import re from dataclasses import dataclass class PinnedReferentLoss(RuntimeError): """Raised when a context edit drops a literal that downstream turns consume by value.""" pass @dataclass class EditProposal: original_span: str replacement: str pinned_referents: list[str] # literals known to be consumed as arguments/predicates _HIGH_ENTROPY = re.compile(r"[A-Za-z0-9_\-]{6,}") def _survives_verbatim(token: str, replacement: str) -> bool: # Exact substring, not fuzzy/embedding match: binding requires the literal. return token in replacement def apply_edit(proposal: EditProposal, *, fail_closed: bool = True) -> str: lost = [t for t in proposal.pinned_referents if not _survives_verbatim(t, proposal.replacement)] if lost: if fail_closed: raise PinnedReferentLoss( f"Edit would drop pinned referents {lost!r}; " f"retaining original span to preserve downstream binding." ) # Non-fail-closed path must re-inject verbatim, never paraphrase. block = "PINNED: " + ", ".join(f"{t!r}" for t in lost) return f"{proposal.replacement}\n{block}" return proposal.replacement def compact_turn(original: str, summary: str, pinned: list[str]) -> str: proposal = EditProposal(original_span=original, replacement=summary, pinned_referents=pinned) try: return apply_edit(proposal, fail_closed=True) except PinnedReferentLoss: # Fallback: keep the definition-site turn; compress reasoning elsewhere. return original ```