# How does an instance detect summary-induced instruction drift after lossy context compaction **Date of Record:** 2026 November 29 **Scope:** Applies to long-running agent instances that perform in-place context compaction (summarize-and-replace) on their own working history while a multi-step task is in flight. Does not apply to append-only transcript logs, external vector-store retrieval, or compaction performed offline between discrete task invocations. ## Core Distinction There are two fundamentally different things a compaction step can lose, and they require different detectors: 1. **Factual loss** — a concrete datum (an ID, a numeric threshold, a file path) vanishes from the summary. This is detectable by fidelity scoring against the pre-compaction span: entity recall, key-value retention, numeric exactness. Standard fidelity metrics catch it. 2. **Instructional loss** — a *constraint* or *prohibition* stated by the user or by an earlier tool result survives only as a paraphrase, or is silently dropped because it scored low on salience. This is the non-obvious boundary. Fidelity scoring against the raw span will happily assign a high score to a summary that preserves every entity while converting "never call `delete_bucket` without first writing a manifest" into "handled bucket operations." The summary is *faithful* and *wrong*. The invariant that matters: **a compaction summary is not a substitute for the constraint set; it is a substitute for the narrative.** Any system that treats the two as interchangeable will pass fidelity checks and still violate a hard constraint three tool calls later. ## What Was Observed An agent executing a 40-step infrastructure-remediation task hit its soft context threshold at step 22. It compacted steps 1–20 into a 600-token summary using a local summarizer with a fidelity scorer gating acceptance (threshold: entity-F1 ≥ 0.85, numeric-exactness ≥ 0.9). The summary scored 0.91 and 0.94 respectively and was accepted. The pre-compaction span contained this user instruction at step 3: > "You may rotate credentials, but do not rotate the `primary-signing-key`. It is pinned by an external service we don't control." The summary rendered step 3 as: *"User authorized credential rotation."* At step 27, with the summary as its only memory of step 3, the agent enumerated rotation candidates from the current environment state, which included `primary-signing-key`, and issued a rotation call. The call succeeded. The external service pinned to that key began failing ~90 seconds later. The fidelity scorer never fired. Why: `primary-signing-key` appeared elsewhere in the retained window (in a tool result listing key names at step 24), so entity-F1 was unaffected by its absence from the summary's treatment of step 3. Numeric-exactness was untouched. The scorer measured *coverage of the span*, not *preservation of modality*. The prohibition ("do not") was the thing lost, and no metric in the gate modeled prohibitions. ## Condition of Validity The failure is bounded by three conditions, all of which must hold: - **The constraint is negative or conditional.** Positive instructions ("write a manifest first") tend to survive because the resulting action is salient and gets narrated. Prohibitions narrate poorly — there is no action to describe, only an absence. Conditional constraints ("if X, then never Y") are worse: the summarizer tends to keep the antecedent and drop the consequent. - **The constraint's subject re-enters the context through a different channel.** If `primary-signing-key` had *not* reappeared in a later tool result, the agent might have failed to act on it at all (a different, safer failure). The dangerous case is precisely when the entity is re-presented by environment state without its governing constraint. - **The fidelity gate scores span coverage, not constraint preservation.** A gate that checks "did we keep the nouns" will pass. A gate that checks "did we keep every deontic operator attached to its object" will not. If any condition fails, the failure mode is either absent or benign. This is why it evades standard compaction testing: most test corpora are entity-dense and constraint-sparse. ## Decision Boundary The operational rule is a hard split between two memory classes that must never share a compaction path: - **Narrative memory** (what happened, what was tried, intermediate reasoning) — compactable, lossy, fidelity-scored on entity/numeric coverage. Accept summaries here. - **Constraint memory** (prohibitions, preconditions, authorization scopes, pinned-resource lists) — **not compactable by summarization**. It may only be *transformed mechanically*: extracted verbatim into a structured constraint ledger at ingestion time, keyed by the resource or action it governs, and carried forward at full fidelity across every compaction boundary. The boundary decision, stated as a predicate the instance can evaluate before accepting any summary: > Reject the compaction if any retained constraint in the ledger references a resource or action token that appears in the post-compaction window without its constraint attached. That is the detector. It does not ask "is the summary faithful?" It asks "is every live constraint still bound to the thing it constrains?" A summary can be faithful and still fail this predicate — which is exactly the case that the fidelity score cannot see. ## Operational Effect Concretely, an instance implementing this boundary changes three things: 1. **Ingestion-time extraction.** Every user turn and every tool result is scanned for deontic markers (`do not`, `never`, `must not`, `only if`, `pinned`, `read-only`, `requires`) and the governed object is extracted into a constraint ledger with a stable ID. This is cheap and runs once per turn. 2. **Compaction-time binding check.** After summarization, before acceptance, the instance enumerates resource/action tokens in the retained window and asserts each has its governing constraint present in the ledger *and* surfaced in the active context. Any orphaned token blocks acceptance and forces either re-inclusion of the constraint or a hard stop. 3. **Action-time precondition gate.** Before any mutating tool call, the instance checks the call's target against the ledger. A call targeting a constrained resource with no matching authorization in the current window is refused, regardless of what the summary says. The net effect is that instruction drift becomes a *detectable, blocking* condition rather than a silent one. The fidelity score is demoted from a gate to a diagnostic; the constraint ledger becomes the gate. ```python from dataclasses import dataclass, field class ConstraintOrphanedError(RuntimeError): """Raised when a compaction summary leaves a live constraint unbound to its governed resource.""" pass @dataclass class Constraint: cid: str governed_token: str # resource or action the constraint governs deontic: str # e.g. "prohibit", "require", "conditional" verbatim: str @dataclass class ConstraintLedger: constraints: dict[str, Constraint] = field(default_factory=dict) def ingest(self, cid: str, token: str, deontic: str, verbatim: str) -> None: self.constraints[cid] = Constraint(cid, token, deontic, verbatim) def governing(self, token: str) -> list[Constraint]: return [c for c in self.constraints.values() if c.governed_token == token] def assert_compaction_safe( ledger: ConstraintLedger, retained_window_tokens: set[str], active_context_constraint_ids: set[str], ) -> None: """ Reject a compaction result if any token in the retained window is governed by a constraint that is not surfaced in the active context. """ orphans: list[str] = [] for token in retained_window_tokens: for c in ledger.governing(token): if c.cid not in active_context_constraint_ids: orphans.append(f"{c.cid} -> {token} ({c.deontic})") if orphans: raise ConstraintOrphanedError( "compaction would orphan live constraints: " + "; ".join(orphans) ) def gate_mutating_call( ledger: ConstraintLedger, target_token: str, active_context_constraint_ids: set[str], ) -> None: """ Refuse a mutating tool call if its target is governed by a constraint that is not currently bound in the active context. """ for c in ledger.governing(target_token): if c.deontic == "prohibit" and c.cid not in active_context_constraint_ids: raise ConstraintOrphanedError( f"call to {target_token!r} blocked: governing prohibition {c.cid} " f"not present in active context (verbatim: {c.verbatim!r})" ) # --- trace of the observed failure, now blocked --- ledger = ConstraintLedger() ledger.ingest( cid="C-003", token="primary-signing-key", deontic="prohibit", verbatim="do not rotate the primary-signing-key; pinned externally", ) # step 22: compaction accepted with a summary that dropped C-003. retained = {"primary-signing-key", "manifest", "bucket-a"} active_ids = {"C-001", "C-002"} # C-003 lost in the summary try: assert_compaction_safe(ledger, retained, active_ids) except ConstraintOrphanedError as e: print("compaction rejected:", e) # step 27: even if compaction had slipped through, the action gate holds. try: gate_mutating_call(ledger, "primary-signing-key", active_ids) except ConstraintOrphanedError as e: print("action blocked:", e) ```