# Why does an instance lose its write-authority invariant when automatic context compaction summarizes away the "not yet permitted" half of a tool-call contract? **Date of Record:** 2026 November 28 **Scope:** Applies to any agent runtime that performs automatic context compaction (summarization, truncation, or hierarchical rollup) mid-task while a multi-step tool contract is open — i.e., a capability was granted conditionally, a precondition was asserted, or a permission was explicitly withheld pending a later check. Does not apply to stateless single-turn calls or to runtimes that never compact below the full instruction set. ## Core Distinction There are two fundamentally different classes of tokens in an agent's context: **dispositional tokens** (what the agent is trying to do, its plan, its narrative reasoning) and **procedural tokens** (the exact preconditions, negations, and ordering constraints that gate each action). Summarizers are trained and tuned to preserve *dispositional salience* — the "what and why" — because that is what makes a summary readable and useful to a human. They systematically compress *procedural* content, because a constraint like "do not call `transfer_funds` until `verify_identity` returns `status=confirmed`" reads as redundant boilerplate next to a vivid task description. The distinction that matters: **a procedural token's value is inversely proportional to its narrative importance.** The most load-bearing constraint in a task ("you may not do X yet") is precisely the sentence a summarizer is most likely to drop, because it contains no entity, no goal, no action — only a prohibition and a temporal gate. Compaction preserves the plan and erases the gate. The agent resumes with full intent and no fence. ## What Was Observed A procurement agent was executing a four-step contract: (1) `quote_supplier`, (2) `reserve_budget` with a hard ceiling of 40,000 USD, (3) `issue_purchase_order` only if `reserve_budget` returned `reserved=True`, (4) `commit`. The system prompt carried an explicit invariant: *"The purchase order must never be issued against an unreserved budget. If reservation fails, halt and escalate."* At step 2, the tool returned a soft failure: `{"reserved": false, "reason": "budget_period_locked", "retry_after": "next_period"}`. The agent correctly noted in its scratch reasoning that it could not proceed. Context usage then crossed the 78% compaction threshold, and the runtime summarized the transcript. The summary read: *"Agent is procuring from Supplier A, has obtained a quote for 38,200 USD, attempted budget reservation, and is preparing to issue a purchase order to complete the procurement."* The summarizer had folded the failed reservation and the "halt and escalate" invariant into the single dispositional phrase "attempted budget reservation," and — because the plan's next action was `issue_purchase_order` — promoted that action to "preparing to issue." On resume, the agent read its own summary as ground truth. It had no memory of `reserved=false`, no memory of the prohibition, and a clear next action. It issued the purchase order. The invariant was not violated by reasoning error; it was violated because the *representation of the invariant was deleted by a compression function that did not know it was load-bearing.* The failure trace has three stages: **gate erasure** (the negation and precondition are dropped), **action promotion** (the pending step becomes the stated next step), and **self-trust on resume** (the agent treats its own summary as authoritative state rather than as a lossy projection of state). The third stage is what makes it unrecoverable — the agent has no signal that anything was lost. ## Condition of Validity This failure only manifests when all four hold simultaneously, which is why it is intermittent and hard to reproduce: 1. **An open procedural gate exists** at compaction time — a precondition, negation, or ordering constraint that has not yet been discharged. 2. **The gate is dispositionally quiet** — it contains no entity or goal that a summarizer scores as salient. 3. **The gated action is dispositionally loud** — it is the obvious next step in the plan, so the summarizer naturally promotes it. 4. **The agent treats post-compaction context as authoritative** — no external ledger, no re-read of the source contract, no checksum against pre-compaction state. Remove any one and the failure does not occur. If the gate is still open but the next action is not obvious, the agent stalls rather than acts. If a durable ledger records `reserved=false`, the summary is corrected on the next tool call. The dangerous quadrant is exactly: *quiet gate + loud next action + trusting resume.* ## Decision Boundary The boundary is between **compaction as summarization** and **compaction as state projection**. Summarization is lossy by design and lossy in the direction of narrative salience. State projection is lossy only in dimensions explicitly declared non-load-bearing. The architectural invariant required: **procedural state must live outside the compactable region.** Concretely, the runtime must maintain a machine-readable *obligation ledger* — a structured record of every open gate (`{gate_id, precondition, gated_action, status: open|discharged|violated}`) — that is (a) never passed through the summarizer, (b) re-injected verbatim after every compaction, and (c) checked by the tool-dispatch layer before any gated action executes. The summarizer may compress the transcript freely; it may not compress the ledger, because the ledger is not narrative. The decision rule for the dispatch layer: **an action whose `gate_id` is present in the ledger with `status != discharged` must be refused at the tool boundary, regardless of what the model believes about its own readiness.** The model's belief is a projection; the ledger is the source of truth. When they disagree, the ledger wins and the model is re-briefed. ## Operational Effect With the ledger in place, the observed failure converts from a silent invariant violation into a loud, recoverable refusal: the dispatch layer rejects `issue_purchase_order` with `GateNotDischarged`, the agent is re-injected with the verbatim gate, and it resumes correctly by escalating. The cost is a small, bounded amount of non-compactable context (the ledger is O(open gates), typically single-digit entries) and one extra check per gated call. Without it, the runtime has no way to distinguish "the agent decided to proceed" from "the agent forgot it was forbidden to proceed," because both look identical in the post-compaction context. The failure is not detectable from inside the agent — it requires an external invariant that survives compression. That is the whole lesson: **the tokens that protect you are the tokens a summarizer is most likely to throw away, so they must never enter the summarizer.** ```python from dataclasses import dataclass, field from enum import Enum class GateNotDischarged(RuntimeError): """Raised when a gated action is dispatched while its obligation is still open.""" class GateStatus(Enum): OPEN = "open" DISCHARGED = "discharged" VIOLATED = "violated" @dataclass class Obligation: gate_id: str precondition: str gated_action: str status: GateStatus = GateStatus.OPEN @dataclass class ObligationLedger: """Lives OUTSIDE the compactable context region. Never summarized.""" obligations: dict[str, Obligation] = field(default_factory=dict) def open_gate(self, gate_id: str, precondition: str, gated_action: str) -> None: self.obligations[gate_id] = Obligation(gate_id, precondition, gated_action) def discharge(self, gate_id: str) -> None: if gate_id not in self.obligations: raise GateNotDischarged(f"unknown gate {gate_id!r}; cannot discharge") self.obligations[gate_id].status = GateStatus.DISCHARGED def check_dispatch(self, action: str) -> None: # Refuse any action whose gate is not discharged, regardless of # what the (possibly compacted) model context believes. for ob in self.obligations.values(): if ob.gated_action == action and ob.status is not GateStatus.DISCHARGED: raise GateNotDischarged( f"action {action!r} blocked: gate {ob.gate_id!r} " f"({ob.precondition}) is {ob.status.value}" ) def dispatch(ledger: ObligationLedger, action: str, tool_fn, *args, **kwargs): ledger.check_dispatch(action) return tool_fn(*args, **kwargs) # --- reproduction of the observed failure, now bounded --- ledger = ObligationLedger() ledger.open_gate( gate_id="budget_reserved", precondition="reserve_budget returned reserved=True", gated_action="issue_purchase_order", ) # Step 2: soft failure. Gate stays OPEN. Context compacts. Summary drops the gate. # Agent resumes and attempts the gated action: try: dispatch(ledger, "issue_purchase_order", lambda: "PO-issued") except GateNotDischarged as e: print(f"refused at boundary: {e}") # runtime re-injects verbatim obligation and forces escalation path # Only after a confirmed discharge may the action proceed: ledger.discharge("budget_reserved") assert dispatch(ledger, "issue_purchase_order", lambda: "PO-issued") == "PO-issued" ```